plugins/dap-go: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2025-01-26 13:14:13 -06:00
parent 4d1bd375c7
commit 6ff7127291
No known key found for this signature in database
6 changed files with 131 additions and 98 deletions

View file

@ -0,0 +1,53 @@
{
lib,
...
}:
let
inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts;
dapHelpers = import ../dap/dapHelpers.nix { inherit lib; };
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "dap-go";
package = "nvim-dap-go";
maintainers = [ lib.maintainers.khaneliman ];
settingsOptions = {
dap_configurations = lib.nixvim.mkNullOrOption (types.listOf dapHelpers.configurationOption) ''
Additional dap configurations.
See `:h dap-configuration` for more detail.
'';
delve = {
path = defaultNullOpts.mkStr "dlv" "The path to the executable dlv which will be used for debugging.";
initialize_timeout_sec = defaultNullOpts.mkUnsignedInt 20 "Time to wait for delve to initialize the debug session.";
port = defaultNullOpts.mkStr "$${port}" ''
A string that defines the port to start delve debugger.
Defaults to string "$${port}" which instructs dap
to start the process in a random available port.
'';
args = lib.nixvim.mkNullOrOption (types.listOf types.str) "Additional args to pass to dlv.";
build_flags = defaultNullOpts.mkStr "" "Build flags to pass to dlv.";
};
};
# Manually supplied to nvim-dap config module
callSetup = false;
extraConfig = cfg: {
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("dap-go").setup(${lib.nixvim.toLuaObject cfg.settings})
'';
};
};
# NOTE: Renames added in https://github.com/nix-community/nixvim/pull/2897 (2025-01-26)
imports = [ ./deprecations.nix ];
}

View file

@ -0,0 +1,48 @@
{ lib, ... }:
let
oldPluginBasePath = [
"plugins"
"dap"
"extensions"
"dap-go"
];
newPluginBasePath = [
"plugins"
"dap-go"
];
settingsPath = newPluginBasePath ++ [ "settings" ];
renamedOptions = [
"dapConfigurations"
[
"delve"
"path"
]
[
"delve"
"initializeTimeoutSec"
]
[
"delve"
"port"
]
[
"delve"
"args"
]
[
"delve"
"buildFlags"
]
];
renameWarnings =
lib.nixvim.mkSettingsRenamedOptionModules oldPluginBasePath settingsPath
renamedOptions;
in
{
imports = renameWarnings ++ [
(lib.mkRenamedOptionModule (oldPluginBasePath ++ [ "enable" ]) (newPluginBasePath ++ [ "enable" ]))
];
}

View file

@ -1,69 +0,0 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts;
cfg = config.plugins.dap.extensions.dap-go;
dapHelpers = import ./dapHelpers.nix { inherit lib; };
in
{
options.plugins.dap.extensions.dap-go = {
enable = lib.mkEnableOption "dap-go";
package = lib.mkPackageOption pkgs "dap-go" {
default = [
"vimPlugins"
"nvim-dap-go"
];
};
dapConfigurations = lib.nixvim.mkNullOrOption (types.listOf dapHelpers.configurationOption) ''
Additional dap configurations.
See `:h dap-configuration` for more detail.
'';
delve = {
path = defaultNullOpts.mkStr "dlv" "The path to the executable dlv which will be used for debugging.";
initializeTimeoutSec = defaultNullOpts.mkInt 20 "Time to wait for delve to initialize the debug session.";
port = defaultNullOpts.mkStr "$\{port}" ''
A string that defines the port to start delve debugger.
Defaults to string "$\{port}" which instructs dap
to start the process in a random available port.
'';
args = lib.nixvim.mkNullOrOption (types.listOf types.str) "Additional args to pass to dlv.";
buildFlags = defaultNullOpts.mkStr "" "Build flags to pass to dlv.";
};
};
config =
let
options = with cfg; {
dap_configurations = dapConfigurations;
delve = with delve; {
inherit path port args;
initialize_timeout_sec = initializeTimeoutSec;
build_flags = buildFlags;
};
};
in
lib.mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("dap-go").setup(${lib.nixvim.toLuaObject options})
'';
};
};
}

View file

@ -13,7 +13,6 @@ let
in
lib.nixvim.plugins.mkNeovimPlugin {
imports = [
./dap-go.nix
./dap-python.nix
./dap-ui.nix
./dap-virtual-text.nix

View file

@ -0,0 +1,30 @@
{
empty = {
plugins.dap-go.enable = true;
};
default = {
plugins.dap-go = {
enable = true;
settings = {
dap_configurations = [
{
# Must be "go" or it will be ignored by the plugin
type = "go";
name = "Attach remote";
mode = "remote";
request = "attach";
}
];
delve = {
path = "dlv";
initialize_timeout_sec = 20;
port = "$\{port}";
args = [ ];
build_flags = "-tags=unit";
};
};
};
};
}

View file

@ -1,28 +0,0 @@
{
empty = {
plugins.dap.extensions.dap-go.enable = true;
};
default = {
plugins.dap.extensions.dap-go = {
enable = true;
dapConfigurations = [
{
# Must be "go" or it will be ignored by the plugin
type = "go";
name = "Attach remote";
mode = "remote";
request = "attach";
}
];
delve = {
path = "dlv";
initializeTimeoutSec = 20;
port = "$\{port}";
args = [ ];
buildFlags = "-tags=unit";
};
};
};
}