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

feat(cmds): support snippet text edit #252

Merged
merged 3 commits into from
May 25, 2020
Merged

Conversation

fannheyward
Copy link
Owner

rust-lang/rust-analyzer#4494

@oblitum @TimoFreiberg can you guys test this? Maybe you need to download latest nightly release.

@TimoFreiberg
Copy link
Contributor

TimoFreiberg commented May 20, 2020

I'll try it :)
Do I understand correctly that I don't need to change any config and that I only expect assists to still place the cursor in the correct place?

Findings:

  • Generating a function in another module (mod foo; foo::bar()<|>;) generates the function in the current module instead. The latest release of coc-rust-analyzer correctly generates the function in foo.rs instead.

@TimoFreiberg
Copy link
Contributor

Oh my, this fixes the "select the generated todo!()" part of rust-lang/rust-analyzer#3639 🎉

@oblitum
Copy link

oblitum commented May 21, 2020

For me, checking actions when cursor is over foo at:

fn main() {
    foo();
}

Gives Add function action, which when triggered, generates a stub like:

fn main() {
    foo();
}
fn foo() {
    todo!()
}

I can see from neovim statusline that after that I enter a coc snippet session, but it's not useful because my cursor is at the end of the code, and there's no placeholder to jump to.

@oblitum
Copy link

oblitum commented May 21, 2020

Happens with mini.vim as:

set runtimepath^=~/.vim/plugged/coc.nvim
colorscheme peachpuff
let mapleader = ' '
nmap <silent> <leader>cA <Plug>(coc-codeaction)
vmap <silent> <leader>cA <Plug>(coc-codeaction-selected)

@fannheyward
Copy link
Owner Author

@oblitum do you use the stable or nightly release? stable release will add function foo but without jumping into it. nightly release will bring you into the foo function, and select todo!() in snippet mode.

https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/lsp-extensions.md#snippettextedit

@oblitum
Copy link

oblitum commented May 21, 2020

I've tested with this pull + rust-analyzer nightly 42dd0ce.

coc/extensions/coc-rust-analyzer-data
❯ ./rust-analyzer --version
rust-analyzer 42dd0ce

@fannheyward
Copy link
Owner Author

Yes, it's the latest nightly release. This snippet textEdit feature is new in rust-analyzer.

@fannheyward
Copy link
Owner Author

@TimoFreiberg how do you get Generating a function in another module action?

@TimoFreiberg
Copy link
Contributor

By writing mod foo; in some rust file, when the foo.rs doesn't exist yet. Then just placing the cursor on foo and trigger (coc-codeaction)

@fannheyward
Copy link
Owner Author

@TimoFreiberg yes, this will trigger Create module action, create foo.rs file, but there is no generates the function, nothing in foo.rs.

@TimoFreiberg
Copy link
Contributor

TimoFreiberg commented May 21, 2020

Oh shit, I misread.
In that example case, when foo.rs exists, writing foo::bar(); in the old file should offer to generate fn bar() { todo!() } in foo.rs.
It used to properly generate the function in foo.rs, but now it generates it in the same file where foo::bar(); was written.

@fannheyward
Copy link
Owner Author

@TimoFreiberg reproduced.

@fannheyward
Copy link
Owner Author

@TimoFreiberg Tested with VSCode + RA, will fail to generate function for this example case. rust-lang/rust-analyzer#4551

@oblitum
Copy link

oblitum commented May 21, 2020

Sorry folks but I couldn't make it work like expected on my side, even with this branch compiled and latest rust-analyzer nightly. Jump to place holder doesn't work. Now on latest coc.nvim things got a bit more non intuitive because it's not showing coc actions for current line anymore and actions for buffer by default, so to even make the create function action to show I have to use coc action with selection.

@fannheyward
Copy link
Owner Author

@oblitum yes, coc-codeaction was changed to buffer only, you can use coc-codeaction-line neoclide/coc.nvim@d792515

@fannheyward
Copy link
Owner Author

@TimoFreiberg make a fix for generating function issue

@TimoFreiberg
Copy link
Contributor

TimoFreiberg commented May 23, 2020

Now the closing brace of the generated function gets selected instead of the todo!()

Expected:

fn foo() {
    |todo!()|
}

Actual:

fn foo() {
   todo!()
|}|

@oblitum
Copy link

oblitum commented May 23, 2020

This is the behavior I reported.

@fannheyward fannheyward merged commit c74c1fd into master May 25, 2020
@fannheyward fannheyward deleted the feat/snippet-text-edit branch May 25, 2020 10:12
@fannheyward fannheyward restored the feat/snippet-text-edit branch May 29, 2020 01:35
@fannheyward fannheyward deleted the feat/snippet-text-edit branch June 1, 2020 09:50
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

Successfully merging this pull request may close these issues.

None yet

3 participants