feat(neovim): improve rust_analyzer config
This commit is contained in:
parent
86231db308
commit
1e229baafd
|
@ -40,6 +40,22 @@ end
|
||||||
local config = require("lspconfig")
|
local config = require("lspconfig")
|
||||||
local configs = require("lspconfig.configs")
|
local configs = require("lspconfig.configs")
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
if not configs.glslls then
|
if not configs.glslls then
|
||||||
configs.glslls = {
|
configs.glslls = {
|
||||||
default_config = {
|
default_config = {
|
||||||
|
@ -78,10 +94,14 @@ config.glslls.setup(default_config)
|
||||||
config.rust_analyzer.setup {
|
config.rust_analyzer.setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
root_dir = config.util.root_pattern("Cargo.toml", "rust-project.json", ".git"),
|
root_dir = function(f)
|
||||||
|
return monorepo_pattern({ "Cargo.toml", "rust-project.json" }, { ".git" }, f)
|
||||||
|
end,
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {
|
["rust-analyzer"] = {
|
||||||
|
cargo = { buildScripts = { enable = true } },
|
||||||
checkOnSave = { command = "clippy" },
|
checkOnSave = { command = "clippy" },
|
||||||
|
procMacro = { enable = true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -90,9 +110,7 @@ config.omnisharp.setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
root_dir = function(f)
|
root_dir = function(f)
|
||||||
local git_root = config.util.root_pattern(".git")(f)
|
return monorepo_pattern({ "*.sln" }, { "*.csproj" }, f)
|
||||||
local git_root_sln = config.util.root_pattern("*.sln")(git_root)
|
|
||||||
return git_root_sln or config.util.root_pattern("*.sln", "*.csproj")(f)
|
|
||||||
end,
|
end,
|
||||||
cmd = { "OmniSharp", "--languageserver", "--hostPID", tostring(pid) },
|
cmd = { "OmniSharp", "--languageserver", "--hostPID", tostring(pid) },
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue