-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WIP snippet support #1178
Conversation
I think you could get a nicer parser if you used parser combinators: |
Ah I see, you're basically porting https://github.com/onivim/vscode-snippet-parser/blob/master/src/snippetParser.ts ? |
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. |
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. |
Ah I see. Definitely some room for improvement there in the parser. I'll look into it asap |
Maybe you could look at https://github.com/jsdw/yap? |
No need for more dependencies. |
There's some work on snippets ongoing in https://github.com/helix-editor/helix/tree/snippets |
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
TabStop
s (hello $1, good $2
), which I hope can be solved afterMarks
(Marks #703) is implemented.Choice
(Good ${1|morning,afternoon,night|}
), I just don't know about a good way to embed these choices into the editor.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?