Replies: 11 comments 53 replies
-
I was thinking something like the following, using ---
id = 'classDeclaration'
description = 'Class declaration'
insertionScopeType = 'statement'
[variables.name]
[variables.body]
wrapperScopeType = 'namedFunction'
---
---
id = 'classDeclaration'
langIds = ['python']
[variables.name]
formatter = 'pascalCase'
---
class {{ name }}:
{{ body }}
---
id = 'classDeclaration'
langIds = ['typescript', 'typescriptreact', 'javascript', 'javascriptreact']
[variables.name]
formatter = 'pascalCase'
---
class {{ name }} {
{{ body }}
} Note how in the first "snippet", the body is empty, so we're just defining attributes without defining a snippet body, and we don't use Note also that we strip trailing newlines in the snippet body so that the user can add extra spacing for readability Looks like there is a Looks like with that toml extension we can signal important keys in the schema via At its simplest, a snippet could just look like: ---
id = 'helloWorld'
---
Hello, {{ name }}! |
Beta Was this translation helpful? Give feedback.
-
nunjucks looks kinda nice as a templating language for the body of the snippet. I like the way the filters look; a lot like jq Has a few VSCode extensions but this one gets the best reviews it appears |
Beta Was this translation helpful? Give feedback.
-
Fwiw here is a list of template engines |
Beta Was this translation helpful? Give feedback.
-
Also fwiw here is how it would look if we used yaml for the metadata header: ---
id: classDeclaration
description: Class declaration
insertionScopeType: statement
langIds:
- python
variables:
body:
wrapperScopeType: namedFunction
---
---
id: classDeclaration
langIds:
- python
variables:
name:
formatter: pascalCase
---
class {{ name }}:
{{ body }}
---
id: classDeclaration
langIds:
- typescript
- typescriptreact
- javascript
- javascriptreact
variables:
name:
formatter: pascalCase
---
class {{ name }} {
{{ body }}
} if we go with yaml we'd want to register schema like this |
Beta Was this translation helpful? Give feedback.
-
Do we want to use |
Beta Was this translation helpful? Give feedback.
-
could be a bit confusing the fact that the different bodies are associated just by the fact that they share an identifier. Could be a bit confusing / error prone. Possibly just have it so that if you only specify identifier in first snippet in body, the rest of the snippets in the language don't need to specify the identifier and are assumed to have the same identifier |
Beta Was this translation helpful? Give feedback.
-
Do have any thoughts on how to handle tabs/indentation now when we represent the body as plaintext?
Is that a tab symbol? four spaces? The reason why this matters is that vscode handles the insertion of a tab symbol according to the users tab settings, but if the body actually contains just white spaces as indentation I don't believe that actually happens. |
Beta Was this translation helpful? Give feedback.
-
You might want to consider copying yasnippet: https://github.com/joaotavora/yasnippet You write almost no more than the thing you are templating! It also looks like someone already implemented it in vs code: https://marketplace.visualstudio.com/items?itemName=mads-hartmann.yassnippet If you need more information than this, I'd encorage parsing that format which is very convenient for end users into a richer one. |
Beta Was this translation helpful? Give feedback.
-
One consideration is whether or not template engine constructs such as if-then-else and for loops can reference user input, and whether their bodies can hide/expose further holes. I think we should be able to handle such cases, but doing so would expose several UX and programming issues: Holes may appear, disappear, and reappear at any point during snippet resolution. Do we remember their previous values? What about holes which have no absolute name, e.g., holes which are generated by a for loop? Do we just remember all values so far in a list? From an implementation perspective, we’d have to rerun the template engine at every user edit in a hole, since the template may have resolved differently. However, the user may switch between editing the contents of holes and the text generated by the template. How do we remember these updates to the generated text. Barring for loops, we could probably use the existing cursorless functionality to dynamically create a “new” temporary snippet if we remember where the snippet started and where it ended, and we know where the holes are. However, this becomes a lot more tricky if we, say, edit the standard text generated by a for loop in only the third instance. So maybe just remembering edits to the generated text and rebasing them, as it were, would be better? |
Beta Was this translation helpful? Give feedback.
-
Yesterday we had another discussion about snippets and we decided that Cursorless snippets actions should be able to be utilized by custom/external snippets sent over the command server. My goal would be to have a snippet representation that we could upstream to the community and be used by different ide and projects. I've been thinking on a much simpler snippet format that reminds a lot about Talon files.
|
Beta Was this translation helpful? Give feedback.
-
After some thorough thought I have now gone ahead and implemented a format that I'm very happy with. @pokey @josharian have already given input and I have made some tweaks based on that. https://github.com/AndreasArvidsson/andreas-talon/tree/master/core/snippets |
Beta Was this translation helpful? Give feedback.
-
We should come up with a good representation for our snippets. Currently they look like the following:
This representation is hard to read
Beta Was this translation helpful? Give feedback.
All reactions