Updated lspconfig to support new nvim lsp configuration via vim.lsp

This commit is contained in:
2025-06-08 12:26:11 +02:00
parent 16a77a5e42
commit 15bd852a77
9 changed files with 130 additions and 146 deletions

View File

@@ -1,28 +1,28 @@
{
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"catppuccin": { "branch": "main", "commit": "5b5e3aef9ad7af84f463d17b5479f06b87d5c429" },
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
"catppuccin": { "branch": "main", "commit": "fa42eb5e26819ef58884257d5ae95dd0552b9a66" },
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" },
"cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" },
"cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" },
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
"copilot-cmp": { "branch": "master", "commit": "15fc12af3d0109fa76b60b5cffa1373697e261d1" },
"fidget.nvim": { "branch": "main", "commit": "4e854f3299e21d1c18279add340428a97520fc44" },
"friendly-snippets": { "branch": "main", "commit": "31f2a2657b6261724313281fe0d8ba6f43f4a4fa" },
"fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" },
"friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },
"git-worktree.nvim": { "branch": "master", "commit": "f247308e68dab9f1133759b05d944569ad054546" },
"harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" },
"mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" },
"neoconf.nvim": { "branch": "main", "commit": "0c3cb10a7ff11acfa3067896a6108db3bd18d8aa" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "bef29b653ba71d442816bf56286c2a686210be04" },
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
"neoconf.nvim": { "branch": "main", "commit": "00c0fadc851dc2ede0e4955022fb8a5df1c30ca4" },
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
"nvim-lspconfig": { "branch": "master", "commit": "e39da6a820d2a700904117d29f0dd476d64262cf" },
"nvim-treesitter": { "branch": "master", "commit": "7bbed4b548d9a81c14351bda93d16336edefd067" },
"nvim-lspconfig": { "branch": "master", "commit": "036885e8e5456d3907626b634693234f628afef6" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" },
"undotree": { "branch": "master", "commit": "b951b87b46c34356d44aa71886aecf9dd7f5788a" },
"vim-fugitive": { "branch": "master", "commit": "4a745ea72fa93bb15dd077109afbb3d1809383f2" },
"vim-tmux-navigator": { "branch": "master", "commit": "791dacfcfc8ccb7f6eb1c853050883b03e5a22fe" },
"vim-tmux-navigator": { "branch": "master", "commit": "97e58f2b3b4f8fd30ce149302f10202f363cc361" },
"vimwiki": { "branch": "dev", "commit": "72792615e739d0eb54a9c8f7e0a46a6e2407c9e8" }
}

View File

@@ -0,0 +1,6 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('clangd', {
capabilities = capabilities,
})

View File

@@ -0,0 +1,6 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('eslint', {
capabilities = capabilities,
})

View File

@@ -0,0 +1,13 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('lua_ls', {
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
})

View File

@@ -0,0 +1,6 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('pylsp', {
capabilities = capabilities,
})

View File

@@ -0,0 +1,6 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('rust_analyzer', {
capabilities = capabilities,
})

View File

@@ -0,0 +1,6 @@
local cmp_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_lsp.default_capabilities()
vim.lsp.config('ts_ls', {
capabilities = capabilities,
})

View File

