scalameta / coc-metals

Deprecated in favor of scalameta/nvim-metals
http://scalameta.org/metals/
Apache License 2.0
167 stars 24 forks source link

Insert inferred type #401

Closed otto-dev closed 3 years ago

otto-dev commented 3 years ago

I don't think this is possible yet using coc-metals, but please correct me if I'm wrong. Metals provides a command to insert the inferred type for a variable: https://scalameta.org/metals/docs/integrations/new-editor.html#insert-inferred-type-of-a-value

Is it possible to utilize this using coc-metals, or could it be made possible?

ckipp01 commented 3 years ago

Hey @otto-dev! Thanks for the question. This is actually already doable via coc-metals utilizing code actions.

2021-06-12 18 23 16

The mapping I'm using can be found here:

https://github.com/scalameta/coc-metals/blob/b54d19487058efafd24d4e8912d1970cd430491e/coc-mappings.vim#L100

otto-dev commented 3 years ago

Amazing! Thanks for the instructions, and the link for finding out more.

otto-dev commented 3 years ago

Sorry to get back to this, but I can't get it to work. Any hints how I could work on fixing this? Is this an upstream issue?

DeepinScreenshot_select-area_20210613125811

otto-dev commented 3 years ago

Okay, for others, this works for me:

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

This works for selections:

xmap <Space>a  <Plug>(coc-codeaction-selected)
otto-dev commented 3 years ago

~Issue: When I use Scala 3 sources, there is a only 1-2 second window a few seconds after vim startup where I can trigger the Insert type annotation code action, which executes correctly. Then it stops working.~ Actually, this appear to only work for primitive types. Upstream issue: https://github.com/scalameta/metals/issues/2875

ckipp01 commented 3 years ago

Okay, for others, this works for me:

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

This works for selections:

xmap <Space>a  <Plug>(coc-codeaction-selected)

Glad you got it to work. Yea there are multiple different ways to trigger this.

Actually, this appear to only work for primitive types. Upstream issue: scalameta/metals#2875

Answered over there.