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

WIP snippet support #1178

Closed
wants to merge 1 commit into from
Closed

WIP snippet support #1178

wants to merge 1 commit into from

Conversation

pppKin
Copy link
Contributor

@pppKin pppKin commented Nov 26, 2021

Hi, This draft PR is my initial attempt to add snippet support to helix. I may not be the best guy for this task but I just want snippet support so bad so I just went ahead and see what I can do;)

Implementing snippet is definitely not a easy task so what I plan here is to first implement something basic and, if everything goes well, improve it over time and eventually enable LSP snippet and user defined snippet for all end users.

This PR contains a parser(many part of which is inspired by vscode's parser) to generate a AST of some sort from a snippet fragment, then generate a Transaction from the AST to be consumed by the editor.

Current implementation aims to support LSP Snippet, note that other editors like vscode might support a more complex syntax. We might be able to get there eventually, but right now just keep everything as simple as possible:). For a start please take a look at the definition of SnippetItem, and the test cases to get a glimpse in what is done so far. Current development is entirely driven by test cases, and should have no impact on other parts of the editor.

Some difficulties I've encountered so far (and need help from you guys) includes

  • supporting multiple TabStops (hello $1, good $2), which I hope can be solved after Marks (Marks #703) is implemented.
  • supporting Choice (Good ${1|morning,afternoon,night|}), I just don't know about a good way to embed these choices into the editor.
  • Expanding special variables(TM_DIRECTORY, TM_PROJECT_DIRECTORY, etc.) can be troublesome too because I will need to pull in editor/context bit but definitely doable.

The code right now might be a mess(hence the draft PR), I intend to clean it up and comment as best as I can though. So what do you guys think?

@pppKin pppKin mentioned this pull request Nov 26, 2021
@archseer
Copy link
Member

@pppKin
Copy link
Contributor Author

pppKin commented Nov 27, 2021

Yeah, I have considered nom, but I just don't want to pull in another dependency yet. Should be easy to rewrite with a parser library in the future though.

@archseer
Copy link
Member

Parser combinator functions can be simple enough to handwrite our own, that's what I did in my lua implementation. I've used nom before but I stopped using it after the library went through major breaking changes twice.

@pppKin
Copy link
Contributor Author

pppKin commented Nov 27, 2021

Ah I see. Definitely some room for improvement there in the parser. I'll look into it asap

@kirawi
Copy link
Member

kirawi commented Dec 5, 2021

Maybe you could look at https://github.com/jsdw/yap?

@archseer
Copy link
Member

archseer commented Dec 5, 2021

No need for more dependencies.

@the-mikedavis the-mikedavis mentioned this pull request Apr 9, 2022
@the-mikedavis the-mikedavis added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label May 18, 2022
@kirawi kirawi added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Sep 13, 2022
@archseer
Copy link
Member

There's some work on snippets ongoing in https://github.com/helix-editor/helix/tree/snippets

@archseer archseer closed this Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants