dotfiles/.config/nvim/lua/lsp/init.lua

90 lines
2.9 KiB
Lua
Raw Normal View History

local lsp = require_mod("lspconfig")
local mason_lsp = require_mod("mason-lspconfig")
2022-12-24 12:33:46 -05:00
local sign = vim.fn.sign_define
local sign_name = {"Error","Warn","Info","Hint"}
2023-03-12 16:09:11 -04:00
-- Set lsp signs
for k, icon in pairs(vim.g.diagnostic_sings) do
2023-03-12 16:09:11 -04:00
sign("DiagnosticSign" .. sign_name[k],{text=icon,texthl="DiagnosticSign" .. sign_name[k]})
end
2023-03-12 16:09:11 -04:00
-- Settings diagnostics
2022-12-24 12:33:46 -05:00
vim.diagnostic.config {
2023-03-12 16:09:11 -04:00
signs = true,
underline = true,
update_in_insert = false,
severity_sort = false,
2022-12-24 12:33:46 -05:00
2023-03-12 16:09:11 -04:00
virtual_text = {prefix = 'x'},
float = {border = "rounded"},
2022-12-24 12:33:46 -05:00
}
vim.g.lsp_handler = {
2023-03-12 16:09:11 -04:00
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover,{border="rounded"}),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help,{border="rounded"})
2022-12-24 12:33:46 -05:00
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.foldingRange = {
2023-03-12 16:09:11 -04:00
dynamicRegistration = false,
lineFoldingOnly = true,
}
2023-03-12 16:09:11 -04:00
local navic = require("nvim-navic")
vim.g.lsp_capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
2022-12-24 12:33:46 -05:00
2023-08-14 19:28:08 -04:00
vim.g.lsp_on_attach = function(client, bufnr)
2023-03-12 16:09:11 -04:00
print("Attaching to:",client.name)
2023-08-14 19:28:08 -04:00
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set("n", keys, func, {buffer = bufnr, desc = desc})
end
2023-03-12 16:09:11 -04:00
if client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr)
end
2023-08-14 19:28:08 -04:00
nmap('gd', vim.lsp.buf.definition, "[G]oto [D]efinition")
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
2023-03-12 16:09:11 -04:00
2023-08-14 19:28:08 -04:00
nmap('K',vim.lsp.buf.hover, "Hover Documentation")
nmap('[d', vim.diagnostic.goto_prev, "[G]oto previous diagnostic message")
nmap(']d', vim.diagnostic.goto_next, "[G]oto next diagnostic message")
nmap('<leader>e', vim.diagnostic.open_float, "Open floating diagnostic message")
2022-12-24 12:33:46 -05:00
end
local servers = mason_lsp.get_installed_servers()
for _, server in ipairs(servers) do
2023-03-12 16:09:11 -04:00
local ok, result = pcall(require, "lsp.servers."..server)
if ok then
local lsp_server = lsp[server]
if lsp_server ~= nil then
local ok, err = pcall(lsp_server.setup, result)
if err ~= nil then
vim.pretty_print(err)
end
else
vim.pretty_print({server = server, result = result})
2022-12-24 12:33:46 -05:00
end
2023-03-12 16:09:11 -04:00
end
2022-12-24 12:33:46 -05:00
end