@@ -1,77 +1,13 @@
return {
{
'neovim/nvim-lspconfig',
dependencies = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'folke/neoconf.nvim',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'hrsh7th/nvim-cmp',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
{ 'j-hui/fidget.nvim', tag = 'v1.4.0' },
keys = {
{ "<space>e", vim.diagnostic.open_float, mode = "n", desc = "Open diagnostic float" },
{ "[d", vim.diagnostic.goto_prev, mode = "n", desc = "Go to previous diagnostic" },
{ "]d", vim.diagnostic.goto_next, mode = "n", desc = "Go to next diagnostic" },
{ "<space>q", vim.diagnostic.setloclist, mode = "n", desc = "Set location list with diagnostics" },
},
config = function()
local cmp = require('cmp')
local cmp_lsp = require('cmp_nvim_lsp')
local capabilities = cmp_lsp.default_capabilities()
require('fidget').setup({})
require('mason').setup()
require('mason-lspconfig').setup({
ensure_installed = { 'eslint', 'ts_ls', 'rust_analyzer', 'lua_ls', 'clangd', 'volar', 'pylsp' },
})
require("mason-lspconfig").setup_handlers {
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
local server_config = {
capabilities = capabilities,
}
if require("neoconf").get(server_name .. ".disable") then -- disable servers with neoconfg
return
end
if server_name == "volar" then -- TODO: fix for tsserver should i keep this can i just uninstall tsserver and use only volar?
server_config.filetypes = { 'vue', 'typescript', 'javascript' }
end
require("lspconfig")[server_name].setup(server_config)
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
-- ["rust_analyzer"] = function ()
-- require("rust-tools").setup {}
-- end
-- configure lua server to fix vim warning
["lua_ls"] = function()
local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup {
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
}
end,
}
-- end mason_lspconfig setup handlers
-- setup keymaps:
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
@@ -99,7 +35,20 @@ return {
end,
})
-- Set up diagnostics
vim.diagnostic.config({
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
}
})
-- Set up cmp
local cmp = require('cmp')
local cmp_select_behavior = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
@@ -136,45 +85,68 @@ return {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
}),
sources = cmp.config.sources({
{ name = 'luasnip' }, -- For luasnip users.
{ name = 'nvim_lsp' },
{ name = 'path' },
-- Copilot Source
{ name = "copilot", group_index = 2 },
},
{
{ name = 'buffer' },
})
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'buffer' },
-- Copilot Source
{ name = "copilot", group_index = 2 },
}),
})
end,
dependencies = {
'L3MON4D3/LuaSnip',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'hrsh7th/nvim-cmp',
'saadparwaiz1/cmp_luasnip',
{ 'j-hui/fidget.nvim', opts = {} },
},
},
-- end cmp setup
{
'mason-org/mason-lspconfig.nvim',
dependencies = {
{ 'mason-org/mason.nvim', opts = {} },
'neovim/nvim-lspconfig',
},
vim.diagnostic.config({
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
}
})
opts = {
ensure_installed = { 'eslint', 'ts_ls', 'rust_analyzer', 'lua_ls', 'clangd', 'pylsp' },
},
},
-- keymaps for snippet navigation
--
{
"L3MON4D3/LuaSnip", -- Snippet engine
keys = {
-- Move up in snippet fields
local ls = require('luasnip')
vim.keymap.set({ "i", "s" }, "<C-k>", function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, { silent = true })
{
"<C-k>",
function()
local ls = require("luasnip")
if ls.jumpable(-1) then
ls.jump(-1)
end
end,
mode = { "i", "s" },
desc = "Jump to the previous snippet field",
silent = true,
},
-- Move down in snippet fields
vim.keymap.set({ "i", "s" }, "<C-j>", function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, { silent = true })
end
}
{
"<C-j>",
function()
local ls = require("luasnip")
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end,
mode = { "i", "s" },
desc = "Expand or jump to the next snippet field",
silent = true,
},
},
},
}

View File

@@ -1,31 +0,0 @@
return {
{
'folke/neoconf.nvim',
opts = {
-- override any of the default settings here
plugins = {
-- configures lsp clients with settings in the following order:
-- - lua settings passed in lspconfig setup
-- - global json settings
-- - local json settings
lspconfig = {
enabled = true,
},
-- configures jsonls to get completion in .nvim.settings.json files
jsonls = {
enabled = true,
-- only show completion in json settings for configured lsp servers
configured_servers_only = false,
},
-- configures lua_ls to get completion of lspconfig server settings
lua_ls = {
-- by default, lua_ls annotations are only enabled in your neovim config directory
enabled_for_neovim_config = true,
-- explicitely enable adding annotations. Mostly relevant to put in your local .nvim.settings.json file
enabled = false,
},
},
}
}
}