dot/.config/nvim/lua/plugins/lsp.lua
2024-03-26 12:26:31 +01:00

113 lines
2.9 KiB
Lua

return {
{
"VonHeikemen/lsp-zero.nvim",
branch = "v2.x",
lazy = true,
config = function()
require("lsp-zero.settings").preset({})
end,
},
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
{ "L3MON4D3/LuaSnip" },
},
config = function()
require("lsp-zero.cmp").extend()
local cmp = require("cmp")
local cmp_action = require("lsp-zero.cmp").action()
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()
local lsp = require("lsp-zero")
lsp.ensure_installed(
{
"lua_ls",
"gopls",
"pylsp",
"tsserver",
}
)
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({ buffer = bufnr })
end)
local read_exec_path = function(exec_name)
local handle = io.popen("which " .. exec_name)
local result = handle:read("*a"):gsub("\n", "")
handle:close()
return result
end
nvim_lsp = require("lspconfig")
nvim_lsp.lua_ls.setup(lsp.nvim_lua_ls())
nvim_lsp.gopls.setup({})
nvim_lsp.dartls.setup({})
nvim_lsp.pylsp.setup({})
nvim_lsp.tsserver.setup({})
lsp.setup()
end,
},
}