Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

How to support snippets on code actions expansions. #74

Closed
emi2k01 opened this issue Oct 11, 2021 · 12 comments
Closed

How to support snippets on code actions expansions. #74

emi2k01 opened this issue Oct 11, 2021 · 12 comments

Comments

@emi2k01
Copy link

emi2k01 commented Oct 11, 2021

If I have the following code:

pub struct Foo;

impl std::fmt::Display for Foo {
}

fn main() {
}

and I use the code action Implement missing members, the generated code is:

pub struct Foo;

impl std::fmt::Display for Foo {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        ${0:todo!()} // I want my cursor to move here.
    }
}

fn main() {
}

I am using vim-vsnip for regular snippets.

I don't know if this is in the scope of rust-tools or not.

@simrat39
Copy link
Owner

Should be possible if there's some exported api in the completion plugins (nvim-cmp / compe)

@simrat39
Copy link
Owner

This all really depends if a snippet plugin adds support for this, because its out of scope for this plugin

@emi2k01
Copy link
Author

emi2k01 commented Oct 16, 2021

It makes sense. Should this issue be closed? I'll keep an eye on the vim-vsnip issue.

Thanks!

@simrat39
Copy link
Owner

Let's keep it open for now

@hrsh7th
Copy link

hrsh7th commented Oct 18, 2021

  1. The TextEdit related implementations are implemented in nvim core (vim.lsp.util.apply_text_edits).
  2. The Snippet feature implemented in vim-vsnip or LuaSnip.
  3. The CompleteItem handling implemented in nvim-cmp
  4. The rust-analyzer related features implemented in rust-tools.nvim

So I think it should be implemented in rust-tools.nvim.

But I also think it is too harder because snippet and textEdit both are complex implementation.

@hrsh7th
Copy link

hrsh7th commented Oct 18, 2021

I think rust-tools.nvim should get the snippet expansion function as a configuration item. (nvim-cmp does it).

And You can override the vim.lsp.util.apply_text_edits function. (I don't like this solution but I have no another idea...

@sharksforarms
Copy link

I would expect it to work like this where you can configure how the snippet gets expanded: https://github.com/hrsh7th/nvim-cmp/blob/main/README.md?plain=1#L70-L81

@simrat39
Copy link
Owner

I would expect it to work like this where you can configure how the snippet gets expanded: https://github.com/hrsh7th/nvim-cmp/blob/main/README.md?plain=1#L70-L81

Yes I would prefer this as well, but the snippet extenstions would have to actually support the SnippetTextEdits that are given by rust analyzer which aren't supported by any afaik

@simrat39
Copy link
Owner

I think rust-tools.nvim should get the snippet expansion function as a configuration item. (nvim-cmp does it).

And You can override the vim.lsp.util.apply_text_edits function. (I don't like this solution but I have no another idea...

Yep we plan to do it if snippet plugins are down to add support

@ModProg
Copy link

ModProg commented Jan 25, 2022

I don't know if this is related, but when using rust_analyzer with lspconfig without rust-tools I get this expansion on "fill match arms":

match c {
    Test::A(_) => todo!(),
    Test::B(_) => todo!(),
    Test::C { a, b, c } => todo!(),
}

But with rust-tools this happens:

match c {
    Test::A(${0:_}) => todo!(),
    Test::B(_) => todo!(),
    Test::C { a, b, c } => todo!(),
}

Maybe it is possible to have the lspconfig expansion for now, until the cursor move is implemented, as that code is at least compilable?

@Freyskeyd
Copy link

I agree for now I can't really use rust-tools for that :s
Can we have an option to switch from one another ?

@simrat39
Copy link
Owner

simrat39 commented Mar 26, 2022

Fixed with 0190496

Edit: Don't think we'll ever support actual snippets, but now we replace the placeholders with the defaults so its valid rust code.

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

No branches or pull requests

6 participants