lua cmp/lsp-config 仅自动完成标准函数/结构,不会自动完成本地变量和函数

问题描述 投票:0回答:1

使用我当前的

lspconfig
插件的 nvim 设置:

return {

    {
        "williamboman/mason.nvim",
        config = function()
            require("mason").setup({})
        end
    },
    {
        "williamboman/mason-lspconfig.nvim",
        config = function()
            require("mason-lspconfig").setup({
                    ensure_installed = { "lua_ls", "clangd" }
            })
        end
    },
    {
        "neovim/nvim-lspconfig",
        config = function()
            local cmp_lsp = require("cmp_nvim_lsp")
            local capabilities =  vim.tbl_deep_extend(
                "force",
                {},
                vim.lsp.protocol.make_client_capabilities(),
                cmp_lsp.default_capabilities()
            )
            local lspconfig = require("lspconfig")
            lspconfig.lua_ls.setup({
                capabilities = capabilities
            })
            lspconfig.clangd.setup({
                capabilities = capabilities
            })
            vim.keymap.set('n', 'K', vim.lsp.buf.hover, {})
            vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {})
            vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, {})
        end
    }

对于完成:

return {
    {
        "hrsh7th/cmp-nvim-lsp"
    },
    {
        'L3MON4D3/LuaSnip',
        dependencies = {
            'saadparwaiz1/cmp_luasnip',
            "rafamadriz/friendly-snippets",
        },
    },
    {
        'hrsh7th/nvim-cmp',
        config = function()
           local cmp = require'cmp'
            require("luasnip.loaders.from_vscode").lazy_load()
            cmp.setup({
                snippet = {
                    expand = function(args)
                        require('luasnip').lsp_expand(args.body)
                    end,
                },
                window = {
                    completion = cmp.config.window.bordered(),
                    documentation = cmp.config.window.bordered(),
                },
                mapping = cmp.mapping.preset.insert({
                    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
                    ['<C-f>'] = cmp.mapping.scroll_docs(4),
                    ['<C-Space>'] = cmp.mapping.complete(),
                    ['<C-e>'] = cmp.mapping.abort(),
                    ['<CR>'] = cmp.mapping.confirm({ select = true }), 
                }),
                sources = cmp.config.sources({
                    { name = 'nvim-lsp' },
                    { name = 'luasnip' }, 
                    { name = 'buffer' },
                })
            }) 
        end
    }
}

问题是自动补全显示片段,不显示任何错误,并且工作得很好,除了它不自动补全我自己定义的变量和函数这一事实。

我尝试使用

:LspInfo
:LspLog
检查其中是否存在隐藏的错误,但没有真正显示出来。语言服务器已连接并且工作正常。

autocomplete neovim language-server-protocol
1个回答
0
投票

更改此行:

{ name = 'nvim-lsp' },

{ name = 'nvim_lsp' },
© www.soinside.com 2019 - 2024. All rights reserved.