2022-06-22 19:50:50 +00:00
|
|
|
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("<C-k>", vim.lsp.buf.signature_help)
|
|
|
|
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("<C-p>", vim.diagnostic.goto_prev)
|
|
|
|
nnoremap("<C-n>", vim.diagnostic.goto_next)
|
|
|
|
|
|
|
|
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()
|
2022-06-24 10:41:32 +00:00
|
|
|
vim.lsp.buf.formatting_sync({}, 3000)
|
2022-06-22 19:50:50 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
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 = {
|
2022-06-22 20:09:56 +00:00
|
|
|
["bashls"] = {},
|
2022-06-22 19:50:50 +00:00
|
|
|
["rnix"] = {},
|
2022-06-22 20:09:56 +00:00
|
|
|
["terraformls"] = {},
|
|
|
|
["tflint"] = {},
|
2022-06-26 19:12:32 +00:00
|
|
|
["yamlls"] = {},
|
2022-06-22 19:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local lspconfig = require("lspconfig")
|
|
|
|
|
2022-06-24 10:41:32 +00:00
|
|
|
for lsp, settings in pairs(servers) do
|
2022-06-22 19:50:50 +00:00
|
|
|
lspconfig[lsp].setup({
|
2022-06-24 10:41:32 +00:00
|
|
|
settings = settings,
|
2022-06-22 19:50:50 +00:00
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|
|
|
|
end
|
2022-06-24 10:41:32 +00:00
|
|
|
|
|
|
|
require("rust-tools").setup({
|
|
|
|
server = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
cargo = {
|
|
|
|
loadOutDirsFromCheck = true,
|
|
|
|
},
|
|
|
|
checkOnSave = { command = "clippy" },
|
|
|
|
procMacro = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
capabilities = capabilities,
|
|
|
|
},
|
|
|
|
})
|
2022-06-24 11:08:02 +00:00
|
|
|
|
|
|
|
local luadev = require("lua-dev").setup({
|
|
|
|
lspconfig = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
},
|
|
|
|
runtime_path = true,
|
|
|
|
})
|
|
|
|
|
|
|
|
lspconfig["sumneko_lua"].setup(luadev)
|