From c4e9c2b7cb788bfabc50607d87e82ab87ba40771 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 26 Jan 2025 15:11:29 -0600 Subject: [PATCH] plugins/dap-ui: migrate to mkNeovimPlugin --- .../{dap/dap-ui.nix => dap-ui/default.nix} | 103 ++++---------- plugins/by-name/dap-ui/deprecations.nix | 126 ++++++++++++++++++ plugins/by-name/dap/default.nix | 1 - .../plugins/by-name/dap-ui/default.nix | 99 ++++++++++++++ .../plugins/by-name/dap/dap-ui.nix | 97 -------------- 5 files changed, 253 insertions(+), 173 deletions(-) rename plugins/by-name/{dap/dap-ui.nix => dap-ui/default.nix} (60%) create mode 100644 plugins/by-name/dap-ui/deprecations.nix create mode 100644 tests/test-sources/plugins/by-name/dap-ui/default.nix delete mode 100644 tests/test-sources/plugins/by-name/dap/dap-ui.nix diff --git a/plugins/by-name/dap/dap-ui.nix b/plugins/by-name/dap-ui/default.nix similarity index 60% rename from plugins/by-name/dap/dap-ui.nix rename to plugins/by-name/dap-ui/default.nix index 659b9550ba..d140dbce23 100644 --- a/plugins/by-name/dap/dap-ui.nix +++ b/plugins/by-name/dap-ui/default.nix @@ -1,15 +1,11 @@ { lib, - config, - pkgs, ... }: let inherit (lib) mkOption types; inherit (lib.nixvim) defaultNullOpts; - cfg = config.plugins.dap.extensions.dap-ui; - mkSizeOption = lib.nixvim.mkNullOrOption (with types; either int (numbers.between 0.0 1.0)); mkKeymapOptions = @@ -54,17 +50,14 @@ let }; }; in -{ - options.plugins.dap.extensions.dap-ui = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = lib.mkEnableOption "dap-ui"; - - package = lib.mkPackageOption pkgs "dap-ui" { - default = [ - "vimPlugins" - "nvim-dap-ui" - ]; - }; +lib.nixvim.plugins.mkNeovimPlugin { + name = "dap-ui"; + moduleName = "dapui"; + package = "nvim-dap-ui"; + maintainers = [ lib.maintainers.khaneliman ]; + + settingsOptions = { controls = { enabled = defaultNullOpts.mkBool true "Enable controls"; @@ -77,20 +70,20 @@ in "console" ] "Element to show the controls on."; - icons = { - disconnect = defaultNullOpts.mkStr "" ""; - pause = defaultNullOpts.mkStr "" ""; - play = defaultNullOpts.mkStr "" ""; - run_last = defaultNullOpts.mkStr "" ""; - step_into = defaultNullOpts.mkStr "" ""; - step_over = defaultNullOpts.mkStr "" ""; - step_out = defaultNullOpts.mkStr "" ""; - step_back = defaultNullOpts.mkStr "" ""; - terminate = defaultNullOpts.mkStr "" ""; + icons = lib.mapAttrs (name: icon: defaultNullOpts.mkStr icon "The icon for ${name}.") { + disconnect = ""; + pause = ""; + play = ""; + run_last = ""; + step_into = ""; + step_over = ""; + step_out = ""; + step_back = ""; + terminate = ""; }; }; - elementMappings = lib.nixvim.mkNullOrOption (types.attrsOf ( + element_mappings = lib.nixvim.mkNullOrOption (types.attrsOf ( types.submodule { options = mkKeymapOptions "element mapping overrides" { edit = "e"; @@ -106,12 +99,12 @@ in } )) "Per-element overrides of global mappings."; - expandLines = defaultNullOpts.mkBool true "Expand current line to hover window if larger than window size."; + expand_lines = defaultNullOpts.mkBool true "Expand current line to hover window if larger than window size."; floating = { - maxHeight = mkSizeOption "Maximum height of the floating window."; + max_height = mkSizeOption "Maximum height of the floating window."; - maxWidth = mkSizeOption "Maximum width of the floating window."; + max_width = mkSizeOption "Maximum width of the floating window."; border = defaultNullOpts.mkBorder "single" "dap-ui floating window" ""; @@ -125,7 +118,7 @@ in }) "Keys to trigger actions in elements."; }; - forceBuffers = defaultNullOpts.mkBool true "Prevents other buffers being loaded into dap-ui windows."; + force_buffers = defaultNullOpts.mkBool true "Prevents other buffers being loaded into dap-ui windows."; icons = { collapsed = defaultNullOpts.mkStr "" ""; @@ -189,57 +182,17 @@ in render = { indent = defaultNullOpts.mkInt 1 "Default indentation size."; - maxTypeLength = lib.nixvim.mkNullOrOption types.int "Maximum number of characters to allow a type name to fill before trimming."; + max_type_length = lib.nixvim.mkNullOrOption types.int "Maximum number of characters to allow a type name to fill before trimming."; - maxValueLines = defaultNullOpts.mkInt 100 "Maximum number of lines to allow a value to fill before trimming."; + max_value_lines = defaultNullOpts.mkInt 100 "Maximum number of lines to allow a value to fill before trimming."; }; - selectWindow = defaultNullOpts.mkLuaFn null '' + select_window = defaultNullOpts.mkLuaFn null '' A function which returns a window to be used for opening buffers such as a stack frame location. ''; }; - config = - let - options = - with cfg; - { - inherit - controls - icons - layouts - mappings - ; - - element_mappings = elementMappings; - - floating = with floating; { - inherit border mappings; - max_height = maxHeight; - max_width = maxWidth; - }; - - force_buffers = forceBuffers; - - render = with render; { - inherit indent; - max_type_length = maxTypeLength; - max_value_lines = maxValueLines; - }; - - select_window = selectWindow; - } - // cfg.extraOptions; - in - lib.mkIf cfg.enable { - extraPlugins = [ cfg.package ]; - - plugins.dap = { - enable = true; - - extensionConfigLua = '' - require("dapui").setup(${lib.nixvim.toLuaObject options}); - ''; - }; - }; + # NOTE: Renames added in https://github.com/nix-community/nixvim/pull/2897 (2025-01-26) + deprecateExtraOptions = true; + imports = [ ./deprecations.nix ]; } diff --git a/plugins/by-name/dap-ui/deprecations.nix b/plugins/by-name/dap-ui/deprecations.nix new file mode 100644 index 0000000000..b96c20bf31 --- /dev/null +++ b/plugins/by-name/dap-ui/deprecations.nix @@ -0,0 +1,126 @@ +{ lib, ... }: +let + oldPluginBasePath = [ + "plugins" + "dap" + "extensions" + "dap-ui" + ]; + newPluginBasePath = [ + "plugins" + "dap-ui" + ]; + + settingsPath = newPluginBasePath ++ [ "settings" ]; + + renamedOptions = [ + [ + "controls" + "enabled" + ] + [ + "controls" + "element" + ] + [ + "controls" + "icons" + "disconnect" + ] + [ + "controls" + "icons" + "pause" + ] + [ + "controls" + "icons" + "play" + ] + [ + "controls" + "icons" + "run_last" + ] + [ + "controls" + "icons" + "step_into" + ] + [ + "controls" + "icons" + "step_over" + ] + [ + "controls" + "icons" + "step_out" + ] + [ + "controls" + "icons" + "step_back" + ] + [ + "controls" + "icons" + "terminate" + ] + [ "elementMappings" ] + [ "expandLines" ] + [ + "floating" + "maxHeight" + ] + [ + "floating" + "maxWidth" + ] + [ + "floating" + "border" + ] + [ + "floating" + "mappings" + ] + [ "forceBuffers" ] + [ + "icons" + "collapsed" + ] + [ + "icons" + "current_frame" + ] + [ + "icons" + "expanded" + ] + [ "layouts" ] + [ "mappings" ] + [ + "render" + "indent" + ] + [ + "render" + "maxTypeLength" + ] + [ + "render" + "maxValueLines" + ] + [ "selectWindow" ] + ]; + + renameWarnings = + lib.nixvim.mkSettingsRenamedOptionModules oldPluginBasePath settingsPath + renamedOptions; +in +{ + imports = renameWarnings ++ [ + (lib.mkRenamedOptionModule (oldPluginBasePath ++ [ "enable" ]) (newPluginBasePath ++ [ "enable" ])) + ]; +} diff --git a/plugins/by-name/dap/default.nix b/plugins/by-name/dap/default.nix index 0afbc49afe..2d5dc4d5b0 100644 --- a/plugins/by-name/dap/default.nix +++ b/plugins/by-name/dap/default.nix @@ -14,7 +14,6 @@ let in lib.nixvim.plugins.mkNeovimPlugin { imports = [ - ./dap-ui.nix ./dap-virtual-text.nix ]; diff --git a/tests/test-sources/plugins/by-name/dap-ui/default.nix b/tests/test-sources/plugins/by-name/dap-ui/default.nix new file mode 100644 index 0000000000..783900654f --- /dev/null +++ b/tests/test-sources/plugins/by-name/dap-ui/default.nix @@ -0,0 +1,99 @@ +{ + empty = { + plugins.dap-ui.enable = true; + }; + + default = { + plugins.dap-ui = { + enable = true; + + settings = { + controls = { + element = "repl"; + enabled = true; + icons = { + disconnect = ""; + pause = ""; + play = ""; + run_last = ""; + step_back = ""; + step_into = ""; + step_out = ""; + step_over = ""; + terminate = ""; + }; + }; + element_mappings = { }; + expand_lines = true; + floating = { + border = "single"; + mappings = { + close = [ + "q" + "" + ]; + }; + }; + force_buffers = true; + icons = { + collapsed = ""; + current_frame = ""; + expanded = ""; + }; + layouts = [ + { + elements = [ + { + id = "scopes"; + size = 0.25; + } + { + id = "breakpoints"; + size = 0.25; + } + { + id = "stacks"; + size = 0.25; + } + { + id = "watches"; + size = 0.25; + } + ]; + position = "left"; + size = 40; + } + { + elements = [ + { + id = "repl"; + size = 0.5; + } + { + id = "console"; + size = 0.5; + } + ]; + position = "bottom"; + size = 10; + } + ]; + mappings = { + edit = "e"; + expand = [ + "" + "<2-LeftMouse>" + ]; + open = "o"; + remove = "d"; + repl = "r"; + toggle = "t"; + }; + render = { + indent = 1; + max_value_lines = 100; + }; + }; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/dap/dap-ui.nix b/tests/test-sources/plugins/by-name/dap/dap-ui.nix deleted file mode 100644 index 18beeb23ba..0000000000 --- a/tests/test-sources/plugins/by-name/dap/dap-ui.nix +++ /dev/null @@ -1,97 +0,0 @@ -{ - empty = { - plugins.dap.extensions.dap-ui.enable = true; - }; - - default = { - plugins.dap.extensions.dap-ui = { - enable = true; - - controls = { - element = "repl"; - enabled = true; - icons = { - disconnect = ""; - pause = ""; - play = ""; - run_last = ""; - step_back = ""; - step_into = ""; - step_out = ""; - step_over = ""; - terminate = ""; - }; - }; - elementMappings = { }; - expandLines = true; - floating = { - border = "single"; - mappings = { - close = [ - "q" - "" - ]; - }; - }; - forceBuffers = true; - icons = { - collapsed = ""; - current_frame = ""; - expanded = ""; - }; - layouts = [ - { - elements = [ - { - id = "scopes"; - size = 0.25; - } - { - id = "breakpoints"; - size = 0.25; - } - { - id = "stacks"; - size = 0.25; - } - { - id = "watches"; - size = 0.25; - } - ]; - position = "left"; - size = 40; - } - { - elements = [ - { - id = "repl"; - size = 0.5; - } - { - id = "console"; - size = 0.5; - } - ]; - position = "bottom"; - size = 10; - } - ]; - mappings = { - edit = "e"; - expand = [ - "" - "<2-LeftMouse>" - ]; - open = "o"; - remove = "d"; - repl = "r"; - toggle = "t"; - }; - render = { - indent = 1; - maxValueLines = 100; - }; - }; - }; -}