dot/.config/nvim/lua/plugins/lsp.lua

125 lines
3.3 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,
}
}
}
}
}
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",
},
handlers = {
function(server_name)
require('lspconfig')[server_name].setup(configs[server_name] or {})
end,
}
})
end
},
}