2023-01-03 14:13:09 -05:00
|
|
|
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
|
2023-01-03 14:13:09 -05:00
|
|
|
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]})
|
2023-01-03 14:13:09 -05:00
|
|
|
end
|
2023-01-01 15:52:12 -05:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-03 14:13:09 -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-01-03 14:13:09 -05:00
|
|
|
}
|
|
|
|
|
2023-03-12 16:09:11 -04:00
|
|
|
local navic = require("nvim-navic")
|
|
|
|
|
2023-01-03 14:13:09 -05:00
|
|
|
vim.g.lsp_capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
2022-12-24 12:33:46 -05:00
|
|
|
|
|
|
|
vim.g.lsp_on_attach = function(client,bufnr)
|
2023-03-12 16:09:11 -04:00
|
|
|
print("Attaching to:",client.name)
|
|
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr,...) end
|
|
|
|
local opts = {noremap = true,silent=true}
|
|
|
|
|
|
|
|
if client.server_capabilities.documentSymbolProvider then
|
|
|
|
navic.attach(client, bufnr)
|
|
|
|
end
|
|
|
|
|
|
|
|
buf_set_keymap('n','gd','<cmd>lua vim.lsp.buf.definition()<CR>',opts)
|
|
|
|
buf_set_keymap('n','K', '<cmd>lua vim.lsp.buf.hover()<CR>',opts)
|
|
|
|
buf_set_keymap('n','[d','<cmd>lua vim.diagnostic.goto_prev()<CR>',opts)
|
|
|
|
buf_set_keymap('n',']d','<cmd>lua vim.diagnostic.goto_next()<CR>',opts)
|
|
|
|
buf_set_keymap('n','<leader>d','<cmd>lua vim.diagnostic.open_float({border="rounded"})<CR>',opts)
|
2023-05-03 05:06:15 -04:00
|
|
|
buf_set_keymap('n','<space>f','<cmd>lua vim.lsp.buf.formatting()<CR>',opts)
|
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})
|
|
|
|
-- vim.notify("Missing server configuration for " .. server, "error")
|
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
|