Skip to content

Commit

Permalink
plugins/dap-ui: migrate to mkNeovimPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Jan 27, 2025
1 parent b7901a5 commit c4e9c2b
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 173 deletions.
103 changes: 28 additions & 75 deletions plugins/by-name/dap/dap-ui.nix → plugins/by-name/dap-ui/default.nix
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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";

Expand All @@ -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";
Expand All @@ -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" "";

Expand All @@ -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 "" "";
Expand Down Expand Up @@ -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 ];
}
126 changes: 126 additions & 0 deletions plugins/by-name/dap-ui/deprecations.nix
Original file line number Diff line number Diff line change
@@ -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" ]))
];
}
1 change: 0 additions & 1 deletion plugins/by-name/dap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ let
in
lib.nixvim.plugins.mkNeovimPlugin {
imports = [
./dap-ui.nix
./dap-virtual-text.nix
];

Expand Down
99 changes: 99 additions & 0 deletions tests/test-sources/plugins/by-name/dap-ui/default.nix
Original file line number Diff line number Diff line change
@@ -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"
"<Esc>"
];
};
};
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 = [
"<CR>"
"<2-LeftMouse>"
];
open = "o";
remove = "d";
repl = "r";
toggle = "t";
};
render = {
indent = 1;
max_value_lines = 100;
};
};
};
};
}
Loading

0 comments on commit c4e9c2b

Please sign in to comment.