Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't display all language snippets from extensions #70

Closed
tnarik opened this issue Jun 24, 2021 · 10 comments
Closed

Doesn't display all language snippets from extensions #70

tnarik opened this issue Jun 24, 2021 · 10 comments
Labels
invalid This doesn't seem right

Comments

@tnarik
Copy link

tnarik commented Jun 24, 2021

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.

@RandomFractals
Copy link
Owner

RandomFractals commented Jun 24, 2021

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

@RandomFractals
Copy link
Owner

RandomFractals commented Jun 24, 2021

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.

@RandomFractals RandomFractals added the invalid This doesn't seem right label Jun 24, 2021
@DanTup
Copy link

DanTup commented Jun 25, 2021

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!

@RandomFractals
Copy link
Owner

RandomFractals commented Jun 25, 2021

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!

@DanTup
Copy link

DanTup commented Jun 25, 2021

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 microsoft/vscode#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).

@tnarik
Copy link
Author

tnarik commented Jun 26, 2021

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.

Screenshot 2021-06-26 at 08 54 55

@RandomFractals
Copy link
Owner

RandomFractals commented Jun 26, 2021

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.

@RandomFractals
Copy link
Owner

@tnarik please see #47 that is still open and on our todo list for you to see other "global" and user-defined snippets.

@RandomFractals
Copy link
Owner

@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:

image

@tnarik
Copy link
Author

tnarik commented Jun 27, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants