hrsh7th / nvim-cmp

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

Nvim 0.9.0: vim.treesitter.query.get_node_text() is deprecated #1513

Closed smitropoulos closed 1 year ago

smitropoulos commented 1 year ago

FAQ

Announcement

Minimal reproducible full config

Base config with this setup

{
            snippet = {
                expand = function(args)
                    luasnip.lsp_expand(args.body)
                end,
            },
            window = {
                completion = cmp.config.window.bordered(),
                documentation = cmp.config.window.bordered(),
            },
            mapping = {
                ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
                ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
                ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
                ["<C-e>"] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close() }),
                ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
                ["<C-p>"] = cmp.mapping.select_prev_item(),
                ["<C-n>"] = cmp.mapping.select_next_item(),
                -- Accept currently selected item. If none selected, `select` first item.
                -- Set `select` to `false` to only confirm explicitly selected items.
                ["<CR>"] = cmp.mapping.confirm({ select = false }),
                ["<Tab>"] = cmp.mapping(function(fallback)
                    if cmp.visible() then
                        cmp.select_next_item()
                    elseif luasnip.expandable() then
                        luasnip.expand()
                    elseif luasnip.expand_or_jumpable() then
                        luasnip.expand_or_jump()
                    else
                        fallback()
                    end
                end, { "i", "s" }),
                ["<S-Tab>"] = cmp.mapping(function(fallback)
                    if cmp.visible() then
                        cmp.select_prev_item()
                    elseif luasnip.jumpable(-1) then
                        luasnip.jump(-1)
                    else
                        fallback()
                    end
                end, { "i", "s" }),
            },
            formatting = {
                fields = { "kind", "abbr", "menu" },
                format = function(entry, vim_item)
                    -- Kind icons
                    -- vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
                    vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
                    vim_item.menu = ({
                        buffer = "[buf]",
                        nvim_lsp = "[lsp]",
                        luasnip = "[snip]",
                        path = "[path]",
                        nvim_lua = "[api]",
                        rg = "[rg]",
                    })[entry.source.name]
                    return vim_item
                end,
            },
            sources = {
                -- Higher number higher prio, upper in the list
                { name = "nvim_lsp", priority = 80, max_item_count = 8 },
                { name = "luasnip", priority = 70, max_item_count = 8 },
                { name = "rg", priority = 65, max_item_count = 4 },
                { name = "buffer", priority = 60, max_item_count = 4 },
                { name = "nvim_lua", priority = 55, max_item_count = 4 },
                { name = "path", priority = 50, max_item_count = 4 },
                { name = "calc", priority = 40, max_item_count = 4 },
                { name = "git", priority = 40, max_item_count = 4 },
            },
            sorting = {
                priority_weight = 1.0,
                comparators = {
                    cmp.config.compare.scopes,
                    cmp.config.compare.offset,
                    cmp.config.compare.exact,
                    cmp.config.compare.score,
                    cmp.config.compare.recently_used,
                    cmp.config.compare.locality,
                    cmp.config.compare.kind, -- compare.sort_text,
                    cmp.config.compare.length,
                    cmp.config.compare.order,
                },
            },
            confirm_opts = {
                behavior = cmp.ConfirmBehavior.Replace,
                select = false,
            },
            experimental = {
                ghost_text = false,
                native_menu = false,
            },
        }

Description

Vim.treesitter.query.get_note_text() is deprecated as of NVIM 0.9.0. It will be removed in version 0.10 and it is advised to be replaced with vim.treesitter.get_node_text() as per :help deprecated.

Steps to reproduce

Open any file and enter insert mode.

Expected behavior

No error or warnigns should be produced.

Actual behavior

Warnings about deprecation are being issued.

Additional context

No response

smitropoulos commented 1 year ago

Tried fixing it locally, changing the line 206 in lua/cmp/config/compare.lua. Changed the method to the one suggested, no warnings after it

uga-rosa commented 1 year ago

Working in #1499

YodaEmbedding commented 1 year ago

Related PRs:

uga-rosa commented 1 year ago

This issue can be closed.