nvim/after/plugin/lsp.lua
2024-11-11 14:51:12 +02:00

175 lines
4.3 KiB
Lua

local lsp_zero = require("lsp-zero")
local lspconfig = require("lspconfig")
lsp_zero.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp_zero.default_keymaps({ buffer = bufnr })
local opts = { buffer = bufnr, remap = false }
-- Code action
vim.keymap.set("n", "<leader>la", function()
vim.lsp.buf.code_action()
end, opts)
-- Diagnostic
vim.keymap.set("n", "<leader>ld", function()
vim.diagnostic.open_float()
end, opts)
-- Get docs
vim.keymap.set("n", "K", function()
vim.lsp.buf.hover()
end, opts)
-- Jump to definition
vim.keymap.set("n", "gd", function()
vim.lsp.buf.definition()
end)
-- Jump to declaration
vim.keymap.set('n', 'gD', function()
vim.lsp.buf.declaration()
end)
-- Lists all the implementations for the symbol under the cursor
vim.keymap.set('n', 'gi', function()
vim.lsp.buf.implementation()
end)
-- Jumps to the definition of the type symbol
vim.keymap.set('n', 'go', function()
vim.lsp.buf.type_definition()
end)
-- Lists all the references
vim.keymap.set('n', 'gr', function()
vim.lsp.buf.references()
end)
-- -- Displays a function's signature information
-- vim.keymap.set('n', '<C-k>', function()
-- vim.lsp.buf.signature_help()
-- end)
-- Renames all references to the symbol under the cursor
vim.keymap.set('n', '<F2>', function()
vim.lsp.buf.rename()
end)
require("lsp_signature").on_attach({}, bufnr)
end)
vim.filetype.add({ extension = { templ = "templ" } })
lsp_zero.setup_servers({ "gopls", "lua_ls", "nil_ls", "pylsp", "clangd" })
lspconfig.html.setup {
cmd = { "vscode-html-language-server", "--stdio" },
filetypes = { "html" },
init_options = {
configurationSection = { "html", "css", "javascript" },
embeddedLanguages = {
css = true,
javascript = true
},
provideFormatter = true
},
single_file_support = true
}
lspconfig.gopls.setup({
settings = {
gopls = {
hints = {
rangeVariableTypes = true,
parameterNames = true,
constantValues = true,
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
functionTypeParameters = true,
},
}
}
})
lspconfig.lua_ls.setup({
settings = {
Lua = {
workspace = {
checkThirdParty = false,
library = vim.tbl_deep_extend('force', vim.api.nvim_get_runtime_file("", true), {
"${3rd}/luv/library",
"${3rd}/busted/library",
"/usr/share/awesome/lib",
"/usr/share/lua",
}),
},
diagnostics = {
globals = {
"awesome",
"awful",
"client",
"screen",
"tag",
"root",
},
},
runtime = { version = 'LuaJIT' },
completion = { callSnippet = "Replace", },
telemetry = { enable = false, },
}
}
})
-- lspconfig.tailwindcss.setup({
-- filetypes = { "templ", "astro", "javascript", "typescript", "react" },
-- init_options = { userLanguages = { templ = "html" } },
-- })
--
-- lspconfig.htmx.setup({
-- filetypes = { "html", "templ" },
-- })
local cmp = require("cmp")
local cmp_action = require("lsp-zero").cmp_action()
local cmp_select = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
mapping = cmp.mapping.preset.insert({
-- `Enter` key to confirm completion
["<CR>"] = cmp.mapping.confirm({ select = false }),
["<C-j>"] = cmp.mapping.select_next_item(cmp_select),
["<C-k>"] = cmp.mapping.select_prev_item(cmp_select),
["<Tab>"] = cmp.mapping.confirm({ select = true }),
-- Ctrl+Space to trigger completion menu
["<C-Space>"] = cmp.mapping.complete(),
-- Navigate between snippet placeholder
["<C-f>"] = cmp_action.luasnip_jump_forward(),
["<C-b>"] = cmp_action.luasnip_jump_backward(),
-- Scroll up and down in the completion documentation
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
}),
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
sources = {
{ name = 'path' },
{ name = 'nvim_lsp', keyword_length = 1 },
{ name = 'vim-dadbod-completion', keyword_length = 1 },
{ name = 'buffer', keyword_length = 3 },
}
})