ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.83k stars 451 forks source link

/lua/modules/configs/completion\cmp.lua:95: attempt to concatenate a nil value #634

Closed Qejun closed 1 year ago

Qejun commented 1 year ago

Version confirmation

Following prerequisites

Neovim version

NVIM v0.8.3 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compiled by runneradmin@fv-az171-224 Features: -acl +iconv +tui See ":help feature-compile" system vimrc file: "$VIM\sysinit.vim" fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"

Operating system/version

win10 22h2

Terminal name/version

PowerShell 7.3.3

$TERM environment variable

No response

Branch info

main (Default/Latest)

Fetch Preferences

SSH (use_ssh = true)

How to reproduce the issue

I get this error every time I try to type a letter Error executing vim.schedule lua callback: ...ppData\Local\nvim/lua/modules/configs/completion\cmp.lua:95: attempt to concatenate a nil value
stack traceback: ...ppData\Local\nvim/lua/modules/configs/completion\cmp.lua:95: in function 'format' ...ata/Local/nvim-data/site/lazy/nvim-cmp/lua/cmp/entry.lua:290: in function 'callback'
...cal/nvim-data/site/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'get_vim_item' ...ata/Local/nvim-data/site/lazy/nvim-cmp/lua/cmp/entry.lua:397: in function 'callback'
...cal/nvim-data/site/lazy/nvim-cmp/lua/cmp/utils/cache.lua:38: in function 'match' ...ta/Local/nvim-data/site/lazy/nvim-cmp/lua/cmp/source.lua:114: in function 'get_entries' ...ta/Local/nvim-data/site/lazy/nvim-cmp/lua/cmp/source.lua:352: in function 'cb' vim/_editor.lua:248: in function <vim/_editor.lua:247>

screen

Expected behavior

what should i do to solve this problem?

Actual behavior

screen

Additional information

This is what "checkhealth" outputs:

gitsigns: require("gitsigns.health").check()

lazy: require("lazy.health").check()

lazy.nvim

man: require("man.health").check()

mason: require("mason.health").check()

mason.nvim report

`

`

null-ls: require("null-ls.health").check()

nvim: health#nvim#check

Configuration

Performance

Remote Plugins

nvim-treesitter: require("nvim-treesitter.health").check()

Installation

OS Info:

{ machine = "x86_64", release = "10.0.19045", sysname = "Windows_NT", version = "Windows 10 Pro" }

Parser/Features H L F I J

provider: health#provider#check

Clipboard (optional)

Python 3 provider (optional)

Python virtualenv

Ruby provider (optional)

Node.js provider (optional)

Perl provider (optional)

vim.lsp: require("vim.lsp.health").check()

vim.treesitter: require("vim.treesitter.health").check()

which_key: health#which_key#check

WhichKey: checking conflicting keymaps

vollowx commented 1 year ago

Maybe the same as #624 ?

Qejun commented 1 year ago

Maybe the same as #624 ?

I think you have a point,After I commented out the relevant code, the problem disappeared along with the Nerd fonts icon.

2023-04-09 142647

file in :nvim\lua\modules\configs\completion\cmp.lua

Jint-lzxy commented 1 year ago

@Qejun https://github.com/ayamir/nvimdots/commit/d506a191287ef5e02de799e4340f5fc2889470a6 implemented a temporary workaround, you only need to pull the latest changes.

This is part of the v0.9 migration.

Qejun commented 1 year ago

I pulled the new config file, but didn't upgrade nvim from 0.8 to 0.9, so my problem was not solved. I took the suggestion in https://github.com/ayamir/nvimdots/issues/624 and the solution in version 0.8 is as follows: file in \nvim\lua\modules\configs\completion\cmp.lua

