158 lines
4.3 KiB
Lua
158 lines
4.3 KiB
Lua
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local function nnoremap(key, command)
|
|
vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr })
|
|
end
|
|
|
|
local telescope = require("telescope.builtin")
|
|
|
|
nnoremap("gD", vim.lsp.buf.declaration)
|
|
nnoremap("gd", telescope.lsp_definitions)
|
|
nnoremap("gt", telescope.lsp_type_definitions)
|
|
nnoremap("gi", telescope.lsp_implementations)
|
|
nnoremap("gr", telescope.lsp_references)
|
|
nnoremap("K", vim.lsp.buf.hover)
|
|
nnoremap("<leader>rn", vim.lsp.buf.rename)
|
|
nnoremap("<leader>ca", vim.lsp.buf.code_action)
|
|
nnoremap("<leader>f", vim.lsp.buf.formatting)
|
|
nnoremap("<leader>d", telescope.diagnostics)
|
|
nnoremap("<leader>D", require("lsp_lines").toggle)
|
|
nnoremap("<C-p>", vim.diagnostic.goto_prev)
|
|
nnoremap("<C-n>", vim.diagnostic.goto_next)
|
|
|
|
-- disable tsserver formatting
|
|
if client.name == "tsserver" then
|
|
client.resolved_capabilities["document_formatting"] = false
|
|
end
|
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
group = augroup,
|
|
buffer = bufnr,
|
|
callback = function()
|
|
vim.lsp.buf.formatting_sync(nil, 3000)
|
|
end,
|
|
})
|
|
end
|
|
|
|
local illuminate = require("illuminate")
|
|
illuminate.on_attach(client)
|
|
end
|
|
|
|
local lsp_status = require("lsp-status")
|
|
lsp_status.config({
|
|
current_function = false,
|
|
show_filename = false,
|
|
diagnostics = true,
|
|
})
|
|
lsp_status.register_progress()
|
|
|
|
local capabilities = vim.tbl_extend("keep", vim.lsp.protocol.make_client_capabilities(), lsp_status.capabilities)
|
|
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
|
|
|
|
local servers = {
|
|
["bashls"] = {},
|
|
["dockerls"] = {},
|
|
["pylsp"] = {
|
|
pylsp = {
|
|
plugins = {
|
|
pycodestyle = {
|
|
maxLineLength = 120
|
|
}
|
|
}
|
|
}
|
|
},
|
|
["pyright"] = {},
|
|
["rnix"] = {},
|
|
["terraformls"] = {},
|
|
["tflint"] = {},
|
|
["tsserver"] = {},
|
|
["yamlls"] = {},
|
|
}
|
|
|
|
local lspconfig = require("lspconfig")
|
|
|
|
for lsp, settings in pairs(servers) do
|
|
lspconfig[lsp].setup({
|
|
settings = settings,
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
end
|
|
|
|
-- setup rust tools
|
|
local codelldb_base_path = vim.env.HOME .. "/.vscode-extensions/vscode-lldb/share/vscode/extensions/vadimcn.vscode-lldb/"
|
|
local codelldb_bin_path = codelldb_base_path .. 'adapter/codelldb'
|
|
local codelldb_lib_path = codelldb_base_path .. 'lldb/lib/liblldb.so'
|
|
|
|
require("rust-tools").setup({
|
|
server = {
|
|
on_attach = on_attach,
|
|
settings = {
|
|
["rust-analyzer"] = {
|
|
cargo = {
|
|
loadOutDirsFromCheck = true,
|
|
},
|
|
checkOnSave = { command = "clippy" },
|
|
procMacro = {
|
|
enable = true,
|
|
},
|
|
},
|
|
},
|
|
capabilities = capabilities,
|
|
},
|
|
dap = {
|
|
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_bin_path, codelldb_lib_path)
|
|
},
|
|
})
|
|
|
|
local luadev = require("lua-dev").setup({
|
|
lspconfig = {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
},
|
|
runtime_path = true,
|
|
})
|
|
|
|
lspconfig["sumneko_lua"].setup(luadev)
|
|
|
|
-- setup null-ls for markdown formatting
|
|
local null_ls = require("null-ls")
|
|
null_ls.setup({
|
|
sources = {
|
|
null_ls.builtins.formatting.prettier,
|
|
null_ls.builtins.code_actions.eslint_d,
|
|
null_ls.builtins.diagnostics.eslint_d,
|
|
null_ls.builtins.diagnostics.tsc,
|
|
},
|
|
|
|
on_attach = on_attach,
|
|
})
|
|
|
|
-- setup lsp_lines
|
|
require("lsp_lines").setup()
|
|
|
|
-- setup vim diagnostics
|
|
vim.diagnostic.config({
|
|
virtual_text = false,
|
|
signs = true,
|
|
update_in_insert = true,
|
|
underline = true,
|
|
severity_sort = false,
|
|
float = {
|
|
border = "rounded",
|
|
source = "always",
|
|
header = "",
|
|
prefix = "",
|
|
},
|
|
})
|
|
|
|
-- setup html languageserver
|
|
lspconfig["html"].setup({
|
|
cmd = { "html-languageserver", "--stdio" },
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|