helix icon indicating copy to clipboard operation
helix copied to clipboard

snippet support

Open skewballfox opened this issue 4 years ago • 18 comments

not exactly a feature request, more of request to implement a feature (or whether to wait until extensions are supported).

I've been working on what I hope will be a cross editor snippet manager (link to project) where the client and server are written in rust. while I'm looking to support a few features not covered in the specification (hoping to achieve eventual feature parity with ultisnips), the syntax I'm working to support is a superset of the syntax defined in the lsp specification.

even with support for only basic dynamic snippets(ie vscode snippets), a major usecase is reducing the amount of effort to support snippets by emerging editors to defining the interface (similar to the benefit of the LSP).

the project is at the point to where I can get completions per keystroke and insert/navigate snippets in vscode, but I'm depending on features specific to vscode. Working to support vscode first is also slowing me down because I really dislike/suck with javascript.

I'm aware that extension support is ongoing, but this also might be supportable by the editor itself (I'm trying to make it to where client implementation should be very little code) and also would make sense to a certain degree given that, while no language server (that I know of) handles snippets, snippets are a part of the LSP specification.

skewballfox avatar Jun 30 '21 18:06 skewballfox

Hi! sniper sounds like a very interesting project!

I assume @archseer's intention was to support LSP snippets natively so I don't know if sniper support will be a built-in feature (it is also obviously very young). At any rate, I hope we can at least see a plugin for that at some point hence the A-plugin label.

Regarding an eventual built-in support, if @archseer is favorable, you may want to get involved with helix development. Don't hesitate to drop in for a chat at Helix community Helix Space :smile:

CBenoit avatar Jun 30 '21 20:06 CBenoit

I think it's worth looking at the-way for inspiration.

EpocSquadron avatar Aug 31 '21 04:08 EpocSquadron

While all these snippets managers are nice, I think they should be implemented as a plugin.

Regarding an eventual built-in support

It could be helpful to have simple built-in snippet support like vscode snippet:). Perhaps we can have a go at this?

