Files
nvim/lua/plugins/lsp.lua
2025-11-04 11:44:29 +01:00

118 lines
3.4 KiB
Lua

return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/cmp-nvim-lsp",
},
config = function()
require("mason").setup()
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
local map = function(keys, func, desc)
vim.keymap.set("n", keys, func, {buffer = event.buf, desc = desc})
end
-- Navigation
map("gd", vim.lsp.buf.definition, "Go to definition")
map("gD", vim.lsp.buf.declaration, "Go to declatation")
map("gi", vim.lsp.buf.implementation, "Go to implementation")
map("gr", vim.lsp.buf.definition, "Go to references")
map("gt", vim.lsp.buf.type_definition, "Go to type definition")
-- Documentation
map("K", vim.lsp.buf.hover, "Hover documentation")
map("<leader>K", vim.lsp.buf.signature_help, "Signature help")
-- LSP Actions
map("<leader>ca", vim.lsp.buf.code_action, "Code action")
map("<leader>cr", vim.lsp.buf.rename, "Rename")
map("<leader>cf", vim.lsp.buf.format, "Format")
-- Diagnostics
map("<leader>do", vim.diagnostic.open_float, "Show diagnostics")
map("<leader>dl", vim.diagnostic.goto_next, "Next diagnostic")
map("<leader>dh", vim.diagnostic.goto_prev, "Previous diagnostic")
map("<leader>dF", vim.diagnostic.setloclist, "Quickfix diagnostics")
map("<leader>da", vim.diagnostic.setloclist, "List diagnostics")
end,
})
local servers = {
-- Javascript/TypeScript/React
ts_ls = {
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
},
},
},
},
-- Hyprland
hyprls = {},
-- CSS/SCSS
cssls = {},
-- stylelint
stylelint_lsp = {},
-- HTML
html = {},
-- PHP
intelephense = {
settings = {
php = {
validate = {
enable = true,
run = "onSave",
},
},
},
},
-- Python
pyright = {},
-- JSON
jsonls = {},
-- TOML
taplo = {},
-- YAML
yamlls = {},
-- Rust
rust_analyzer = {
settings = {
["rust_analyzer"] = {
check = {
command = "clippy"
},
},
},
},
-- Go
gopls = {},
-- Markdown
marksman = {},
-- Lua
lua_ls = {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
},
}
require("mason-lspconfig").setup({
ensure_installed = vim.tbl_keys(servers),
handlers = {
function(server_name)
local config = servers[server_name] or {}
config.capabilities = capabilities
lspconfig[server_name].setup(config)
end,
},
})
end,
}