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

Go to definition is not working in vue SFC components (*.vue files) #4106

Closed
FreshHead opened this issue Mar 16, 2024 · 8 comments
Closed

Go to definition is not working in vue SFC components (*.vue files) #4106

FreshHead opened this issue Mar 16, 2024 · 8 comments

Comments

@FreshHead
Copy link

Good day to you.
I setup tsserver as described in configuration:

https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#vue-support

But when I use "go to definition" with cursor under custom component name inside template section I always end up in shims-vue.d.ts file of my project. Same if I use go to defenition on component name in import in script section of SFC.

My neovim config is based on kickstart.nvim. Below is the part made by instructions in https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#vue-support:

    tsserver = {
      filetypes = {
        'typescript',
        'vue',
      },
      init_options = {
        plugins = {
          {
            name = '@vue/typescript-plugin',
            location = '/home/u/.nvm/versions/node/v20.8.0/lib/node_modules/@vue/typescript-plugin',
            languages = { 'javascript', 'typescript', 'vue' },
          },
        },
      },
    },

    volar = { filetypes = { 'vue' } },

Than I use lua vim.lsp.buf.definition()

Expected behavior
The file with my component is opened

Neovim version (nvim -v)
0.9.5

Language server name/version
typescript-language-sever 4.3.3, vue-language-server 2.0.6

Operating system/version
linux mint 21

Log file
https://gist.github.com/FreshHead/64b96748af826e3f8c0406561c4b4cd6

@CofCat456
Copy link
Contributor

Where can I view your nvim config? I can't find the settings for tsserver.

If possible, please also provide a vue file to reproduce the error.

@FreshHead
Copy link
Author

FreshHead commented Mar 17, 2024

Where can I view your nvim config? I can't find the settings for tsserver.

If possible, please also provide a vue file to reproduce the error.

Thanks for the quick response.
You can check my config at https://github.com/FreshHead/kickstart-modular.nvim

I cannot attach code of the project I am working on, but code of the components looks like this:

MyComponentContainer.vue

<template>
<MyButton>Some text</MyButton>
</template>
<script setup lang="ts">
import MyButtom from '@/components/MyButton';
</script>

BTW I am using vue 3.2.47 and typescript 4.7.4
Stil on vue-cli 5.0.8

@FreshHead
Copy link
Author

FreshHead commented Mar 17, 2024

Hm, I even tried your config (wich may be inspired by "dev as life" ;) ) and "go to definition" still does not work properly.

Big chances that is something off with my project. I tried projects without TS and "go to definition" opens components just fine. But I also tried some Vue+TS projects in particular Evan's You wordle https://github.com/yyx990803/vue-wordle
and when I use "go to definition" I get a message "No definitions found".

BTW issue is started when I decided moving from lazyVim into custom config. But right now even my old lazyVim config is not working.

@CofCat456
Copy link
Contributor

嗯,我什至嘗試了你的配置(這可能是受到“開發如生活”的啟發;))並且“轉到定義”仍然無法正常工作。

我的專案很有可能出了問題。我嘗試了沒有 TS 的項目,「轉到定義」打開元件就好了。但我也嘗試了一些 Vue+TS 項目,特別是 Evan 的 You wordle yyx990803/vue-wordle ,當我使用“轉到定義”時,我收到一條訊息“未找到定義”。

順便說一句,當我決定從lazyVim轉向自訂配置時,問題就開始了。但現在即使我舊的lazyVim 配置也無法運作。

It sounds very strange.

I tried the vue-cli project and yyx990803/vue-wordle, and it worked fine for me.

What is your version of @vue/typescript-plugin?

@FreshHead
Copy link
Author

FreshHead commented Mar 17, 2024

嗯,我什至嘗試了你的配置(這可能是受到“開發如生活”的啟發;))並且“轉到定義”仍然無法正常工作。
我的專案很有可能出了問題。我嘗試了沒有 TS 的項目,「轉到定義」打開元件就好了。但我也嘗試了一些 Vue+TS 項目,特別是 Evan 的 You wordle yyx990803/vue-wordle ,當我使用“轉到定義”時,我收到一條訊息“未找到定義”。
順便說一句,當我決定從lazyVim轉向自訂配置時,問題就開始了。但現在即使我舊的lazyVim 配置也無法運作。

It sounds very strange.

I tried the vue-cli project and yyx990803/vue-wordle, and it worked fine for me.

What is your version of @vue/typescript-plugin?

@vue/typescript-plugin 2.0.6. I installed it with npm globally and even installed it into the project itself

@CofCat456
Copy link
Contributor

CofCat456 commented Mar 17, 2024

Hey, I just tried your nvim config.

I only modified the location of @vue/typescript-plugin, and it worked very well.

I guess maybe it's an issue with your project, or the @vue/typescript-plugin wasn't correctly read by the tsserver.

2024-03-17.6.48.34.mov
截圖 2024-03-17 下午6 55 30

@FreshHead
Copy link
Author

FreshHead commented Mar 17, 2024

Thanks you for your time. You can close this issue as completed but I also wanna ask, do you know how can I check that tsserver is loading @vue/typescript plugin?

@CofCat456
Copy link
Contributor

Honestly, I'm not sure either.

However, as far as I know, if @vue/typescript-plugin is not loaded correctly, you probably won't receive any messages indicating its status.

So, if you are certain that @vue/typescript-plugin has been loaded but you are unable to use "Go to definition" correctly, then it might be an issue with Volar itself, and you should continue to investigate this further.

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

No branches or pull requests

2 participants