chaozwn / astronvim_with_coc_or_mason

astronvim_config
102 stars 25 forks source link

Vue+Typescript+Vite项目中如果使用path alias,gf无法跳转到目标文件 #24

Closed tim-huang closed 2 months ago

tim-huang commented 2 months ago

Vue 3.4.29 + typescript 5.4 + Vite 5.3.1

tsconfig.json配置

{
    "paths": {
      "@/*": ["./src/*"]
    }
}

vite配置了

export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

在ts或vue文件中,使用@引用文件:

import HelloWorld from '@/components/HelloWorld.vue'

此时在HelloWorld上使用gd可以跳转到正确的文件,但在@/components/HelloWorld.vue上使用gf无法跳转到文件。提示: E447: 在路径中找不到文件 "/components/HelloWorld.vue"

chaozwn commented 2 months ago

Vue 3.4.29 + typescript 5.4 + Vite 5.3.1

tsconfig.json配置

{
    "paths": {
      "@/*": ["./src/*"]
    }
}

vite配置了

export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

在ts或vue文件中,使用@引用文件:

import HelloWorld from '@/components/HelloWorld.vue'

此时在HelloWorld上使用gd可以跳转到正确的文件,但在@/components/HelloWorld.vue上使用gf无法跳转到文件。提示: E447: 在路径中找不到文件 "/components/HelloWorld.vue"

gf is function improved by whick key, which is support by lsp client. so you must use the real file path to use gf.

tim-huang commented 2 months ago

Vue 3.4.29 + typescript 5.4 + Vite 5.3.1 tsconfig.json配置

{
    "paths": {
      "@/*": ["./src/*"]
    }
}

vite配置了

export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

在ts或vue文件中,使用@引用文件:

import HelloWorld from '@/components/HelloWorld.vue'

此时在HelloWorld上使用gd可以跳转到正确的文件,但在@/components/HelloWorld.vue上使用gf无法跳转到文件。提示: E447: 在路径中找不到文件 "/components/HelloWorld.vue"

gf is function improved by whick key, which is support by lsp client. so you must use the real file path to use gf.

Thanks for your quick response, I got it.