hrsh7th / nvim-cmp

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

nvim-cmp/lua/cmp/view .lua:270: attempt to index field 'docs' (a nil value) #1710

Open EdmundsEcho opened 10 months ago

EdmundsEcho commented 10 months ago

FAQ

Announcement

Minimal reproducible full config

    sources = cmp.config.sources({
        { name = "nvim_lsp" },                -- from language server
        { name = "nvim_lsp_signature_help" }, -- display function signatures with current parameter emphasized
        { name = "path" },
        { name = "treesitter" },
        { name = "nvim_lua",               keyword_length = 2 }, -- complete neovim's Lua runtime API such vim.lsp.*
        { name = "vsnip",                  keyword_length = 2 },
        { name = "buffer",                 keyword_length = 2 }, -- source current buffer
        { name = "lspconfig" },                    -- access to all languages
        { name = "cmp_tabnine" },                  -- AI for completion
        { name = "rg" },                           -- ripgrep
        { name = "npm",                    keyword_length = 4 },
        { name = "tmux" },
        { name = "fish" },
        -- cmp clippy
    }),
    view = "wildmenu", -- or 'native' 'wildmenu'
    window = {
        -- completion = cmp.config.window.bordered(),
        -- documentation = cmp.config.window.bordered(),
    },
    formatting = {
        fields = { "menu", "abbr", "kind" },
        format = function(entry, item)
            local menu_icon = {
                nvim_lsp = "λ",
                vsnip = "⋗",
                buffer = "Ω",
                path = "◇",
            }
            item.menu = menu_icon[entry.source.name]
            return item
        end,
    },

Description

neovim generates a list of suggestions. When I select a suggestion, I get an error in the lua source code for this plugin (printed in my messages):

Error executing vim.schedule lua callback: /Users/edmund/.config/nvim/bundle/nvim-cmp/lua/cmp/view
.lua:270: attempt to index field 'docs' (a nil value)

stack traceback:
        /Users/edmund/.config/nvim/bundle/nvim-cmp/lua/cmp/view.lua:270: in function 'callback'
        ...und/.config/nvim/bundle/nvim-cmp/lua/cmp/utils/async.lua:138: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Steps to reproduce

Trigger the display of suggested lints. Hit tab to select one of the choices.

Expected behavior

If the plugin can't find a source, fail quietly.

Actual behavior

Generates error messages in the command region.

Additional context

In a jsx and py files I get a missing key error. Despite my not having looked at the source code, I wonder if the plugin should just fail quietly if the error is cause by not finding a source.

fcomoreira1 commented 9 months ago

I have the exact same problem with OCaml

ddn0 commented 8 months ago

I had a similar issue and I was able to resolve it by removing the custom view configuration.

    view = "wildmenu", -- or 'native' 'wildmenu'

If you do want to keep your custom view configuration, it should at least define the values in https://github.com/hrsh7th/nvim-cmp/blob/51260c02a8ffded8e16162dcf41a23ec90cfba62/lua/cmp/config/default.lua#L93-L101 as https://github.com/hrsh7th/nvim-cmp/blob/51260c02a8ffded8e16162dcf41a23ec90cfba62/lua/cmp/view.lua#L270 depends on view.docs.auto_open being defined.