admin管理员组文章数量:1316030
I've been trying to get my autocomplete working. It works when I hit ctr space but everything I get says text.
Here is my lsp config:
local on_attach = function(_,_)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {})
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {})
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {})
vim.keymap.set('n', 'gr', vim.lsp.buf.references, {})
end
return {
{
"williamboman/mason.nvim",
config = function()
require("mason").setup()
end,
},
{
"williamboman/mason-lspconfig.nvim",
dependencies = { "williamboman/mason.nvim" }, -- Ensure Mason is loaded first
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"clangd",
"ts_ls",
"omnisharp",
"lua_ls", -- Correct LSP name for Lua
},
})
end,
},
{
"neovim/nvim-lspconfig",
dependencies = { "williamboman/mason-lspconfig.nvim" }, -- Ensure LSP configurations are loaded after Mason
config = function()
require("lspconfig").lua_ls.setup({on_attach = on_attach, settings = {Lua = {completion = {callSnippet ="Replace", enable=true,}}}})
require("lspconfig").ts_ls.setup({on_attack = on_attach})
require("lspconfig").clangd.setup({on_attach = on_attach})
require("lspconfig").omnisharp.setup({on_attach = on_attach})
end,
},
}
Here is my cmp config:
return {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"rafamadriz/friendly-snippets",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
completion = {
completeopt = "menu,menuone,preview,noselect"
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({ -- Fix here
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-Space>"] = cmp.mappingplete(), -- Fix here
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
})
})
end
}
I'm not really sure what I'm doing wrong. I straight up don't get any autocompletes at all, only if I hit ctrl space. I get snippets sometimes, but I'm not really sure why I'm not getting any lsp recommendations. I've already confirmed that my lsp is working properly. I get all the errors and stuff however I'm not sure why this specifically isn't working.
I've been trying to get my autocomplete working. It works when I hit ctr space but everything I get says text.
Here is my lsp config:
local on_attach = function(_,_)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {})
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {})
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {})
vim.keymap.set('n', 'gr', vim.lsp.buf.references, {})
end
return {
{
"williamboman/mason.nvim",
config = function()
require("mason").setup()
end,
},
{
"williamboman/mason-lspconfig.nvim",
dependencies = { "williamboman/mason.nvim" }, -- Ensure Mason is loaded first
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"clangd",
"ts_ls",
"omnisharp",
"lua_ls", -- Correct LSP name for Lua
},
})
end,
},
{
"neovim/nvim-lspconfig",
dependencies = { "williamboman/mason-lspconfig.nvim" }, -- Ensure LSP configurations are loaded after Mason
config = function()
require("lspconfig").lua_ls.setup({on_attach = on_attach, settings = {Lua = {completion = {callSnippet ="Replace", enable=true,}}}})
require("lspconfig").ts_ls.setup({on_attack = on_attach})
require("lspconfig").clangd.setup({on_attach = on_attach})
require("lspconfig").omnisharp.setup({on_attach = on_attach})
end,
},
}
Here is my cmp config:
return {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"rafamadriz/friendly-snippets",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
completion = {
completeopt = "menu,menuone,preview,noselect"
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({ -- Fix here
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-Space>"] = cmp.mappingplete(), -- Fix here
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
})
})
end
}
I'm not really sure what I'm doing wrong. I straight up don't get any autocompletes at all, only if I hit ctrl space. I get snippets sometimes, but I'm not really sure why I'm not getting any lsp recommendations. I've already confirmed that my lsp is working properly. I get all the errors and stuff however I'm not sure why this specifically isn't working.
Share Improve this question edited Jan 30 at 9:45 lcheylus 2,4531 gold badge19 silver badges34 bronze badges asked Jan 29 at 23:18 Haroon AlmadaniHaroon Almadani 112 bronze badges1 Answer
Reset to default 1First, I have checked several times, but I don't see you have cmp-lsp
in your config. After you have installed cmp-lsp
you have to pass capabilities to the server setup table like in this example:
{
"neovim/nvim-lspconfig",
dependencies = { "williamboman/mason-lspconfig.nvim", "hrsh7th/cmp-nvim-lsp" },
config = function()
local lspconfig = require("lspconfig")
local on_attach = function(_, _)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {})
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
vim.keymap.set("n", "gr", vim.lsp.buf.references, {})
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())
lspconfig.lua_ls.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = { Lua = { completion = { callSnippet = "Replace", enable = true } } },
})
end,
}
You have to pass the capabilities
to every server you set. You can automatically do that with a loop to avoid repetition.
I'd recommend you to check kickstart.nvim if you haven't. It is an amazing starting point to learn about Neovim config.
本文标签: neovimNVIM Cmp LSP autocomplete not working Using masonnvim alongside nvimcmpStack Overflow
版权声明:本文标题:neovim - NVIM Cmp LSP autocomplete not working. Using mason.nvim alongside nvim-cmp - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741993123a2409506.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论