hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.53k stars 377 forks source link

Missing items in autocomplete #1697

Open BingCoke opened 10 months ago

BingCoke commented 10 months ago

FAQ

Announcement

Minimal reproducible full config


cmp.setup({
    snippet = {
        expand = function(args)
            require("luasnip").lsp_expand(args.body)
        end,
    },
    mapping = cmp.mapping.preset.insert({
        ["<c-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
        ["<c-j>"] = cmp.mapping.select_next_item(), -- next suggestion

        ["<C-u>"] = cmp.mapping.scroll_docs(-4),
        ["<C-d>"] = cmp.mapping.scroll_docs(4),

        ["<A-Space>"] = cmp.mapping.complete(), -- show completion suggestions

        ["<C-e>"] = cmp.mapping.abort(), -- close completion window
        ["<Tab>"] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }),

        ["<c-l>"] = cmp.mapping(function(fallback)
            if luasnip.jumpable(1) then
                luasnip.jump(1)
            else
                fallback()
            end
        end, { "i", "s" }),

        ["<c-h>"] = cmp.mapping(function(fallback)
            if luasnip.jumpable(-1) then
                luasnip.jump(-1)
            end
        end, { "i", "s" }),
    }),
    preselect = cmp.PreselectMode.None,
    sources = cmp.config.sources({
        { name = "nvim_lsp" },
        { name = "luasnip" },
        { name = "path" },
    }, {
        { name = "buffer" },
    }),
    window = {
        completion = cmp.config.window.bordered(),
        documentation = {
            border = border("CmpDocBorder"),
            winhighlight = "Normal:CmpDoc",
            max_width = 20,
        },
    },
})

typescript config

    require("typescript-tools").setup({
        on_attach = function(cli, buf)
            on_attach(cli, buf)
        end,
        capabilities = default_capabilities,
        --handlers = { ... },
        settings = {
            -- spawn additional tsserver instance to calculate diagnostics on it
            separate_diagnostic_server = true,
            -- "change"|"insert_leave" determine when the client asks the server about diagnostic
            publish_diagnostic_on = "insert_leave",
            -- array of strings("fix_all"|"add_missing_imports"|"remove_unused")
            -- specify commands exposed as code_actions
            expose_as_code_action = {},
            tsserver_plugins = {
                -- for TypeScript v4.9+
                --"@styled/typescript-styled-plugin",
                -- or for older TypeScript versions
                --"typescript-styled-plugin",
                "typescript-plugin-css-modules",
            },
            tsserver_file_preferences = {
                includeInlayParameterNameHints = "all",
                includeCompletionsForModuleExports = true,
                quotePreference = "single",
            },
        },
    })

Description

Here is auto complete suggestions. image when i fire "< a - space>" to use cmp.mapping.complete()

Here is result image

Steps to reproduce

I use it in nestjs project with typescript.

  1. npm i -g @nestjs/cli && nest new app to build project
  2. delete these lines in app.service.ts
    
    import { Injectable } from '@nestjs/common';

@Injectable()


3. input "@Inj" to auto import Injectable.But get nothing.
4. fire < a - space > will get juggestion list has injectable complete item.

### Expected behavior

get consistent result suggestion list

### Actual behavior

canot get Injectable from auto complete suggetion list.

### Additional context

It seems that the problem is not only here,
I use rust,And get same problem.
auto complete 
![CopyQ JbIxpy](https://github.com/hrsh7th/nvim-cmp/assets/81607010/80261c02-9940-4e8c-912c-680cd0366dd8)
map complete
![CopyQ jaFmaW](https://github.com/hrsh7th/nvim-cmp/assets/81607010/f4275388-634b-4579-92f7-6df0d5c5aa0a)

and some suggestion list is ok. I can get consistent result suggestion list
![image](https://github.com/hrsh7th/nvim-cmp/assets/81607010/6dfcfeab-c5c0-4bc1-a6f8-ec95f2c3b2fc)
BingCoke commented 10 months ago

something interesting, image I will get all item above of '@Injectable' but miss item above of class AppService image

In vscode everything is ok. image

BingCoke commented 9 months ago

image The author of typescript-tools there is no problem in lsp, so it cloud be a something wrong in cmp?