nixos-config/home-manager/neovim/lspconfig.lua

196 lines
5.3 KiB
Lua
Raw Normal View History

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 function format_buffer()
2023-04-11 05:40:22 +00:00
vim.lsp.buf.format({
timeout_ms = 3000,
async = false,
filter = function(formatter)
return formatter.name ~= "tsserver" and formatter.name ~= "volar"
end
})
end
2022-06-22 19:50:50 +00:00
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", format_buffer)
2022-06-22 19:50:50 +00:00
nnoremap("<leader>d", telescope.diagnostics)
nnoremap("<leader>D", require("lsp_lines").toggle)
2022-06-22 19:50:50 +00:00
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 = format_buffer,
2022-06-22 19:50:50 +00:00
})
end
local illuminate = require("illuminate")
illuminate.on_attach(client)
2022-06-22 19:50:50 +00:00
end
local lsp_status = require("lsp-status")
lsp_status.config({
current_function = false,
show_filename = false,
diagnostics = true,
status_symbol = "",
2022-06-22 19:50:50 +00:00
})
lsp_status.register_progress()
2022-12-07 14:11:38 +00:00
-- setup lua language server for init.nvim and nvim plugin development
require("neodev").setup({
override = function(root_dir, options)
2022-12-07 14:11:38 +00:00
if require("neodev.util").has_file(root_dir, "/etc/nixos") then
options.enabled = true
options.plugins = true
2022-12-07 14:11:38 +00:00
end
end,
})
local capabilities = require("cmp_nvim_lsp").default_capabilities(lsp_status.capabilities)
2022-06-22 19:50:50 +00:00
local servers = {
["bashls"] = {},
["dockerls"] = {},
2023-04-11 05:40:10 +00:00
["jsonls"] = {},
2023-05-11 14:35:40 +00:00
["lua_ls"] = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
},
2022-11-30 14:46:29 +00:00
["pylsp"] = {
pylsp = {
plugins = {
pycodestyle = {
maxLineLength = 120
}
}
}
},
["pyright"] = {},
2022-06-22 19:50:50 +00:00
["rnix"] = {},
["terraformls"] = {},
["tflint"] = {},
2022-07-27 14:23:11 +00:00
["tsserver"] = {},
2023-03-15 13:34:37 +00:00
["yamlls"] = {
yaml = {
keyOrdering = false
}
},
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
2022-08-23 09:46:14 +00:00
-- 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'
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-08-23 09:46:14 +00:00
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_bin_path, codelldb_lib_path)
},
2022-06-24 10:41:32 +00:00
})
-- setup null-ls for markdown formatting
local null_ls = require("null-ls")
null_ls.setup({
sources = {
2022-07-27 14:23:11 +00:00
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,
})
2022-07-25 06:48:10 +00:00
-- setup lsp_lines
2022-08-22 05:56:40 +00:00
require("lsp_lines").setup()
-- setup vim diagnostics
2022-07-25 06:48:10 +00:00
vim.diagnostic.config({
virtual_text = false,
2022-08-22 05:56:40 +00:00
signs = true,
update_in_insert = true,
underline = true,
severity_sort = true,
2022-08-22 05:56:40 +00:00
float = {
border = "rounded",
source = "always",
header = "",
prefix = "",
},
2022-07-25 06:48:10 +00:00
})
-- setup diagnostics signs
local diagnostics_signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(diagnostics_signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
-- setup html languageserver
lspconfig["html"].setup({
cmd = { "html-languageserver", "--stdio" },
on_attach = on_attach,
capabilities = capabilities,
})
2023-01-09 06:41:29 +00:00
-- setup volar
lspconfig["volar"].setup({
cmd = { "./node_modules/.bin/vue-language-server", "--stdio" },
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
on_attach = on_attach,
capabilities = capabilities,
})