edit: I did have a go that (#1178), aiming to support LSP snippet. It's far from complete but now we at least know what difficulties we might encounter if we eventually try to implement snippet inside helix-core, and whether we should leave it to a plugin of some sort.

pppKin avatar Oct 08 '21 03:10 pppKin

Strongly need this feature. are there any alternatives?

theowenyoung avatar Jun 26 '22 09:06 theowenyoung

You can implement it and send us a PR?

archseer avatar Jun 27 '22 07:06 archseer

Strongly need this feature. are there any alternatives?

Here's the way I did it:

  • write a simple language server: https://github.com/quantonganh/snippets-ls
  • create a snippet file ~/.config/helix/go-snippets.yaml:
main: |-
  func main() {
      $1
  }

err: |-
  if err != nil {
      $1
  }
  • update the ~/.config/helix/languages.toml:
[[language]]
name = "go"
formatter = { command = "goimports"}
language-servers = ["gopls", "snippets-ls"]

[language-server.snippets-ls]
args = ["-config", "/Users/quantong/.config/helix/go-snippets.yaml"]
command="snippets-ls"

Hope it helps.

quantonganh avatar Aug 09 '23 14:08 quantonganh

There is still one things bothering me right now about the snippet support: The snippets are previewed in the file rather than in the completion/documentation area of the editor. While tabbing through completion candidates this is rather distracting.

I don't know how hard this is to implement, but i at least wanted to let others know. But all in all the snippet support is shaping up to be very good, keep up the amazing work👍

Uldgiw avatar Aug 27 '23 19:08 Uldgiw

  • write a simple language server: https://github.com/quantonganh/snippets-ls

I'm looking through the spec for 3.17, though it might be something you can answer directly? do you know if there is a way to do a streaming response with the language server protocol? I switched to gRPC more easily handle composable snippets, and potentially programmatic snippets.

the former would be easy to handle, just build and replace prior to sending. The latter would be difficult, if not impossible, without bidirectional streaming.

skewballfox avatar Aug 27 '23 19:08 skewballfox

Just to add another LSP that has Snippets created for Helix https://github.com/estin/simple-completion-language-server by @estin

danillos avatar Aug 28 '23 01:08 danillos

Actually come to think of it, if all the community cares about is dynamic snippet support(vscode style snippets) I could create a fork of my project that swaps out grpc for another json RPC, and acts as a server just for helix.

This would allow direct use of vscode snippets, plus support for snippets made of snippets, which is missing from vscode

skewballfox avatar Aug 28 '23 17:08 skewballfox

Support for VSCode snippets would be excellent!

On Mon, 28 Aug 2023 at 18:20, Joshua Ferguson @.***> wrote:

Actually come to think of it, if all the community cares about is dynamic snippet support(vscode style snippets) I could create a fork of my project that swaps out grpc for another json RPC, and acts as a server just for helix.

This would allow direct use of vscode snippets, plus support for snippets made of snippets, which is missing from vscode

— Reply to this email directly, view it on GitHub https://github.com/helix-editor/helix/issues/395#issuecomment-1696061681, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVIG2ATTRXEJOGLMHTY7LXXTHM7ANCNFSM47S5TSFA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

erasebegin avatar Aug 28 '23 19:08 erasebegin

I believe it is important not to overly rely on LSP (Language Server Protocol) and instead give more control to developers. Each developer has a clear understanding of the syntax of the language they are using, but everyone has slightly different coding preferences. It would be beneficial to allow developers to configure their own code snippet suggestions through a configuration file.

zzx31584729 avatar Feb 05 '24 11:02 zzx31584729

If you need a simple snippet in the current version... helix/config.toml

C-g = [
  ":insert-output echo 'if err != nil {\\n}'",
  "move_line_up",
  "open_below",
]

janos-r avatar Mar 10 '24 04:03 janos-r

I'm sorry if I'm missing something here. Has snippet support not landed yet? Maybe I'm misunderstanding the docs, but shouldn't it be working according to them?

https://docs.helix-editor.com/configuration.html?highlight=snippet#editorlsp-section

victorz avatar Apr 19 '24 10:04 victorz

Some snippet support has landed but not proper support, that will be https://github.com/helix-editor/helix/pull/9801

gabydd avatar Apr 19 '24 11:04 gabydd

Some snippet support has landed but not proper support, that will be #9801

Thank you kindly!

victorz avatar Apr 20 '24 13:04 victorz

I don't know if this would best go into a new issue, but auto expand support for snippets would be very nice. VSCode does not support it, but it is a game changer workflow wise.

GameDungeon avatar Aug 11 '24 16:08 GameDungeon

#9801 fully implements the snippet system, but a subsequent PR would still need to be made to implement a snippet manager inside Helix.

kirawi avatar Aug 12 '24 22:08 kirawi

So how exactly can I define snippets then? That does not seem to be described in the documentation.

danrot avatar Jan 19 '25 10:01 danrot

a subsequent PR would still need to be made to implement a snippet manager inside Helix.

UltraBlackLinux avatar Jan 19 '25 11:01 UltraBlackLinux

@UltraBlackLinux I've read that, but the way I've understood the other PR is that this should somehow be possible already, even if it might be cumbersome, and that a snippet manager might only make stuff more convenient.

danrot avatar Jan 19 '25 11:01 danrot

So how exactly can I define snippets then? That does not seem to be described in the documentation.

The quickest way to have snippets in Helix right now would be to use a language server for snippets, like: https://github.com/estin/simple-completion-language-server

One additional benefit with that approach is that your snippets will also work in other editors like Zed.

A full blown snippet manager will most likely make things easier for beginners, but it kinda depends on maintainers and the language server approach is adequate for now in my opinion.

zetashift avatar Jan 19 '25 12:01 zetashift

We do want a snippet manager in core IIRC. Pascal mentioned wanting to use it for https://github.com/helix-editor/helix/issues/1438 as a special form of snippet.

kirawi avatar Jan 19 '25 16:01 kirawi

Folks, I noticed https://github.com/helix-editor/helix/pull/9801 got merged. Is that the snippet system / manager you are talking about? Sadly, the PR has no docs and I do not have the time to go through the code right now.

MarSik avatar May 14 '25 10:05 MarSik

As previously mentioned, #9801 added support for snippet operations, but we don't support managing customs snippets in the editor itself, that needs to currently happen through a separate language server (for example https://github.com/estin/simple-completion-language-server).

archseer avatar May 14 '25 11:05 archseer

Not having the power of LuaSnip/UltiSnips is actually the only thing holding me back from using helix. Things like being able to generate part of the snippet using the input of some tabstops are just something that doesn't work with language server snippets, but is really powerful (LuaSnips function node or UlitSnips python eval blocks). Would really love to see this feature happening 👍

oiiiiiiii avatar Aug 29 '25 09:08 oiiiiiiii

Strongly need this feature. are there any alternatives?

Nowadays, devs are using hx-lsp to solve this problem.

gokayburuc avatar Sep 18 '25 06:09 gokayburuc