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

Language server agnostic snippets #4611

Closed
1 task done
failable opened this issue Jul 21, 2023 · 56 comments · Fixed by #13253
Closed
1 task done

Language server agnostic snippets #4611

failable opened this issue Jul 21, 2023 · 56 comments · Fixed by #13253
Labels
editor Feedback for code editing, formatting, editor iterations, etc feature [core label] priority A high priority issue setting Feedback for preferences, configuration, etc

Comments

@failable
Copy link

Check for existing issues

  • Completed

Describe the feature

Other editors have the ability to define snippet without setting up in the LSP. For example, one can still define snippets for editing plain text files and that does not require user to setup initialization options of a LSP. (And we don't generally have a LSP for plain text files.)

Also some snippets might shared across different file types/LSPs.

If applicable, add mockups / screenshots to help present your vision of the feature

output

@JosephTLyons JosephTLyons added editor Feedback for code editing, formatting, editor iterations, etc setting Feedback for preferences, configuration, etc and removed triage labels Jul 21, 2023
@failable failable mentioned this issue Sep 8, 2023
1 task
@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@xtian
Copy link

xtian commented Jan 24, 2024

One example use-case is authoring HTML embedded in a string/template within another language. By default, Sublime maps Ctrl+W to an 'insert tag' snippet which makes this very easy and provides a consistent workflow across languages.

@miknyko
Copy link

miknyko commented Mar 13, 2024

Hi, when will this happen?

@JosephTLyons JosephTLyons added the priority A high priority issue label Mar 14, 2024
@thoreg
Copy link

thoreg commented Apr 6, 2024

Is there any ongoing work on this feature? Would be happy to join/support here

@0x2CA 0x2CA mentioned this issue Apr 15, 2024
1 task
@auspy
Copy link

auspy commented Apr 19, 2024

is this implement? how to add custom snippets in zed like we in vscode javascript.json?

@sevignator
Copy link

+1 for requesting this feature. It's a huge time saver!

@prescientmoon
Copy link

A very important feature for me is luasnip's auto snippets. Snippets marked as "auto" will trigger the moment the prefix is typed out, without having to select the snippet in the autocomplete menu and press enter. While this might sound useless, it's super handy when having to type LaTeX quickly (i.e.: when taking live notes during a lecture)

@TuralAsgar
Copy link

I want to switch fully to Zed for Go projects and this feature prevents me from switching.
Would be great to have it.

@osiewicz
Copy link
Contributor

osiewicz commented Jul 1, 2024

Heads up everybody, we're most likely going to deprecate snippets extension and bring it directly into core Zed editor. That way they'll work with all languages out of the box and extensions will be able to provide their own snippets.
It would probably also fix #13636

@osiewicz osiewicz reopened this Jul 1, 2024
@fuzenco
Copy link

fuzenco commented Jul 5, 2024

Heads up everybody, we're most likely going to deprecate snippets extension and bring it directly into core Zed editor. That way they'll work with all languages out of the box

Thank you! Can you make sure snippets work with Plain Text files too. I have a shortcut I like to use with Markdown and Plain Text but as of right now I can only use it in .md files because .txt files don’t seem to work with agnostic snippets.

@davidwebca
Copy link

Mmm was anything dropped in the last update? My snippets - that were working - now won't work anymore. 🤔 Files are saved with a syntax selected where it was already working but now it doesn't. Am I insane?

@failable
Copy link
Author

failable commented Jul 11, 2024

@osiewicz Thanks! Works like a charm on the latest preview release

Zed: v0.144.0 (Zed Preview)
OS: macOS 14.5.0
Memory: 32 GiB
Architecture: x86_64

But it's a bit unclear how to name the snippet file especially when there is whitespace in the language name.

For example,

  • For Plain Text, plaintext.json works while plain_text.json and plain text.json don't.
  • While for Git Ignore, git ignore.json works while gitignore.json and git_ignore.json don't.

@fuzenco
Copy link

fuzenco commented Jul 11, 2024

Plaintext using agnostic snippets now works in the latest Preview! This is awesome. Thanks team!

@michTheBrandofficial
Copy link

I tried using the snippets but the dont work at all

@JosephTLyons
Copy link
Collaborator

JosephTLyons commented Jul 23, 2024

I created a pretty small document for getting started with configuring snippets here.

Ill add documentation on how to bundle snippets via an extension soon.

I think we likely have a bit more work to do to make snippets discoverable and easily editable, but the core is all in place, so I think I will close out this issue. Feel free to open up new issues for feature requests about snippets. If you need help building something out, please do so in our Q&A Discussions section

@fuzenco
Copy link

fuzenco commented Jul 23, 2024

Thank you. This is a perfect start. I’m loving Snippets in Zed.

@alejodelosrios
Copy link

alejodelosrios commented Aug 15, 2024

I tried using the snippets but they do not work at all

Same here, I have javascript.json and typescript.json saved on the zed/snippets folder, and it doesn't work.
I've restarted Zed before try and nothing. Would anyone be able to help me?

I must say I'm using the example snippets from the doc https://zed.dev/docs/snippets#snippets

@huhu415
Copy link

huhu415 commented Aug 15, 2024

as this code , you need write blog in .md, when you want to get the body content in .md.
{ "Create new md file": { "prefix": "blog", "body": [ "+++", "title = '$1'", "categories = ['LearnOn${2:line}']", "tags = ['${3:go}']", "date = 2024-$4-$5", "draft = true", "+++" ], "description": "Create new md file" } }

@alejodelosrios
Copy link

I imagine you already have a file called markdown.json stored in zed/snippets. In my case, I´m trying to get snippets for .ts and .tsx files doing the same. I have a typescript.json and typescriptreact.json files in that folder.

Then, when I write the prefix on a file with the extension .ts or .tsx, nothing happens. The autocomplete menu doesn´t offer me the snippet. What I´m doing wrong?

@huhu415
Copy link

huhu415 commented Aug 15, 2024

lol, why? then, i donot know, lol.

@alejodelosrios
Copy link

I can confirm that it is working for javascript & typescript files using the (javascript.json,typescript.json) files. Still doesn't work for React Native files with the typescriptreact.json
If anyone knows how to do it, I would appreciate the help!

@huhu415
Copy link

huhu415 commented Aug 16, 2024

then you can use snippets.json, that will works in all files

@florinpatrascu
Copy link

florinpatrascu commented Aug 16, 2024

I think this small question might just help me climb to the top of the hit list, lol. Is there a way to set the order of the items in the snippet pop-up?

edit:
When they are defined in different snippet files?

@davidwebca
Copy link

That's my main problem too right now. My snippets don't end up first and I can't get it there. At first I thought if I repeatedly used them, there would be a "preference" ranking, but to no avail.

@alejodelosrios
Copy link

then you can use snippets.json, that will works in all files

Thanks @huhu415, this works like a charm!!!

@itsmikesharescode
Copy link

Is this possible now in zed latest version?

@auspy
Copy link

auspy commented Sep 3, 2024

can we use filename as variable when defining snippets. for example: in vscode I used to type "slr" and it created a component with the filename. //example.jsx creates const example = ()=>{return <></>}; export default example;

@ottob
Copy link

ottob commented Sep 9, 2024

I copied a snippet from VS code containing this that didn't work in zed. It would be nice if this was supported too.

${1:$TM_FILENAME_BASE}

@zgjimgjonbalaj
Copy link

Tried adding a php.json file with a simple var_dump() output it doesn't seem to work. I've tried a few variations and setup with no luck.

@mocenigo
Copy link

Heads up everybody, we're most likely going to deprecate snippets extension and bring it directly into core Zed editor. That way they'll work with all languages out of the box and extensions will be able to provide their own snippets. It would probably also fix #13636

This would be great! Any info on whether extensions can also have theur own settings.json that has precedence on the global one in case there is a clashy? (priority should be: global lowest, extension hogher, then project highest)

@romanzipp
Copy link
Contributor

For me, there were no snippets available due to syntax errors. Zed just fails silently.

Via command prompt, open "zed: open log". There should be some kind of Snippet error.

@TheKinng96
Copy link

anyone misunderstood the ~/.config like i do?
I tot it is in my project file but ended up not

a simpler way to target the correct directory is CMD + shift + p, then type snippets
choose configure snippets and pick your language there

@IvanIsak2000
Copy link

Lol

I just pasted a vscode snippet for Golang in go.json:

Image

And when I command CMD + shift + p and select snippets and select Golang I'm moved in the snippet file:

Image

But Zed doesn't see new snippets :(

Image

OS: arch linux

Zed: 0.171.6

What do you think, guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Feedback for code editing, formatting, editor iterations, etc feature [core label] priority A high priority issue setting Feedback for preferences, configuration, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.