Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

plugins/dap-rr: init #3089

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/by-name/dap-go/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
maintainers = [ lib.maintainers.khaneliman ];

settingsOptions = {
dap_configurations = lib.nixvim.mkNullOrOption (types.listOf dapHelpers.configurationOption) ''
dap_configurations = lib.nixvim.mkNullOrOption (types.listOf dapHelpers.configurationType) ''
Additional dap configurations.
See `:h dap-configuration` for more detail.
'';
Expand Down
2 changes: 1 addition & 1 deletion plugins/by-name/dap-python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
type = types.str;
};

customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationType) "Custom python configurations for dap.";

resolvePython = defaultNullOpts.mkLuaFn null ''
Function to resolve path to python to use for program or test execution.
Expand Down
64 changes: 64 additions & 0 deletions plugins/by-name/dap-rr/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{ lib, ... }:
let
inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts;
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "dap-rr";
packPathName = "nvim-dap-rr";
package = "nvim-dap-rr";

maintainers = [ lib.maintainers.GaetanLepage ];

settingsOptions = {
mappings =
defaultNullOpts.mkAttrsOf types.str
{
continue = "<F7>";
step_over = "<F8>";
step_out = "<F9>";
step_into = "<F10>";
reverse_continue = "<F19>";
reverse_step_over = "<F20>";
reverse_step_out = "<F21>";
reverse_step_into = "<F22>";
step_over_i = "<F32>";
step_out_i = "<F33>";
step_into_i = "<F34>";
reverse_step_over_i = "<F44>";
reverse_step_out_i = "<F45>";
reverse_step_into_i = "<F46>";
}
''
Keyboard mappings for nvim-dap-rr.
'';
};

settingsExample = {
mappings = {
continue = "<f4>";
step_over = "<f10>";
step_out = "<f8>";
step_into = "<f11>";
reverse_continue = "<f4>";
reverse_step_over = "<s-f10>";
reverse_step_out = "<s-f8>";
reverse_step_into = "<s-f11>";
};
};

# Manually supplied to nvim-dap config module
callSetup = false;
extraConfig = cfg: {
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("nvim-dap-rr").setup(${lib.nixvim.toLuaObject cfg.settings})
'';
configurations = {
rust = lib.mkDefault [ { __raw = "require('nvim-dap-rr').get_rust_config()"; } ];
cpp = lib.mkDefault [ { __raw = "require('nvim-dap-rr').get_config()"; } ];
Comment on lines +59 to +60
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set up the configurationType so that a string would be automatically converted to lua?

Copy link
Member

@MattSturgeon MattSturgeon Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial reaction: I'd assume not, since we want to gradually move away from such implicit conversion?

Saying that, this is a non-freeform option (right?), so we can design it to be more helpful if we wanted.

If we aren't trying to exactly represent an upstream setting and it's unlikely that non-raw string values will ever be valid, then treating strings as lua is fine IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying that, this is a non-freeform option (right?), so we can design it to be more helpful if we wanted.

If we aren't trying to exactly represent an upstream setting and it's unlikely that non-raw string values will ever be valid, then treating strings as lua is fine IMO.

This was exactly my reasoning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I gave it a try and it adds more complexity than I thought.
As dap-go and dap-python both use this type, we would need to port the conversion logic there too.
Maybe it is better to stick to using the rawType straight.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if we did this we'd want to construct two types; one for use in freeform settings and another one that can be used in nixvim's own options.

Both types could use the same modules in their submodule-type though.

};
};
};
}
44 changes: 23 additions & 21 deletions plugins/by-name/dap/dapHelpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,33 @@ rec {
is used. A use-case for this is starting an adapter asynchronous.
'';

configurationOption = types.submodule {
freeformType = types.attrs;
configurationType = types.maybeRaw (
types.submodule {
freeformType = types.attrs;

options = {
type = lib.mkOption {
description = "Which debug adapter to use.";
type = types.str;
};
options = {
type = lib.mkOption {
description = "Which debug adapter to use.";
type = types.str;
};

request = lib.mkOption {
type = types.enum [
"attach"
"launch"
];
description = ''
Indicates whether the debug adapter should launch a debuggee or attach to one that is already running.
'';
};
request = lib.mkOption {
type = types.enum [
"attach"
"launch"
];
description = ''
Indicates whether the debug adapter should launch a debuggee or attach to one that is already running.
'';
};

name = lib.mkOption {
type = types.str;
description = "A user readable name for the configuration.";
name = lib.mkOption {
type = types.str;
description = "A user readable name for the configuration.";
};
};
};
};
}
);

mkSignOption = default: desc: {
text = lib.nixvim.defaultNullOpts.mkStr default desc;
Expand Down
2 changes: 1 addition & 1 deletion plugins/by-name/dap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

configurations =
lib.nixvim.mkNullOrOption (with types; attrsOf (listOf dapHelpers.configurationOption))
lib.nixvim.mkNullOrOption (with types; attrsOf (listOf dapHelpers.configurationType))
''
Debugger configurations, see `:h dap-configuration` for more info.
'';
Expand Down
58 changes: 58 additions & 0 deletions tests/test-sources/plugins/by-name/dap-rr/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
empty = {
plugins = {
dap.enable = true;
dap-rr.enable = true;
};
};

defaults = {
plugins = {
dap.enable = true;
dap-rr = {
enable = true;

settings = {
mappings = {
continue = "<F7>";
step_over = "<F8>";
step_out = "<F9>";
step_into = "<F10>";
reverse_continue = "<F19>";
reverse_step_over = "<F20>";
reverse_step_out = "<F21>";
reverse_step_into = "<F22>";
step_over_i = "<F32>";
step_out_i = "<F33>";
step_into_i = "<F34>";
reverse_step_over_i = "<F44>";
reverse_step_out_i = "<F45>";
reverse_step_into_i = "<F46>";
};
};
};
};
};

example = {
plugins = {
dap.enable = true;
dap-rr = {
enable = true;

settings = {
mappings = {
continue = "<f4>";
step_over = "<f10>";
step_out = "<f8>";
step_into = "<f11>";
reverse_continue = "<f4>";
reverse_step_over = "<s-f10>";
reverse_step_out = "<s-f8>";
reverse_step_into = "<s-f11>";
};
};
};
};
};
}