2023-04-17 20:27:27 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
with builtins; let
|
|
|
|
cfg = config.vim.languages.go;
|
|
|
|
|
|
|
|
defaultServer = "gopls";
|
|
|
|
servers = {
|
|
|
|
gopls = {
|
|
|
|
package = pkgs.gopls;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.gopls.setup {
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = default_on_attach;
|
|
|
|
cmd = {"${cfg.lsp.package}/bin/gopls", "serve"},
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.vim.languages.go = {
|
|
|
|
enable = mkEnableOption "Go language support";
|
|
|
|
|
|
|
|
treesitter = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Go treesitter" // {default = config.vim.languages.enableTreesitter;};
|
|
|
|
|
2023-04-17 21:55:27 +00:00
|
|
|
package = nvim.types.mkGrammarOption pkgs "go";
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
lsp = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Go LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
server = mkOption {
|
|
|
|
description = "Go LSP server to use";
|
|
|
|
type = with types; enum (attrNames servers);
|
|
|
|
default = defaultServer;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "Go LSP server package";
|
|
|
|
type = types.package;
|
|
|
|
default = servers.${cfg.lsp.server}.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.package];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
|
|
|
vim.lsp.lspconfig.sources.go-lsp = servers.${cfg.lsp.server}.lspConfig;
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|