return function()
    local icons = {
        kind = require("modules.utils.icons").get("kind"),
        type = require("modules.utils.icons").get("type"),
        cmp = require("modules.utils.icons").get("cmp"),
    }
    local t = function(str)
        return vim.api.nvim_replace_termcodes(str, true, true, true)
    end

    local border = function(hl)
        return {
            { "╭", hl },
            { "─", hl },
            { "╮", hl },
            { "│", hl },
            { "╯", hl },
            { "─", hl },
            { "╰", hl },
            { "│", hl },
        }
    end

    ---Handling situations where LuaSnip failed to perform any jumps
    ---@param r integer @Cursor position (row) before calling LuaSnip
    ---@param c integer @Cursor position (col) before calling LuaSnip
    ---@param fallback function @Fallback function inherited from cmp
    local luasnip_fallback = vim.schedule_wrap(function(r, c, fallback)
        local _r, _c = unpack(vim.api.nvim_win_get_cursor(0))
        if _r == r and _c == c then
            fallback()
        end
    end)

    local cmp_window = require("cmp.utils.window")

    cmp_window.info_ = cmp_window.info
    cmp_window.info = function(self)
        local info = self:info_()
        info.scrollable = false
        return info
    end

    local compare = require("cmp.config.compare")
    compare.lsp_scores = function(entry1, entry2)
        local diff
        if entry1.completion_item.score and entry2.completion_item.score then
            diff = (entry2.completion_item.score * entry2.score) - (entry1.completion_item.score * entry1.score)
        else
            diff = entry2.score - entry1.score
        end
        return (diff < 0)
    end

    local lspkind = require("lspkind")
    local cmp = require("cmp")
    local kind_icons = {
        Class = "ﴯ",
        -- Class = "",
        -- Class = "",
        Color = "",
        -- Color = "",
        Constant = "",
        -- Constant = "",
        Constructor = "",
        -- Constructor = "",
        -- Constructor = "",
        Enum = "",
        EnumMember = "",
        Event = "",
        Field = "ﰠ",
        -- Field = "",
        -- Field = "",
        -- Field = "",
        File = "",
        -- File = "",
        -- File = "",
        Folder = "",
        -- Folder = "",
        Function = "",
        Interface = "",
        Keyword = "",
        Method = "",
        Module = "",
        Operator = "",
        Property = "",
        -- Property = "ﰠ",
        Reference = "",
        -- Reference = "",
        -- Reference = "",
        Snippet = "",
        -- Snippet = "",
        Struct = "פּ",
        -- Struct = "",
        Text = "",
        -- Text = "",
        TypeParameter = "",
        -- TypeParameter = "",
        Unit = "",
        Value = "",
        Variable = "",
        -- Variable = "",
        -- Variable = "",
        -- tree-sitter
        String = "",
    }

    cmp.setup({
        window = {
            completion = {
                border = border("Normal"),
                max_width = 80,
                max_height = 20,
            },
            documentation = {
                border = border("CmpDocBorder"),
            },
        },
        sorting = {
            priority_weight = 2,
            comparators = {
                require("copilot_cmp.comparators").prioritize,
                require("copilot_cmp.comparators").score,
                -- require("cmp_tabnine.compare"),
                compare.offset,
                compare.exact,
                compare.lsp_scores,
                require("cmp-under-comparator").under,
                compare.kind,
                compare.sort_text,
                compare.length,
                compare.order,
            },
        },
        --formatting = {
        --  fields = { "kind", "abbr", "menu" },
        --  format = function(entry, vim_item)
        --      local kind = lspkind.cmp_format({
        --          mode = "symbol_text",
        --          maxwidth = 50,
        --          symbol_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp),
        --      })(entry, vim_item)
        --      local strings = vim.split(kind.kind, "%s", { trimempty = true })
        --      kind.kind = " " .. strings[1] .. " "
        --      kind.menu = "    (" .. strings[2] .. ")"
        --      return kind
        --  end,
        --},
        formatting = {
            format = function(entry, vim_item)
                local icon = kind_icons[vim_item.kind] or "default icon or text"
                vim_item.kind = icon .. " " .. vim_item.kind
                return vim_item
            end,
        },
        -- You can set mappings if you want
        mapping = cmp.mapping.preset.insert({
            ["<CR>"] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }),
            ["<C-p>"] = cmp.mapping.select_prev_item(),
            ["<C-n>"] = cmp.mapping.select_next_item(),
            ["<C-d>"] = cmp.mapping.scroll_docs(-4),
            ["<C-f>"] = cmp.mapping.scroll_docs(4),
            ["<C-w>"] = cmp.mapping.close(),
            ["<Tab>"] = cmp.mapping(function(fallback)
                if cmp.visible() then
                    cmp.select_next_item()
                elseif require("luasnip").expand_or_locally_jumpable() then
                    local _r, _c = unpack(vim.api.nvim_win_get_cursor(0))
                    vim.fn.feedkeys(t("<Plug>luasnip-expand-or-jump"))
                    luasnip_fallback(_r, _c, fallback)
                else
                    fallback()
                end
            end, { "i", "s" }),
            ["<S-Tab>"] = cmp.mapping(function(fallback)
                if cmp.visible() then
                    cmp.select_prev_item()
                elseif require("luasnip").jumpable(-1) then
                    vim.fn.feedkeys(t("<Plug>luasnip-jump-prev"), "")
                else
                    fallback()
                end
            end, { "i", "s" }),
        }),
        snippet = {
            expand = function(args)
                require("luasnip").lsp_expand(args.body)
            end,
        },
        -- You should specify your *installed* sources.
        sources = {
            { name = "nvim_lsp" },
            { name = "nvim_lua" },
            { name = "luasnip" },
            { name = "path" },
            { name = "treesitter" },
            { name = "spell" },
            { name = "tmux" },
            { name = "orgmode" },
            { name = "buffer" },
            { name = "latex_symbols" },
            { name = "copilot" },
            -- { name = "codeium" },
            -- { name = "cmp_tabnine" },
        },
    })
end
CharlesChiuGit commented 1 year ago

637 is coming. Hang tight!