2021-08-04 22:21:44 +02:00
|
|
|
local pid = vim.fn.getpid()
|
|
|
|
|
2022-08-25 22:25:58 +02:00
|
|
|
require("nvim-lightbulb").setup({
|
|
|
|
autocmd = {
|
|
|
|
enabled = true,
|
|
|
|
}
|
2022-05-03 21:48:38 +02:00
|
|
|
})
|
2021-08-04 22:21:44 +02:00
|
|
|
|
2022-10-04 14:44:30 +02:00
|
|
|
LspFormat = function(bufnr)
|
|
|
|
vim.lsp.buf.format({
|
|
|
|
filter = function(client)
|
2023-05-31 17:25:46 +02:00
|
|
|
return not vim.tbl_contains({ "tsserver", "jsonls" }, client.name)
|
2022-10-04 14:44:30 +02:00
|
|
|
end,
|
|
|
|
bufnr,
|
|
|
|
timeout_ms = 5000,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2022-08-29 13:14:18 +02:00
|
|
|
local format_augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
2022-05-03 21:48:38 +02:00
|
|
|
local on_attach = function(client, bufnr)
|
2021-08-04 22:21:44 +02:00
|
|
|
-- codelens
|
2022-10-04 10:59:05 +02:00
|
|
|
if client.server_capabilities.codeLensProvider then
|
2022-08-29 13:14:18 +02:00
|
|
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI", "InsertLeave" }, {
|
2022-05-03 21:48:38 +02:00
|
|
|
callback = vim.lsp.codelens.refresh,
|
|
|
|
buffer = bufnr,
|
|
|
|
})
|
|
|
|
end
|
2022-08-29 13:14:18 +02:00
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
|
|
vim.api.nvim_clear_autocmds({ group = format_augroup, buffer = bufnr })
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
|
|
group = format_augroup,
|
|
|
|
buffer = bufnr,
|
|
|
|
callback = function()
|
2022-10-04 14:44:30 +02:00
|
|
|
LspFormat(bufnr)
|
2022-08-29 13:14:18 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2023-06-26 18:03:50 +02:00
|
|
|
|
|
|
|
-- workaround for https://github.com/OmniSharp/omnisharp-roslyn/issues/2483
|
|
|
|
if client.name == "omnisharp" then
|
|
|
|
local tokenModifiers = client.server_capabilities.semanticTokensProvider.legend.tokenModifiers
|
|
|
|
for i, v in ipairs(tokenModifiers) do
|
|
|
|
tokenModifiers[i] = string.gsub(v, "%s*[- ]%s*", "_")
|
|
|
|
end
|
|
|
|
local tokenTypes = client.server_capabilities.semanticTokensProvider.legend.tokenTypes
|
|
|
|
for i, v in ipairs(tokenTypes) do
|
|
|
|
tokenTypes[i] = string.gsub(v, "%s*[- ]%s*", "_")
|
|
|
|
end
|
|
|
|
end
|
2020-09-26 23:54:07 +02:00
|
|
|
end
|
|
|
|
|
2022-05-05 17:56:17 +02:00
|
|
|
local config = require("lspconfig")
|
|
|
|
local configs = require("lspconfig.configs")
|
|
|
|
|
2023-02-01 20:19:37 +01:00
|
|
|
function table.merge(t1, t2)
|
|
|
|
local t = {}
|
|
|
|
for k, v in ipairs(t1) do table.insert(t, v) end
|
|
|
|
for k, v in ipairs(t2) do table.insert(t, v) end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
|
|
|
-- first search git root for global config (monorepo)
|
|
|
|
-- and fall back to normal search order otherwise
|
|
|
|
local monorepo_pattern = function(main_patterns, other_patterns, f)
|
|
|
|
local all_patterns = table.merge(main_patterns, other_patterns)
|
|
|
|
local git_root = config.util.root_pattern(".git")(f)
|
|
|
|
local git_root_sln = config.util.root_pattern(unpack(main_patterns))(git_root)
|
|
|
|
return git_root_sln or config.util.root_pattern(unpack(all_patterns))(f)
|
|
|
|
end
|
|
|
|
|
2022-10-25 10:49:29 +02:00
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
2022-10-04 14:44:30 +02:00
|
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
2022-08-29 14:06:49 +02:00
|
|
|
|
2022-10-04 14:44:30 +02:00
|
|
|
local default_config = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
2022-08-29 14:06:49 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 14:44:30 +02:00
|
|
|
config.jsonls.setup(default_config)
|
|
|
|
config.yamlls.setup(default_config)
|
|
|
|
config.html.setup(default_config)
|
|
|
|
config.cssls.setup(default_config)
|
|
|
|
config.dockerls.setup(default_config)
|
2023-03-16 16:31:02 +01:00
|
|
|
config.nil_ls.setup(default_config)
|
2023-05-31 17:31:38 +02:00
|
|
|
config.nickel_ls.setup(default_config)
|
2022-10-04 14:44:30 +02:00
|
|
|
config.tsserver.setup(default_config)
|
|
|
|
config.graphql.setup(default_config)
|
|
|
|
config.pylsp.setup(default_config)
|
|
|
|
config.terraformls.setup(default_config)
|
|
|
|
config.hls.setup(default_config)
|
|
|
|
config.bufls.setup(default_config)
|
|
|
|
config.vimls.setup(default_config)
|
2020-11-28 16:21:07 +01:00
|
|
|
|
2023-04-09 21:36:47 +02:00
|
|
|
config.bashls.setup {
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
|
|
|
-- disable bashls for .env files
|
|
|
|
if client.name == "bashls"
|
|
|
|
and bufname:match "%.env" ~= nil
|
|
|
|
and bufname:match "%.env.*" ~= nil
|
|
|
|
then
|
|
|
|
vim.lsp.stop_client(client.id)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return on_attach()
|
|
|
|
end,
|
|
|
|
capabilities = capabilities,
|
|
|
|
}
|
|
|
|
|
2022-08-29 13:14:18 +02:00
|
|
|
config.rust_analyzer.setup {
|
2022-07-30 08:42:20 +02:00
|
|
|
on_attach = on_attach,
|
2022-06-27 01:03:17 +02:00
|
|
|
capabilities = capabilities,
|
2023-02-01 20:19:37 +01:00
|
|
|
root_dir = function(f)
|
|
|
|
return monorepo_pattern({ "Cargo.toml", "rust-project.json" }, { ".git" }, f)
|
|
|
|
end,
|
2022-07-26 13:05:52 +02:00
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
2023-02-01 20:19:37 +01:00
|
|
|
cargo = { buildScripts = { enable = true } },
|
2022-07-26 13:05:52 +02:00
|
|
|
checkOnSave = { command = "clippy" },
|
2023-02-01 20:19:37 +01:00
|
|
|
procMacro = { enable = true },
|
2022-07-26 13:05:52 +02:00
|
|
|
},
|
|
|
|
},
|
2022-06-27 01:03:17 +02:00
|
|
|
}
|
|
|
|
|
2022-08-29 13:14:18 +02:00
|
|
|
config.omnisharp.setup {
|
2022-07-30 08:42:20 +02:00
|
|
|
on_attach = on_attach,
|
2021-08-04 22:21:44 +02:00
|
|
|
capabilities = capabilities,
|
2023-01-25 21:39:12 +01:00
|
|
|
root_dir = function(f)
|
2023-02-01 20:19:37 +01:00
|
|
|
return monorepo_pattern({ "*.sln" }, { "*.csproj" }, f)
|
2023-01-25 21:39:12 +01:00
|
|
|
end,
|
2022-08-29 13:14:18 +02:00
|
|
|
cmd = { "OmniSharp", "--languageserver", "--hostPID", tostring(pid) },
|
2020-09-26 23:54:07 +02:00
|
|
|
}
|
|
|
|
|
2022-03-10 15:04:02 +01:00
|
|
|
local runtime_path = vim.split(package.path, ';')
|
|
|
|
table.insert(runtime_path, "lua/?.lua")
|
|
|
|
table.insert(runtime_path, "lua/?/init.lua")
|
|
|
|
|
2023-05-31 17:25:46 +02:00
|
|
|
config.lua_ls.setup {
|
2022-07-30 08:42:20 +02:00
|
|
|
on_attach = on_attach,
|
2022-03-10 15:04:02 +01:00
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
path = runtime_path,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
2022-08-29 13:14:18 +02:00
|
|
|
globals = { "vim" },
|
2022-03-10 15:04:02 +01:00
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-29 13:14:18 +02:00
|
|
|
local null_ls = require("null-ls")
|
|
|
|
local null_ls_custom = {
|
|
|
|
diagnostics = {},
|
|
|
|
formatting = {
|
|
|
|
nix_fmt = {
|
|
|
|
name = "nix fmt",
|
|
|
|
meta = {
|
|
|
|
url = "https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-fmt.html",
|
|
|
|
description = "reformat your code in the standard style",
|
2021-05-05 00:05:37 +02:00
|
|
|
},
|
2022-08-29 13:14:18 +02:00
|
|
|
method = null_ls.methods.FORMATTING,
|
|
|
|
filetypes = { "nix" },
|
|
|
|
generator = require("null-ls.helpers").formatter_factory({
|
2022-05-12 11:57:43 +02:00
|
|
|
command = "nix",
|
2022-08-29 14:06:49 +02:00
|
|
|
args = { "fmt", "$FILENAME" },
|
|
|
|
to_stdin = false,
|
|
|
|
to_temp_file = true,
|
2022-08-29 13:14:18 +02:00
|
|
|
}),
|
2021-05-05 00:05:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-08-04 22:21:44 +02:00
|
|
|
|
2022-08-29 13:14:18 +02:00
|
|
|
null_ls.setup({
|
|
|
|
sources = {
|
|
|
|
null_ls.builtins.diagnostics.statix, -- nix linter
|
2022-10-04 11:08:38 +02:00
|
|
|
null_ls.builtins.diagnostics.buf,
|
2022-08-29 13:14:18 +02:00
|
|
|
null_ls.builtins.diagnostics.eslint_d,
|
|
|
|
null_ls.builtins.diagnostics.stylelint,
|
2023-05-31 17:31:38 +02:00
|
|
|
null_ls.builtins.formatting.topiary.with {
|
|
|
|
filetypes = { "ncl", "nickel" },
|
|
|
|
},
|
2022-08-29 13:14:18 +02:00
|
|
|
null_ls.builtins.formatting.shfmt,
|
2022-10-04 14:44:30 +02:00
|
|
|
null_ls.builtins.formatting.eslint,
|
|
|
|
-- TODO prettier_d_slim isn't working
|
|
|
|
null_ls.builtins.formatting.prettier.with {
|
|
|
|
disabled_filetypes = {
|
|
|
|
"javascript",
|
|
|
|
"javascriptreact",
|
|
|
|
"typescript",
|
|
|
|
"typescriptreact",
|
2022-08-29 13:14:18 +02:00
|
|
|
},
|
|
|
|
},
|
2022-10-04 14:44:30 +02:00
|
|
|
null_ls.builtins.formatting.stylelint,
|
2022-08-29 14:06:49 +02:00
|
|
|
null_ls_custom.formatting.nix_fmt,
|
2022-10-04 11:08:38 +02:00
|
|
|
null_ls.builtins.formatting.buf,
|
2022-08-29 13:14:18 +02:00
|
|
|
null_ls.builtins.formatting.rustfmt,
|
|
|
|
null_ls.builtins.formatting.terraform_fmt,
|
|
|
|
},
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
|
|
|
|
2022-03-30 11:30:29 +02:00
|
|
|
require("nvim-autopairs").setup({
|
2021-08-04 22:21:44 +02:00
|
|
|
check_ts = true,
|
|
|
|
})
|