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
|
|
|
|
|
2023-01-09 06:40:32 +00:00
|
|
|
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
|
|
|
|
})
|
2023-01-09 06:40:32 +00:00
|
|
|
end
|
|
|
|
|
2024-01-09 08:11:19 +00:00
|
|
|
require("lsp-inlayhints").on_attach(client, bufnr)
|
|
|
|
|
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("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)
|
2023-01-09 06:40:32 +00:00
|
|
|
nnoremap("<leader>f", format_buffer)
|
2022-06-22 19:50:50 +00:00
|
|
|
nnoremap("<leader>d", telescope.diagnostics)
|
2022-07-25 06:48:28 +00:00
|
|
|
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,
|
2023-01-09 06:40:32 +00:00
|
|
|
callback = format_buffer,
|
2022-06-22 19:50:50 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-09 08:11:19 +00:00
|
|
|
require("lsp-inlayhints").setup({})
|
|
|
|
|
2022-06-22 19:50:50 +00:00
|
|
|
local lsp_status = require("lsp-status")
|
|
|
|
lsp_status.config({
|
|
|
|
current_function = false,
|
|
|
|
show_filename = false,
|
|
|
|
diagnostics = true,
|
2023-09-29 07:22:30 +00:00
|
|
|
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({
|
2023-04-11 05:39:46 +00:00
|
|
|
override = function(root_dir, options)
|
2022-12-07 14:11:38 +00:00
|
|
|
if require("neodev.util").has_file(root_dir, "/etc/nixos") then
|
2023-04-11 05:39:46 +00:00
|
|
|
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 = {
|
2022-06-22 20:09:56 +00:00
|
|
|
["bashls"] = {},
|
2023-10-12 06:33:48 +00:00
|
|
|
["clangd"] = {},
|
|
|
|
["cmake"] = {},
|
2022-07-21 06:24:53 +00:00
|
|
|
["dockerls"] = {},
|
2023-10-16 18:43:08 +00:00
|
|
|
["eslint"] = {},
|
2023-10-16 18:54:16 +00:00
|
|
|
["html"] = {},
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-10-16 18:28:18 +00:00
|
|
|
["marksman"] = {},
|
2023-12-11 19:04:42 +00:00
|
|
|
["nushell"] = {},
|
2022-11-30 14:46:29 +00:00
|
|
|
["pylsp"] = {
|
|
|
|
pylsp = {
|
|
|
|
plugins = {
|
|
|
|
pycodestyle = {
|
|
|
|
maxLineLength = 120
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
["pyright"] = {},
|
2022-06-22 19:50:50 +00:00
|
|
|
["rnix"] = {},
|
2022-06-22 20:09:56 +00:00
|
|
|
["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
|
|
|
|
2024-01-09 08:11:19 +00:00
|
|
|
-- setup rustaceanvim
|
|
|
|
vim.g.rustaceanvim = {
|
2022-06-24 10:41:32 +00:00
|
|
|
server = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
cargo = {
|
|
|
|
loadOutDirsFromCheck = true,
|
|
|
|
},
|
|
|
|
checkOnSave = { command = "clippy" },
|
|
|
|
procMacro = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 08:11:19 +00:00
|
|
|
}
|
2022-06-24 11:08:02 +00:00
|
|
|
|
2022-07-21 12:02:12 +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.diagnostics.tsc,
|
2022-07-21 12:02:12 +00:00
|
|
|
},
|
|
|
|
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,
|
2023-01-30 09:42:22 +00:00
|
|
|
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
|
|
|
})
|
2022-08-04 05:47:58 +00:00
|
|
|
|
2023-01-30 09:42:22 +00:00
|
|
|
-- setup diagnostics signs
|
2023-07-28 07:04:45 +00:00
|
|
|
local diagnostics_signs = { Error = "", Warn = "", Hint = "", Info = "" }
|
2023-01-30 09:42:22 +00:00
|
|
|
for type, icon in pairs(diagnostics_signs) do
|
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
|
|
end
|
|
|
|
|
2023-01-09 06:41:29 +00:00
|
|
|
-- setup volar
|
|
|
|
lspconfig["volar"].setup({
|
|
|
|
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|