Skip to content

Duplicate code suggestions on some items #5002

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

Closed
Tobls opened this issue Nov 12, 2024 · 8 comments · Fixed by #5019
Closed

Duplicate code suggestions on some items #5002

Tobls opened this issue Nov 12, 2024 · 8 comments · Fixed by #5019
Labels
bug Something isn't working

Comments

@Tobls
Copy link

Tobls commented Nov 12, 2024

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
Copy link

ddad431 commented Nov 16, 2024

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
Copy link
Author

Tobls commented Nov 17, 2024

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
Copy link

ddad431 commented Nov 17, 2024

@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
Copy link
Contributor

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

@Tobls
Copy link
Author

Tobls commented Dec 2, 2024

@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'
        }
    }
})

I have exactly this configuration, but still get duplicate suggestions.

@KazariEX KazariEX added bug Something isn't working and removed pending triage labels Dec 3, 2024
@RayGuo-ergou
Copy link
Contributor

Since one ref is function(value: any): any I don't think it's related to the lsp config at all, the above config looks good to me. My gut feel this caused by typescript declaration. Can you share a minimal reproduction?

@Tobls
Copy link
Author

Tobls commented Dec 4, 2024

Since one ref is function(value: any): any I don't think it's related to the lsp config at all, the above config looks good to me. My gut feel this caused by typescript declaration. Can you share a minimal reproduction?

Sure, these are the relevant nvim plugins in the configurations I use (With lazy as a plugin manager):
LSPconfig:

  return {
      "neovim/nvim-lspconfig",
      event = { "BufReadPre", "BufNewFile" },
      dependencies = {
          "hrsh7th/cmp-nvim-lsp"
      },
      config = function()
          local lspconfig = require("lspconfig")
          local cmp_nvim_lsp = require("cmp_nvim_lsp")

          local keymap = vim.keymap
          local opts = { noremap = true, silent = true }
          local on_attach = function(client, bufnr)
              opts.buffer = bufnr
              opts.desc = "Show LSP references"
              keymap.set("n", "<leader>gu", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references
          end

          -- used to enable autocompletion (assign to every lsp server config)
          local capabilities = cmp_nvim_lsp.default_capabilities()

          local mason_registry = require("mason-registry")
          local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server'
          lspconfig["ts_ls"].setup({
              capabilities = capabilities,
              on_attach = on_attach,
              init_options = {
                  plugins = {
                      {
                          name = "@vue/typescript-plugin",
                          location = vue_language_server_path,
                          languages = { "javascript", "typescript", "vue" },
                      },
                  }
              },
              filetypes = {
                  "javascript",
                  "typescript",
                  "vue",
              },
          })

          lspconfig["volar"].setup({
              capabilities = capabilities,
              on_attach = on_attach,
          })
      end
  }

Mason:

return {
    "williamboman/mason.nvim",
    dependencies = {
        "williamboman/mason-lspconfig.nvim",
    },
    config = function()
        local mason = require("mason")
        local mason_lspconfig = require("mason-lspconfig")

        mason.setup({})

        mason_lspconfig.setup({
            ensure_installed = {
                "ts_ls",
                "volar",
            },
            automatic_installation = true
        })
    end,
}

CMP:

return {
    "hrsh7th/nvim-cmp",
    event = "InsertEnter",
    config = function()
        local cmp = require("cmp")

        cmp.setup({
            completion = {
                completeopt = "menu,menuone,preview,noselect",
            },
            sources = cmp.config.sources({
                { name = "nvim_lsp" }
            }),
        })
    end
}

@RayGuo-ergou
Copy link
Contributor

I mean a typescript project reproduction, and you can also try to create a brand new project with create-vite if that does not have the duplicated lsp completion items, can future confirm your neovim config is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants