dot/.config/nvim/lua/plugins/lsp.lua
2025-10-17 12:34:42 +02:00

179 lines
4.5 KiB
Lua

return {
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
{ "L3MON4D3/LuaSnip" },
},
config = function()
local cmp = require("cmp")
cmp.setup({
completion = {
completeopt = "menu,menuone",
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-c>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
},
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif require("luasnip").expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
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(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
else
fallback()
end
end, {
"i",
"s",
}),
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "nvim_lua" },
{ name = "path" },
},
})
end,
},
-- LSP
{
"neovim/nvim-lspconfig",
cmd = "LspInfo",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
{ "hrsh7th/cmp-nvim-lsp" },
{ "williamboman/mason-lspconfig.nvim" },
{ "williamboman/mason.nvim" },
},
config = function()
configs = {
pylsp = {
settings = {
pylsp = {
plugins = {
mypy = { enabled = true },
black = { enabled = true },
isort = { enabled = true, profile = "black" },
},
},
},
},
ruff = {
init_options = {
settings = {
configuration = "~/.config/nvim/configs/ruff.toml",
organizeImports = false,
showSyntaxErrors = false,
}
}
},
pyright = {
settings = {
pyright = {
disableOptimizeImports = true,
},
python = {
analysis = {
typeCheckingMode = "basic",
autoImportCompletions = false,
}
}
}
},
kotlin_lsp = {
settings = {
kotlin = {
analysis = {
autoSearchClasspath = true,
}
}
}
}
}
for k, v in pairs(configs) do
vim.lsp.config(k, v)
end
vim.lsp.enable({
"lua_ls",
"gopls",
"pyright",
"ruff",
"ts_ls",
"kotlin_lsp"
})
require('mason').setup({})
require('mason-lspconfig').setup({
-- Replace the language servers listed here
-- with the ones you want to install
ensure_installed = {
"lua_ls",
"gopls",
"pyright",
"ruff",
"ts_ls",
"kotlin_lsp"
},
})
end
},
{
"folke/trouble.nvim",
opts = {}, -- for default options, refer to the configuration section for custom setup.
cmd = "Trouble",
keys = {
{
"<leader>xx",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>xX",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>cs",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>cl",
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
desc = "LSP Definitions / references / ... (Trouble)",
},
{
"<leader>xL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>xQ",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
}
}