vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 402 forks source link

Duplicate code suggestions on some items #5002

Open Tobls opened 1 week ago

Tobls commented 1 week ago

Vue - Official extension or vue-tsc version

2.1.10

VSCode version

-

Vue version

3.4.30

TypeScript version

-

System Info

System:
    OS: Linux 6.11 Arch Linux
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600K
    Memory: 25.63 GB / 31.11 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.1.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.9.0 - /usr/bin/npm
    pnpm: 9.12.3 - /usr/bin/pnpm

package.json dependencies

"dependencies": {
        "pinia": "^2.2.2"
    },
    "devDependencies": {
        "@vitejs/plugin-vue": "^5.0.5",
        "@vue/eslint-config-prettier": "^9.0.0",
        "autoprefixer": "^10.4.20",
        "postcss": "^8.4.45",
        "tailwindcss": "^3.4.10",
        "vite": "^5.3.1",
        "vue": "^3.4.30"
    }

Steps to reproduce

When trying to auto-import anything from vue, I get two autocompletion items, with only the second one actually importing it if needed. out(1) out2

What is expected?

Only the second completion item, the one that also auto-imports.

What is actually happening?

I get two autocompletion items, and the one without auto-import is the default.

Link to minimal reproduction

No response

Any additional comments?

I am using neovim and the hyprid mode

ddad431 commented 5 days ago

Make sure that you has enabled the hybrid mode. The following is my configuration, it has no problem. (same version v2.1.10)

local ts_config = {
    name = 'lsp-ts',
    cmd = { 'typescript-language-server.cmd', '--stdio' },
    root_dir = vim.fs.root(0, { 'package.json' }),
    init_options = {
        plugins = {
            {
                name = '@vue/typescript-plugin',
                location = 'path/to/vue-language-server',
                languages = { 'vue' },
            }
        }
    }
}

local vue_config = {
    name = 'lsp-vue',
    cmd = { 'vue-language-server.cmd', '--stdio' },
    root_dir = vim.fs.root(0, { 'package.json' }),
    init_options = {
        vue = {
            hybridMode = true,  -- Note
        },
        typescript = {
            tsdk = 'path/to/tsdk'
        }
    }
}

vim.api.nvim_create_autocmd('FileType', {
    pattern = {
        'javascript', 'vue',
    },
    callback = function()
        vim.lsp.start(ts_config)
        vim.lsp.start(vue_config)
    end,
})
Tobls commented 4 days ago

Make sure that you has enabled the hybrid mode. The following is my configuration, it has no problem. (same version v2.1.10)

I have pretty much the same config

ddad431 commented 4 days ago

@Tobls I have tested all the config methods which listed on readme, the duplicate result only appear on Non-Hybrid mode 2th.

I assume you are using nvim-lspconfig and had installed ts, vue server. Following below steps:

  1. put below code in test.lua
  2. mkdir -p ~/.config/nvim/pack/bucket/opt && cd ~/.config/nvim/pack/bucket/opt
  3. git clone "https://github.com/neovim/nvim-lspconfig"
  4. nvim -u test.lua ./src/App.vue
  5. typing import { ref } from 'v and press <C-x><C-o>
  6. observe competion list

./test.lua:

vim.cmd('packadd nvim-lspconfig')

require('lspconfig').ts_ls.setup({
    init_options = {
        plugins = {
            {
                name = '@vue/typescript-plugin',
                location = '/path/to/vue-language-server',
                languages = {'vue'},
            },
        },
    },
    filetypes = { "javascript", "vue", },
})

require('lspconfig').volar.setup({
    init_options = {
        typescript = {
            tsdk = '/path/to/tsdk'
        }
    }
})
nieyuyao commented 2 days ago

i had same issue in vscode. i noticed that the issue only occurs when Hybrid is turned off.