mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-12-22 09:49:49 +01:00
feat: add debugger for go
This commit is contained in:
parent
bdf77593ee
commit
b029426d34
1 changed files with 63 additions and 0 deletions
|
@ -21,6 +21,46 @@ with builtins; let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
defaultDebugger = "delve";
|
||||||
|
debuggers = {
|
||||||
|
delve = {
|
||||||
|
package = pkgs.delve;
|
||||||
|
dapConfig = ''
|
||||||
|
dap.adapters.delve = {
|
||||||
|
type = "server",
|
||||||
|
port = "''${port}",
|
||||||
|
executable = {
|
||||||
|
command = "${getExe cfg.dap.package}",
|
||||||
|
args = { "dap", "-l", "127.0.0.1:''${port}" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
dap.configurations.go = {
|
||||||
|
{
|
||||||
|
type = "delve",
|
||||||
|
name = "Debug",
|
||||||
|
request = "launch",
|
||||||
|
program = "''${file}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "delve",
|
||||||
|
name = "Debug test", -- configuration for debugging test files
|
||||||
|
request = "launch",
|
||||||
|
mode = "test",
|
||||||
|
program = "''${file}",
|
||||||
|
},
|
||||||
|
-- works with go.mod packages and sub packages
|
||||||
|
{
|
||||||
|
type = "delve",
|
||||||
|
name = "Debug test (go.mod)",
|
||||||
|
request = "launch",
|
||||||
|
mode = "test",
|
||||||
|
program = "./''${relativeFileDirname}",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.vim.languages.go = {
|
options.vim.languages.go = {
|
||||||
enable = mkEnableOption "Go language support";
|
enable = mkEnableOption "Go language support";
|
||||||
|
@ -46,6 +86,24 @@ in {
|
||||||
default = servers.${cfg.lsp.server}.package;
|
default = servers.${cfg.lsp.server}.package;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dap = {
|
||||||
|
enable = mkOption {
|
||||||
|
description = "Enable Go Debug Adapter";
|
||||||
|
type = types.bool;
|
||||||
|
default = config.vim.languages.enableDAP;
|
||||||
|
};
|
||||||
|
debugger = mkOption {
|
||||||
|
description = "Go debugger to use";
|
||||||
|
type = with types; enum (attrNames debuggers);
|
||||||
|
default = defaultDebugger;
|
||||||
|
};
|
||||||
|
package = mkOption {
|
||||||
|
description = "Go debugger package.";
|
||||||
|
type = types.package;
|
||||||
|
default = debuggers.${cfg.dap.debugger}.package;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
@ -58,5 +116,10 @@ in {
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.lspconfig.enable = true;
|
||||||
vim.lsp.lspconfig.sources.go-lsp = servers.${cfg.lsp.server}.lspConfig;
|
vim.lsp.lspconfig.sources.go-lsp = servers.${cfg.lsp.server}.lspConfig;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(mkIf cfg.dap.enable {
|
||||||
|
vim.debugger.nvim-dap.enable = true;
|
||||||
|
vim.debugger.nvim-dap.sources.go-debugger = debuggers.${cfg.dap.debugger}.dapConfig;
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue