-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add language-agnostic snippets #13253
Conversation
|
The official support now is really great.
|
Hey @d1y, |
Nevermind, you're right about highlighting; since we're using the body as doc, it should be valid code. It may contain unsubstituted variables tho, which is a bit of a bummer. |
@osiewicz I'm trying to use this according to these instructions and nothing shows up for me. I've installed the extension and created the following snippet files:
{
"my snippet": {
"prefix": "my-snippet",
"body": [
"console.log('Hello World')"
],
"description": "Log Hello World to the console"
}
}
{
"horizontal line": {
"prefix": "foo",
"body": [
"%--- Internal ------------------------------------------------------------------"
],
"description": "horizontal comment line"
}
} However, typing |
@osiewicz Yes, please support more languages! ❤️ I tried in a file with |
Oh, it looks like there's a typo in languages list; "Shell" should be a "Shell Script" syntax. TL;dr: try other file. I'll fix the shell association in a sec. |
Alright, it works in a Python file. However I noticed it does not work in any supported syntax if the file is not saved. Is that supposed to work? |
No, it's not supposed to work (unrelated to this PR); we don't support LSPs in unsaved files right now. |
Do you want a PR to add more languages? |
I'm on it, but thanks anyways. =) |
This fixes issues spotted by @eproxus in #13253 (comment) Release Notes: -N/A
0.0.3 is out now. Give it a go =) |
@osiewicz Works! Thanks for the quick work! 😍 |
You mention that you should be able to use a snippets.toml file. Have not been able to get this to work. Do I have something formatted wrong?
|
@danremollino yeah, I think the first line should be |
Here's an example [[snippets]]
prefix = "hr"
scope = ["erlang"]
body = '%--- ${1:Internal} ------------------------------------------------------------------'
[[snippets]]
prefix = "iof"
scope = ["erlang"]
body = 'io:format("--> ${1}: ~p~n", [${1}])' @osiewicz Is there any chance advanced text replacements will be added? I'm thinking like filter than VS Code or Sublime uses, with support for regex replacements etc. In the above example I'd like the first |
@eproxus I guess it might be added at some point, yeah - it's in the spec, so I don't see why not; our snippet support is relatively scarce right now, so please create a new issue for it. |
@osiewicz Great! I'll file an issue. Do you know if those variables are supported already, like |
Hehe, nope: #13255 |
@osiewicz I have an issue with starting snippets language server on Ubuntu.
In my zed logs I've found errors related to starting the snippets server: Can you please help me decode the issue here, since my best guess was that the extention is not installed correctly and I've tried reinstalling multiple times with no result? |
@tepavcevic Thankfully this is relatively straightforward - I've screwed up the name of a platform for Linux. None of this is your fault and I'm sorry for it being so confusing. |
Fix invalid platform name on Linux. Related to: #13253 (comment) Release Notes: - N/A
@tepavcevic Can you give 0.0.5 snippets extension a try? |
Just tried out 0.0.5, working as intended. Thanks |
Note that right now we can't attach a language server to arbitrary buffer, which is why I've listed a bunch of languages verbatim.
See https://github.com/zed-industries/simple-completion-language-server/tree/main for docs on how to define your snippets. They should be placed in ~/.config/zed/snippets ;
snippets.(toml|json)
file can be used to define language-agnostic snippets, and any other name (e.g.python.toml
) will apply only to buffers of that particular type.There's https://github.com/rafamadriz/friendly-snippets you can use as a repository of snippets, for your convenience.
Fixes #4611
Release Notes: