2023-04-17 22:27:27 +02:00
|
|
|
{
|
|
|
|
config,
|
2024-03-09 06:49:22 +01:00
|
|
|
pkgs,
|
2023-04-17 22:27:27 +02:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-08 03:16:46 +01:00
|
|
|
}: let
|
2023-11-14 08:18:32 +01:00
|
|
|
inherit (builtins) attrNames;
|
2024-03-09 06:49:22 +01:00
|
|
|
inherit (lib.options) mkEnableOption mkOption;
|
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.meta) getExe;
|
|
|
|
inherit (lib.lists) isList;
|
|
|
|
inherit (lib.types) bool enum either listOf package str;
|
|
|
|
inherit (lib.nvim.types) mkGrammarOption;
|
|
|
|
inherit (lib.nvim.lua) expToLua;
|
2024-07-03 20:42:26 +02:00
|
|
|
inherit (lib.nvim.dag) entryAfter;
|
2023-11-08 03:16:46 +01:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
cfg = config.vim.languages.go;
|
|
|
|
|
|
|
|
defaultServer = "gopls";
|
|
|
|
servers = {
|
|
|
|
gopls = {
|
|
|
|
package = pkgs.gopls;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.gopls.setup {
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = default_on_attach;
|
2023-09-14 23:40:04 +02:00
|
|
|
cmd = ${
|
|
|
|
if isList cfg.lsp.package
|
2024-03-09 06:49:22 +01:00
|
|
|
then expToLua cfg.lsp.package
|
2023-09-14 23:40:04 +02:00
|
|
|
else ''{"${cfg.lsp.package}/bin/gopls", "serve"}''
|
|
|
|
},
|
2023-04-17 22:27:27 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-03-09 06:49:22 +01:00
|
|
|
|
2023-05-08 13:03:26 +02:00
|
|
|
defaultDebugger = "delve";
|
|
|
|
debuggers = {
|
|
|
|
delve = {
|
|
|
|
package = pkgs.delve;
|
|
|
|
};
|
|
|
|
};
|
2023-04-17 22:27:27 +02:00
|
|
|
in {
|
|
|
|
options.vim.languages.go = {
|
|
|
|
enable = mkEnableOption "Go language support";
|
|
|
|
|
|
|
|
treesitter = {
|
2023-10-21 19:15:36 +02:00
|
|
|
enable = mkEnableOption "Go treesitter" // {default = config.vim.languages.enableTreesitter;};
|
2023-06-05 22:10:25 +02:00
|
|
|
|
2024-03-09 06:49:22 +01:00
|
|
|
package = mkGrammarOption pkgs "go";
|
2023-04-17 22:27:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
lsp = {
|
2023-10-21 19:15:36 +02:00
|
|
|
enable = mkEnableOption "Go LSP support" // {default = config.vim.languages.enableLSP;};
|
2023-06-05 22:10:25 +02:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
server = mkOption {
|
|
|
|
description = "Go LSP server to use";
|
2024-03-09 06:49:22 +01:00
|
|
|
type = enum (attrNames servers);
|
2023-04-17 22:27:27 +02:00
|
|
|
default = defaultServer;
|
|
|
|
};
|
2023-06-05 22:10:25 +02:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
package = mkOption {
|
2023-09-23 00:28:39 +02:00
|
|
|
description = "Go LSP server package, or the command to run as a list of strings";
|
|
|
|
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
|
2024-03-09 06:49:22 +01:00
|
|
|
type = either package (listOf str);
|
2023-04-17 22:27:27 +02:00
|
|
|
default = servers.${cfg.lsp.server}.package;
|
|
|
|
};
|
|
|
|
};
|
2023-05-08 13:03:26 +02:00
|
|
|
|
|
|
|
dap = {
|
|
|
|
enable = mkOption {
|
2024-07-03 20:42:26 +02:00
|
|
|
description = "Enable Go Debug Adapter via nvim-dap-go plugin";
|
2024-03-09 06:49:22 +01:00
|
|
|
type = bool;
|
2023-05-08 13:03:26 +02:00
|
|
|
default = config.vim.languages.enableDAP;
|
|
|
|
};
|
2024-07-03 20:42:26 +02:00
|
|
|
|
2023-05-08 13:03:26 +02:00
|
|
|
debugger = mkOption {
|
|
|
|
description = "Go debugger to use";
|
2024-03-09 06:49:22 +01:00
|
|
|
type = enum (attrNames debuggers);
|
2023-05-08 13:03:26 +02:00
|
|
|
default = defaultDebugger;
|
|
|
|
};
|
2024-07-03 20:42:26 +02:00
|
|
|
|
2023-05-08 13:03:26 +02:00
|
|
|
package = mkOption {
|
|
|
|
description = "Go debugger package.";
|
2024-03-09 06:49:22 +01:00
|
|
|
type = package;
|
2023-05-08 13:03:26 +02:00
|
|
|
default = debuggers.${cfg.dap.debugger}.package;
|
|
|
|
};
|
|
|
|
};
|
2023-04-17 22:27:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
})
|
2023-05-08 13:03:26 +02:00
|
|
|
|
|
|
|
(mkIf cfg.dap.enable {
|
2024-07-03 20:42:26 +02:00
|
|
|
vim = {
|
|
|
|
startPlugins = ["nvim-dap-go"];
|
|
|
|
luaConfigRC.nvim-dap-go = entryAfter ["nvim-dap"] ''
|
|
|
|
require('dap-go').setup {
|
|
|
|
delve = {
|
|
|
|
path = '${getExe cfg.dap.package}',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
debugger.nvim-dap.enable = true;
|
|
|
|
};
|
2023-05-08 13:03:26 +02:00
|
|
|
})
|
2023-04-17 22:27:27 +02:00
|
|
|
]);
|
|
|
|
}
|