scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.1k stars 332 forks source link

"Insert type annotation" available in vim ? #2982

Closed achever1 closed 3 years ago

achever1 commented 3 years ago

Hello !

I can't figure out how to have the "Insert type" action in vim. It doesn't appear in the choices. Is it expected ?

image

OS: Linux vim version: NVIM v0.5.0 node version: v12.22.0 coc.nvim version: 0.0.80-aa24232066 coc-metals: 1.0.7 scala: 2.13.5

Originally posted by @armeltd in https://github.com/scalameta/metals/issues/2875#issuecomment-880171397

tgodzik commented 3 years ago

Thanks for reporting! It looks like the position sent to Metals is that of "tot" as the code action suggests the Convert to interpolation string code action. Any idea what's going here @ckipp01 ?

ckipp01 commented 3 years ago

@armeltd are you able to post your mapping that you're using to trigger the code action?

achever1 commented 3 years ago

Issue fixed indeed it was a binding issue. Here's what I had :

" Remap for do codeAction of current line
xmap <leader>a  <Plug>(coc-codeaction-line)
nmap <leader>a  <Plug>(coc-codeaction-line)

I think I copy pasted them a couple of months ago from the metals website.

the default bindings have changed now (line => selected) and it works when I get the new ones :

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

image

Thanks for all what your doing it is really awesome. :+1:

ckipp01 commented 3 years ago

Glad it's fixed. If you are able to, please do shoot in a PR to update the bindings, which can be found here: https://github.com/scalameta/metals/blob/main/docs/editors/vim.md#recommended-cocnvim-mappings. I'll go ahead and leave this open a bit until we get the mappings updated. If you don't have time I should be able to quickly do it later today.

achever1 commented 3 years ago

The default mappings on the site now are working so they don't need any update. it is just the old ones at the time I copy pasted that were not. It is just to "old users" to remind to update their conf sometimes. Maybe this kind of required action could be notified to users in some way (release note ?) because updating the conf is not something I thought about. Now I will :D but I don't know if everyone will.

ckipp01 commented 3 years ago

Ahh ok, sounds good. I'll go ahead and close then. I'll try to think of a better way on the coc-metals side to notify users, but I'm not always aware of the changes coc.nvim makes on their end. 👍🏼

otto-dev commented 3 years ago

Saw this a couple hours late. For googlers: The correct mapping for normal mode is

nmap <Space>a  <Plug>(coc-codeaction-cursor)

you may replace <Space>a of course

achever1 commented 3 years ago

ok done. then I suggest to update the doc https://github.com/scalameta/metals/pull/2985