mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-27 03:47:37 +00:00
languages/go: refactor lsp.servers to use lsp/presets/<name>
This commit is contained in:
parent
40ca9f3f7d
commit
7fc044d091
1 changed files with 10 additions and 49 deletions
|
|
@ -9,8 +9,9 @@
|
||||||
inherit (lib.options) mkEnableOption mkOption literalMD literalExpression;
|
inherit (lib.options) mkEnableOption mkOption literalMD literalExpression;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.meta) getExe;
|
||||||
|
inherit (lib) genAttrs;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.types) bool enum package str;
|
inherit (lib.types) enum package str listOf;
|
||||||
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf mkPluginSetupOption;
|
inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf mkPluginSetupOption;
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
inherit (lib.nvim.dag) entryAfter;
|
||||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||||
|
|
@ -18,47 +19,7 @@
|
||||||
cfg = config.vim.languages.go;
|
cfg = config.vim.languages.go;
|
||||||
|
|
||||||
defaultServers = ["gopls"];
|
defaultServers = ["gopls"];
|
||||||
servers = {
|
servers = ["gopls"];
|
||||||
gopls = {
|
|
||||||
cmd = [(getExe pkgs.gopls)];
|
|
||||||
filetypes = ["go" "gomod" "gosum" "gowork" "gotmpl"];
|
|
||||||
root_dir = mkLuaInline ''
|
|
||||||
function(bufnr, on_dir)
|
|
||||||
local fname = vim.api.nvim_buf_get_name(bufnr)
|
|
||||||
|
|
||||||
local function get_root(fname)
|
|
||||||
if _G.nvf_gopls_mod_cache and fname:sub(1, #_G.nvf_gopls_mod_cache) == _G.nvf_gopls_mod_cache then
|
|
||||||
local clients = vim.lsp.get_clients { name = 'gopls' }
|
|
||||||
if #clients > 0 then
|
|
||||||
return clients[#clients].config.root_dir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return vim.fs.root(fname, 'go.work') or vim.fs.root(fname, 'go.mod') or vim.fs.root(fname, '.git')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- see: https://github.com/neovim/nvim-lspconfig/issues/804
|
|
||||||
if _G.nvf_gopls_mod_cache then
|
|
||||||
on_dir(get_root(fname))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local cmd = { 'go', 'env', 'GOMODCACHE' }
|
|
||||||
local ok, err = pcall(vim.system, cmd, { text = true }, function(output)
|
|
||||||
if output.code == 0 then
|
|
||||||
if output.stdout then
|
|
||||||
_G.nvf_gopls_mod_cache = vim.trim(output.stdout)
|
|
||||||
end
|
|
||||||
on_dir(get_root(fname))
|
|
||||||
else
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.notify(('[gopls] cmd failed with code %d: %s\n%s'):format(output.code, cmd, output.stderr))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
if not ok then vim.notify(('[gopls] cmd failed: %s\n%s'):format(cmd, err)) end
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
defaultFormat = ["gofmt"];
|
defaultFormat = ["gofmt"];
|
||||||
formats = {
|
formats = {
|
||||||
|
|
@ -194,7 +155,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
servers = mkOption {
|
servers = mkOption {
|
||||||
type = deprecatedSingleOrListOf "vim.language.go.lsp.servers" (enum (attrNames servers));
|
type = listOf (enum servers);
|
||||||
default = defaultServers;
|
default = defaultServers;
|
||||||
description = "Go LSP server to use";
|
description = "Go LSP server to use";
|
||||||
};
|
};
|
||||||
|
|
@ -319,12 +280,12 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp.servers =
|
vim.lsp = {
|
||||||
mapListToAttrs (name: {
|
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
||||||
inherit name;
|
servers = genAttrs cfg.lsp.servers (_: {
|
||||||
value = servers.${name};
|
filetypes = ["go" "gomod" "gosum" "gowork" "gotmpl"];
|
||||||
})
|
});
|
||||||
cfg.lsp.servers;
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.format.enable {
|
(mkIf cfg.format.enable {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue