dotfiles/nvim/lua/plugins/40-lsp.lua

170 lines
5.1 KiB
Lua

local servers = {
-- LSPs
"json-lsp",
"lua_ls",
"ruby_lsp",
"rubocop",
"rust_analyzer",
"terraformls",
-- Formatters
"fixjson",
"goimports",
"hclfmt",
"prettierd",
"shellharden",
"stylua",
"yamlfix",
--- Linters
"swiftlint",
}
return {
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
dependencies = {
"mason-org/mason-lspconfig.nvim",
},
opts = {
ensure_installed = servers,
},
},
{
"mason-org/mason-lspconfig.nvim",
opts = {
ensure_installed = {},
automatic_enable = true,
automatic_installation = false,
},
dependencies = {
{ "mason-org/mason.nvim", opts = {} },
"neovim/nvim-lspconfig",
},
-- config = function()
-- require("mason-lspconfig").setup({
-- ensure_installed = {},
-- automatic_enable = true,
-- automatic_installation = false,
-- })
-- -- local lsp_dir = vim.fn.stdpath("config") .. "/lsp"
-- -- local configs = {}
-- -- if vim.fn.isdirectory(lsp_dir) == 1 then
-- -- for _, file in ipairs(vim.fn.readdir(lsp_dir)) do
-- -- if file:match("%.lua$") and file ~= "init.lua" then
-- -- local server_name = file:gsub("%.lua$", "")
-- -- local settings = loadfile(vim.fn.resolve(lsp_dir .. "/" .. file))()
-- -- configs[server_name] = settings
-- -- end
-- -- end
-- -- end
-- -- for server_name, config in pairs(configs) do
-- -- print(vim.inspect(config))
-- -- vim.lsp.config(server_name, config)
-- -- end
-- end,
},
{
"neovim/nvim-lspconfig",
dependencies = {
"mason-org/mason.nvim",
"mason-org/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
{ "j-hui/fidget.nvim", opts = {} },
"saghen/blink.cmp",
},
config = function()
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }),
callback = function(event)
local map = function(keys, func, desc, mode)
vim.keymap.set(mode or "n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
end
map("grn", vim.lsp.buf.rename, "[R]e[n]ame")
map("ga", vim.lsp.buf.code_action, "[g]oto [a]ction", { "n", "x" })
map("gtr", require("telescope.builtin").lsp_references, "[g]o[t]o [r]eferences")
map("gti", require("telescope.builtin").lsp_implementations, "[g]o[t]o [i]mplementation")
map("gtd", require("telescope.builtin").lsp_definitions, "[g]o[t]o [d]efinition")
map("gtD", vim.lsp.buf.declaration, "[g]o[t]o [D]eclaration")
map("gtt", require("telescope.builtin").lsp_type_definitions, "[g]o[t]o [t]ype Definition")
map("gsb", require("telescope.builtin").lsp_document_symbols, "[g]oto [s]ymbols in [b]uffer")
map(
"gsw",
require("telescope.builtin").lsp_dynamic_workspace_symbols,
"[g]oto [s]ymbols in [w]orkspace"
)
local client = vim.lsp.get_client_by_id(event.data.client_id)
local augroup = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
if not client then
return
end
if client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
local highlight_augroup = augroup("kickstart-lsp-highlight", { clear = false })
autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
autocmd("LspDetach", {
group = augroup("kickstart-lsp-detach", { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({
group = "kickstart-lsp-highlight",
buffer = event2.buf,
})
end,
})
end
if client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
map("<leader>th", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
end, "[T]oggle Inlay [H]ints")
end
end,
})
end,
},
}
-- {
-- config = function()
-- -- Diagnostic Config
-- -- See :help vim.diagnostic.Opts
-- vim.diagnostic.config({
-- severity_sort = true,
-- float = { border = "rounded", source = "if_many" },
-- underline = { severity = vim.diagnostic.severity.ERROR },
-- signs = vim.g.have_nerd_font and {
-- text = {
-- [vim.diagnostic.severity.ERROR] = "󰅚 ",
-- [vim.diagnostic.severity.WARN] = "󰀪 ",
-- [vim.diagnostic.severity.INFO] = "󰋽 ",
-- [vim.diagnostic.severity.HINT] = "󰌶 ",
-- },
-- } or {},
-- virtual_text = {
-- source = "if_many",
-- spacing = 2,
-- format = function(diagnostic)
-- local diagnostic_message = {
-- [vim.diagnostic.severity.ERROR] = diagnostic.message,
-- [vim.diagnostic.severity.WARN] = diagnostic.message,
-- [vim.diagnostic.severity.INFO] = diagnostic.message,
-- [vim.diagnostic.severity.HINT] = diagnostic.message,
-- }
-- return diagnostic_message[diagnostic.severity]
-- end,
-- },
-- })
-- end,
-- },