2024-07-10 06:10:56 +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()
|
|
|
|
vim.lsp.buf.format({
|
|
|
|
timeout_ms = 3000,
|
|
|
|
async = false,
|
|
|
|
filter = function(formatter)
|
|
|
|
return formatter.name ~= "tsserver" and formatter.name ~= "volar"
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
require("lsp-inlayhints").on_attach(client, bufnr)
|
|
|
|
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
nnoremap("<M-o>", ":ClangdSwitchSourceHeader<CR>")
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require("lsp-inlayhints").setup({})
|
|
|
|
|
|
|
|
local lsp_status = require("lsp-status")
|
|
|
|
lsp_status.config({
|
|
|
|
current_function = false,
|
|
|
|
show_filename = false,
|
|
|
|
diagnostics = true,
|
|
|
|
status_symbol = "",
|
|
|
|
})
|
|
|
|
lsp_status.register_progress()
|
|
|
|
|
|
|
|
-- setup lua language server for init.nvim and nvim plugin development
|
|
|
|
require("neodev").setup({
|
|
|
|
override = function(root_dir, options)
|
|
|
|
if require("neodev.util").has_file(root_dir, "/etc/nixos") then
|
|
|
|
options.enabled = true
|
|
|
|
options.plugins = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities(lsp_status.capabilities)
|
|
|
|
|
|
|
|
local servers = {
|
|
|
|
["bashls"] = {},
|
|
|
|
["bitbake_language_server"] = {},
|
|
|
|
["clangd"] = {},
|
|
|
|
["cmake"] = {},
|
|
|
|
["dockerls"] = {},
|
|
|
|
["eslint"] = {},
|
|
|
|
["html"] = {},
|
|
|
|
["jsonls"] = {},
|
|
|
|
["lua_ls"] = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = { "vim" },
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
format = {
|
|
|
|
enable = true,
|
|
|
|
defaultConfig = {
|
|
|
|
indent_style = "space",
|
|
|
|
indent_size = "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
["marksman"] = {},
|
|
|
|
["nixd"] = {},
|
|
|
|
["pylsp"] = {
|
|
|
|
pylsp = {
|
|
|
|
plugins = {
|
|
|
|
autopep8 = {
|
|
|
|
enabled = true
|
|
|
|
},
|
|
|
|
flake8 = {
|
|
|
|
enabled = true
|
|
|
|
},
|
|
|
|
pycodestyle = {
|
|
|
|
maxLineLength = 120,
|
|
|
|
enabled = true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
["pyright"] = {},
|
|
|
|
["terraformls"] = {},
|
|
|
|
["texlab"] = {},
|
|
|
|
["tflint"] = {},
|
|
|
|
["tsserver"] = {},
|
|
|
|
["yamlls"] = {
|
|
|
|
yaml = {
|
|
|
|
keyOrdering = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local lspconfig = require("lspconfig")
|
|
|
|
|
|
|
|
for lsp, settings in pairs(servers) do
|
|
|
|
lspconfig[lsp].setup({
|
|
|
|
settings = settings,
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- setup rustaceanvim
|
|
|
|
vim.g.rustaceanvim = {
|
|
|
|
server = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
cargo = {
|
|
|
|
loadOutDirsFromCheck = true,
|
|
|
|
},
|
|
|
|
checkOnSave = { command = "clippy" },
|
|
|
|
procMacro = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
-- setup null-ls for markdown formatting
|
|
|
|
local null_ls = require("null-ls")
|
|
|
|
null_ls.setup({
|
|
|
|
sources = {
|
2024-07-27 20:22:59 +00:00
|
|
|
null_ls.builtins.formatting.prettierd.with({
|
|
|
|
extra_filetypes = { "vimwiki" },
|
|
|
|
}),
|
2024-07-10 06:10:56 +00:00
|
|
|
},
|
|
|
|
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 = true,
|
|
|
|
float = {
|
|
|
|
border = "rounded",
|
|
|
|
source = true,
|
|
|
|
header = "",
|
|
|
|
prefix = "",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
-- 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 volar
|
|
|
|
lspconfig["volar"].setup({
|
|
|
|
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|