From 6ff71272915b99218de615ad25fce33d10c79b84 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 26 Jan 2025 13:14:13 -0600 Subject: [PATCH] plugins/dap-go: migrate to mkNeovimPlugin --- plugins/by-name/dap-go/default.nix | 53 ++++++++++++++ plugins/by-name/dap-go/deprecations.nix | 48 +++++++++++++ plugins/by-name/dap/dap-go.nix | 69 ------------------- plugins/by-name/dap/default.nix | 1 - .../plugins/by-name/dap-go/default.nix | 30 ++++++++ .../plugins/by-name/dap/dap-go.nix | 28 -------- 6 files changed, 131 insertions(+), 98 deletions(-) create mode 100644 plugins/by-name/dap-go/default.nix create mode 100644 plugins/by-name/dap-go/deprecations.nix delete mode 100644 plugins/by-name/dap/dap-go.nix create mode 100644 tests/test-sources/plugins/by-name/dap-go/default.nix delete mode 100644 tests/test-sources/plugins/by-name/dap/dap-go.nix diff --git a/plugins/by-name/dap-go/default.nix b/plugins/by-name/dap-go/default.nix new file mode 100644 index 00000000..29873c6c --- /dev/null +++ b/plugins/by-name/dap-go/default.nix @@ -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 ]; +} diff --git a/plugins/by-name/dap-go/deprecations.nix b/plugins/by-name/dap-go/deprecations.nix new file mode 100644 index 00000000..1f38bf27 --- /dev/null +++ b/plugins/by-name/dap-go/deprecations.nix @@ -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" ])) + ]; +} diff --git a/plugins/by-name/dap/dap-go.nix b/plugins/by-name/dap/dap-go.nix deleted file mode 100644 index 89f22aeb..00000000 --- a/plugins/by-name/dap/dap-go.nix +++ /dev/null @@ -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}) - ''; - }; - }; -} diff --git a/plugins/by-name/dap/default.nix b/plugins/by-name/dap/default.nix index 858815ed..6ea78cb8 100644 --- a/plugins/by-name/dap/default.nix +++ b/plugins/by-name/dap/default.nix @@ -13,7 +13,6 @@ let in lib.nixvim.plugins.mkNeovimPlugin { imports = [ - ./dap-go.nix ./dap-python.nix ./dap-ui.nix ./dap-virtual-text.nix diff --git a/tests/test-sources/plugins/by-name/dap-go/default.nix b/tests/test-sources/plugins/by-name/dap-go/default.nix new file mode 100644 index 00000000..bffacfe7 --- /dev/null +++ b/tests/test-sources/plugins/by-name/dap-go/default.nix @@ -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"; + }; + }; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/dap/dap-go.nix b/tests/test-sources/plugins/by-name/dap/dap-go.nix deleted file mode 100644 index 439a4421..00000000 --- a/tests/test-sources/plugins/by-name/dap/dap-go.nix +++ /dev/null @@ -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"; - }; - }; - }; -}