Closed tnarik closed 3 years ago
That's because they don't list their snippets in extension manifest.
They only have this custom configuration, and I did not find any other references to those snippet files:
https://github.com/Dart-Code/Dart-Code/blob/master/package.json#L2470
@DanTup please correct me if I am wrong.
Snippets viewer is a generic solution and works with most snippet extensions that declare them as described in this doc:
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_install-snippets-from-the-marketplace
Here is a good example of how snippets should be configured in vscode package extension manifest:
https://github.com/softchris/node-snippets/blob/master/package.json#L14
User defined snippets docs are here: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets
See my user defined snippets release notes for v1.6.0: https://github.com/RandomFractals/vscode-snippets-viewer/releases/tag/v1.6.0
And user defined snippets (#12) and project scoped snippets (#46) for more info.
With that said, I am going to close this as invalid since the issue is with the snippets extension not bundling them properly and you need to make sure you follow the setup steps for your own snippets. Those have been well documented and tested by many devs, and work if you have things properly configured per vscode dev team recommendations and snippets docs.
That's because they don't list their snippets in extension manifest.
@DanTup please correct me if I am wrong.
This is correct. The snippets in VS Code are quite limited - we can't attach contexts to them so that they appear only in some situations. This means if we list them in the manifest, the Flutter ones will appear even when you only have a Dart project open.
To fix this, we provide the snippets dynamically based on the loaded project types. In the future, the snippets may more to the language server (to allow more context to be taken into account - eg. don't suggest snippets that create classes if you're already inside a class, as it would be invalid).
Hope this makes sense!
yes, I've seen other code language extensions do that. Bicep for example. So, I am aware of it.
I just wanted to provide information why Snippets Viewer would not display them because your snippets config is more dynamic via LSP API and custom, and it would be hard for me to support such use cases without tapping into LSP.
However, I do think you can still link them in ext. manifest for static snippet viewers, and your code hint providers can handle the dynamic parts in code editor.
Thank you for your clarification and followup!
However, I do think you can still link them in ext. manifest
If we put them in the manifest, we'd be unable to suppress them in contexts we don't want them show up in. There aren't any snippets that are valid to always show.
I did try to get some support for basic contexts in snippets in https://github.com/microsoft/vscode/issues/26943, but was advised to do what I did here. When they move to the server, they'll be even more dynamic (right now, they still show in many incorrect contexts, but I really would like to fix that).
I think that explains why I don't see my user defined dart
snippets either. I added snippets (the same one) for c.json
, html.json
and dart.json
, and only the c
user defined snippets appear because c
was already understood by the viewer in my setup.
yeah, sorry, we don't plan to support dynamic snippets with custom configs.
Every language I know has some basic code templates that can be created for quick starts.
VSCode snippets config is a work in progress as compared to other code template engines I am familiar with.
Hopefully they'll work on improving it as more devs start using snippets.
That was the primary goal and reason for creating this extension in collaboration with other vscode ext. devs.
@tnarik please see #47 that is still open and on our todo list for you to see other "global" and user-defined snippets.
@tnarik btw, have you searched for flutter snippets in vs marketplace?
I just installed 2 extensions that provide them for dart and package them properly for devs to use:
I was using only the basic extensions, and then adding my own templates to use with some libraries (because I didn't see any extension already supporting those libraries, like built_value
). And I wanted to use the extension to see everything that was available, which is why I was surprised when I couldn't see the few snippets I knew were provided. But all this explanation makes it clearer about why they are missing.
With Awesome Flutter Snippets now I can see those (because they are properly indicated as Feature Contributions, like you mentioned) plus also my own. Thanks for the tip, I didn't think about that.
For some reason it is missing the snippets in: https://github.com/Dart-Code/Dart-Code/tree/master/snippets (I have the extension installed), or the User snippet I just created for dart.
I just installed vscode-snippets-viewer a couple of minutes ago, and restarted VS Code. Also checked that
snippets.viewer.skipLanguageSnippets
is empty and I didn't mess anything up.