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

Support more advanced snippet syntax #1279

Open
danielrainer opened this issue Dec 11, 2024 · 2 comments
Open

Support more advanced snippet syntax #1279

danielrainer opened this issue Dec 11, 2024 · 2 comments
Assignees

Comments

@danielrainer
Copy link
Contributor

danielrainer commented Dec 11, 2024

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax

Some snippets already work well, but I noticed that when auto-filling the arms of a match, the placeholders don't get parsed properly.

For example, for the following completing the match arms in this code

    let test = Some(42);
    match test {
        
    }

using the Fill match arms action results in this code:

    let test = Some(42);
    match test {
        Some(${1:_}) => ${2:todo!()},
        None => ${3:todo!()},
    }

It would be great if these placeholders were parsed such that the actual placeholder values are inserted (in this example _, todo!(), and todo!()) and navigation between these is possible (<c-j> and <c-k> using the default mappings).

I took a brief look at the code and it seems that the snippets which are currently not working are parsed in commands.ts:parseSnippet. The working snippets (e.g. the ile postfix snipped) don't seem to be parsed in this function, but I have not yet found out how they are handled. Since those work, there presumably is a working implementation somewhere already.

What's the output of :CocInfo

## versions

vim version: NVIM v0.10.2
node version: v23.1.0
coc.nvim version: 0.0.82-28ad86db 2024-12-07 14:40:45 +0800
coc.nvim directory: ~/.local/share/nvim/lazy/coc.nvim
term: xterm-kitty
platform: linux

## Log of coc.nvim

2024-12-11T00:58:31.435 INFO (pid:69983) [extension:coc-git] - Looking for git in: git
2024-12-11T00:58:31.669 INFO (pid:69983) [plugin] - coc.nvim initialized with node: v23.1.0 after 419
2024-12-11T00:58:31.670 INFO (pid:69983) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2024-12-11T00:58:31.671 INFO (pid:69983) [attach] - receive notification: highlight []
2024-12-11T00:58:31.680 INFO (pid:69983) [language-client-index] - Language server "rust-analyzer" started with 70007
2024-12-11T00:58:31.729 INFO (pid:69983) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2024-12-11T00:58:31.759 INFO (pid:69983) [services] - service rust-analyzer started
2024-12-11T00:58:32.676 INFO (pid:69983) [attach] - receive notification: highlight []
2024-12-11T00:58:33.618 INFO (pid:69983) [attach] - Request action: diagnosticList []
2024-12-11T00:58:34.166 INFO (pid:69983) [attach] - receive notification: highlight []
2024-12-11T00:58:34.314 INFO (pid:69983) [attach] - Request action: diagnosticList []
2024-12-11T00:58:35.003 INFO (pid:69983) [attach] - receive notification: codeAction [ 'cursor' ]
2024-12-11T00:58:35.324 INFO (pid:69983) [attach] - receive notification: highlight []
2024-12-11T00:58:39.645 INFO (pid:69983) [attach] - Request action: diagnosticList []
2024-12-11T00:58:40.946 INFO (pid:69983) [attach] - receive notification: highlight []
2024-12-11T00:58:44.680 INFO (pid:69983) [attach] - receive notification: showInfo []

What's the output of :CocCommand rust-analyzer.serverVersion

rust-analyzer 0.3.2212-standalone

What's your coc-rust-analyzer version? You can get it from :CocList extensions

0.77.5 (also tested locally on the latest commit (4283825)

fannheyward added a commit that referenced this issue Dec 11, 2024
1. apply snippet's placeholder
2. move the cursor to `$0`

Couldn't jump the snippets for now, need coc.nvim to apply SNIP session

#1279
#1228
@fannheyward
Copy link
Owner

fannheyward commented Dec 11, 2024

This feature is SnippetTextEdit, added in LSP 3.18 https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#snippetTextEdit

I've add partly support in coc-rust-analyzer v0.78.0, the snippet can be applied correctly. I'll add the SnippetTextEdit feature in coc.nvim.

@danielrainer
Copy link
Contributor Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants