neoclide / coc-vetur

Vue language server extension for coc.nvim
219 stars 7 forks source link

Are typescript code actions in vue files supported? #50

Closed otijhuis closed 4 years ago

otijhuis commented 4 years ago

I can't get code actions (like adding missing import statements) to work inside <script lang="ts"> tags. I get the message [coc.nvim] CodeAction not found. Should they work or are they not supported?

When I use vetur in vscode or vls with nvim-lsp (in the neovim 0.5 nightly with lsp support) the actions work fine so the language server definitely supports it.

chemzqm commented 4 years ago

Should be problem of your language server, checkout https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

otijhuis commented 4 years ago

Thanks for the quick response. I don't see any problems in the logs. I'll see if I can find a solution. It might be an issue with the defaults in one of the plugins considering nvim-lsp + vls just works without any special settings.

chemzqm commented 4 years ago

Try vetur.dev.vlsPath configuration for your own vls.

otijhuis commented 4 years ago

I finally found out what was causing the issues. There were actually 2 problems. I figured I'd add the solutions here in case other people have the same issues.

Example code:

export default defineComponent({
   setup() {
      const r = ref(0);
      return { r };
   }
}}

In this case defineComponent and ref aren't found. Turns out that vscode didn't have the quickfix for defineComponent either. If I already had import { defineComponent } from '@vue/composition-api' then the quickfix for ref would work and it would ask if it should add it to the import.

This issue was caused by the default tsconfig.json file that was created by vue-cli. It contains "types": ["webpack-env"] which causes it not to find the other types anymore. Once I added "@vue-composition-api" to the types the quickfix would work for defineComponent.

It still wouldn't give any fixes for ref. The issue here was that both coc-codeaction and coc-codeaction-line didn't find anything and those were the only commands I used. For some reason only coc-codeaction-selected works. Don't know why in this case it behaves differently though. But at least it works.

The only issue left is that when there aren't any import statements inside the <script lang="ts"> tag, the first import gets added to the top of the file, instead of inside the script tag. Think I already saw an issue about that somewhere (update: yes it's a vetur bug).