Files
lua-nvim/lua/cargdev/plugins/lsp/lspconfig.lua
2025-07-06 14:37:08 -04:00

128 lines
3.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"hrsh7th/cmp-nvim-lsp",
{ "antosha417/nvim-lsp-file-operations", config = true },
{ "folke/neodev.nvim", opts = {} },
{
"pmizio/typescript-tools.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
},
},
config = function()
local lspconfig = require("lspconfig")
local mason_lspconfig = require("mason-lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local keymap = vim.keymap
mason_lspconfig.setup({
ensure_installed = {
"cssls",
"emmet_ls",
"eslint",
"gopls",
"graphql",
"html",
-- "jdtls", -- uncomment if youre actively doing Java
"lua_ls",
"prismals",
"pyright",
"svelte",
"tailwindcss",
},
})
local capabilities = cmp_nvim_lsp.default_capabilities()
vim.diagnostic.config({
signs = {
severity = {
min = vim.diagnostic.severity.WARN,
},
icons = {
Error = "",
Warn = "",
Hint = "󰠠 ",
Info = "",
},
},
})
local servers = {
cssls = {},
emmet_ls = {},
eslint = {},
gopls = {},
graphql = {},
html = {},
-- jdtls = {}, -- same here
lua_ls = {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
},
},
},
prismals = {},
pyright = {},
svelte = {},
tailwindcss = {},
}
for server, config in pairs(servers) do
config.capabilities = capabilities
lspconfig[server].setup(config)
end
-- ✅ Correct way to setup typescript-tools
require("typescript-tools").setup({
capabilities = capabilities,
-- optional settings:
-- settings = {
-- tsserver_plugins = {},
-- tsserver_max_memory = 4096,
-- }
})
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
local opts = { buffer = ev.buf, silent = true }
local mappings = {
["gR"] = { "<cmd>Telescope lsp_references<CR>", "Show LSP references" },
["gD"] = { vim.lsp.buf.declaration, "Go to declaration" },
["gd"] = { "<cmd>Telescope lsp_definitions<CR>", "Show LSP definitions" },
["gi"] = { "<cmd>Telescope lsp_implementations<CR>", "Show LSP implementations" },
["gt"] = { "<cmd>Telescope lsp_type_definitions<CR>", "Show LSP type definitions" },
["<leader>ca"] = { vim.lsp.buf.code_action, "See available code actions" },
["<leader>rn"] = { vim.lsp.buf.rename, "Smart rename" },
["<leader>D"] = { "<cmd>Telescope diagnostics bufnr=0<CR>", "Show buffer diagnostics" },
["<leader>dd"] = { vim.diagnostic.open_float, "Show line diagnostics" },
["[d"] = { vim.diagnostic.goto_prev, "Go to previous diagnostic" },
["]d"] = { vim.diagnostic.goto_next, "Go to next diagnostic" },
["K"] = { vim.lsp.buf.hover, "Show documentation for cursor" },
["<leader>rs"] = { ":LspRestart<CR>", "Restart LSP" },
}
for key, map in pairs(mappings) do
keymap.set("n", key, map[1], { desc = map[2], silent = true })
end
vim.api.nvim_create_autocmd("CursorHold", {
buffer = ev.buf,
callback = function()
vim.diagnostic.open_float(nil, { focusable = false })
end,
})
vim.o.updatetime = 250
end,
})
end,
}