plugins/dap: move to by-name

This commit is contained in:
Matt Sturgeon 2024-09-04 17:34:55 +01:00
parent 52f125679f
commit 672b9e1ceb
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
12 changed files with 0 additions and 2 deletions

View file

@ -0,0 +1,70 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.dap.extensions.dap-go;
dapHelpers = import ./dapHelpers.nix { inherit lib helpers; };
in
{
options.plugins.dap.extensions.dap-go = {
enable = mkEnableOption "dap-go";
package = lib.mkPackageOption pkgs "dap-go" {
default = [
"vimPlugins"
"nvim-dap-go"
];
};
dapConfigurations = helpers.mkNullOrOption (types.listOf dapHelpers.configurationOption) ''
Additional dap configurations.
See `:h dap-configuration` for more detail.
'';
delve = {
path = helpers.defaultNullOpts.mkStr "dlv" "The path to the executable dlv which will be used for debugging.";
initializeTimeoutSec =
helpers.defaultNullOpts.mkInt 20
"Time to wait for delve to initialize the debug session.";
port = helpers.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 = helpers.mkNullOrOption (types.listOf types.str) "Additional args to pass to dlv.";
buildFlags = helpers.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
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("dap-go").setup(${helpers.toLuaObject options})
'';
};
};
}

View file

@ -0,0 +1,93 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.dap.extensions.dap-python;
dapHelpers = import ./dapHelpers.nix { inherit lib helpers; };
in
{
options.plugins.dap.extensions.dap-python = {
enable = mkEnableOption "dap-python";
package = lib.mkPackageOption pkgs "dap-python" {
default = [
"vimPlugins"
"nvim-dap-python"
];
};
adapterPythonPath = mkOption {
default = "${pkgs.python3.withPackages (ps: with ps; [ debugpy ])}/bin/python3";
description = "Path to the python interpreter. Path must be absolute or in $PATH and needs to have the debugpy package installed.";
type = types.str;
};
console = helpers.defaultNullOpts.mkEnumFirstDefault [
"integratedTerminal"
"internalConsole"
"externalTerminal"
] "Debugpy console.";
customConfigurations = helpers.mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
includeConfigs = helpers.defaultNullOpts.mkBool true "Add default configurations.";
resolvePython = helpers.defaultNullOpts.mkLuaFn null ''
Function to resolve path to python to use for program or test execution.
By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present.
'';
testRunner = helpers.mkNullOrOption (types.either types.str helpers.nixvimTypes.rawLua) ''
The name of test runner to use by default.
The default value is dynamic and depends on `pytest.ini` or `manage.py` markers.
If neither is found "unittest" is used.
'';
testRunners = helpers.mkNullOrOption (with helpers.nixvimTypes; attrsOf strLuaFn) ''
Set to register test runners.
Built-in are test runners for unittest, pytest and django.
The key is the test runner name, the value a function to generate the
module name to run and its arguments.
See |dap-python.TestRunner|.
'';
};
config =
let
options = with cfg; {
inherit console;
include_configs = includeConfigs;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.dap = {
enable = true;
extensionConfigLua =
with helpers;
''
require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject options})
''
+ (optionalString (cfg.testRunners != null) ''
table.insert(require("dap-python").test_runners,
${toLuaObject (builtins.mapAttrs (_: mkRaw) cfg.testRunners)})
'')
+ (optionalString (cfg.customConfigurations != null) ''
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
'')
+ (optionalString (cfg.resolvePython != null) ''
require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
'')
+ (optionalString (cfg.testRunner != null) ''
require("dap-python").test_runner = ${toLuaObject cfg.testRunner};
'');
};
};
}

View file

@ -0,0 +1,248 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.dap.extensions.dap-ui;
mkSizeOption = helpers.mkNullOrOption (with types; either int (numbers.between 0.0 1.0));
mkKeymapOptions =
name:
mapAttrs (
key: default:
helpers.defaultNullOpts.mkNullable (
with types; either str (listOf str)
) default "Map `${key}` for ${name}"
);
elementOption = types.submodule {
options = {
id = helpers.mkNullOrOption types.str "Element ID.";
size = mkSizeOption "Size of the element in lines/columns or as proportion of total editor size (0-1).";
};
};
layoutOption = types.submodule {
options = {
elements = mkOption {
default = [ ];
description = "Elements to display in this layout.";
type = with types; listOf (either str elementOption);
};
size = mkOption {
default = 10;
description = "Size of the layout in lines/columns.";
type = types.int;
};
position = mkOption {
default = "left";
description = "Which side of editor to open layout on.";
type = types.enum [
"left"
"right"
"top"
"bottom"
];
};
};
};
in
{
options.plugins.dap.extensions.dap-ui = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "dap-ui";
package = lib.mkPackageOption pkgs "dap-ui" {
default = [
"vimPlugins"
"nvim-dap-ui"
];
};
controls = {
enabled = helpers.defaultNullOpts.mkBool true "Enable controls";
element = helpers.defaultNullOpts.mkEnumFirstDefault [
"repl"
"scopes"
"stacks"
"watches"
"breakpoints"
"console"
] "Element to show the controls on.";
icons = {
disconnect = helpers.defaultNullOpts.mkStr "" "";
pause = helpers.defaultNullOpts.mkStr "" "";
play = helpers.defaultNullOpts.mkStr "" "";
run_last = helpers.defaultNullOpts.mkStr "" "";
step_into = helpers.defaultNullOpts.mkStr "" "";
step_over = helpers.defaultNullOpts.mkStr "" "";
step_out = helpers.defaultNullOpts.mkStr "" "";
step_back = helpers.defaultNullOpts.mkStr "" "";
terminate = helpers.defaultNullOpts.mkStr "" "";
};
};
elementMappings = helpers.mkNullOrOption (types.attrsOf (
types.submodule {
options = mkKeymapOptions "element mapping overrides" {
edit = "e";
expand = [
"<CR>"
"<2-LeftMouse>"
];
open = "o";
remove = "d";
repl = "r";
toggle = "t";
};
}
)) "Per-element overrides of global mappings.";
expandLines = helpers.defaultNullOpts.mkBool true "Expand current line to hover window if larger than window size.";
floating = {
maxHeight = mkSizeOption "Maximum height of the floating window.";
maxWidth = mkSizeOption "Maximum width of the floating window.";
border = helpers.defaultNullOpts.mkBorder "single" "dap-ui floating window" "";
mappings = helpers.mkNullOrOption (types.submodule {
options = mkKeymapOptions "dap-ui floating" {
close = [
"<ESC>"
"q"
];
};
}) "Keys to trigger actions in elements.";
};
forceBuffers = helpers.defaultNullOpts.mkBool true "Prevents other buffers being loaded into dap-ui windows.";
icons = {
collapsed = helpers.defaultNullOpts.mkStr "" "";
current_frame = helpers.defaultNullOpts.mkStr "" "";
expanded = helpers.defaultNullOpts.mkStr "" "";
};
layouts = helpers.defaultNullOpts.mkListOf layoutOption [
{
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;
}
] "List of layouts for dap-ui.";
mappings = helpers.mkNullOrOption (types.submodule {
options = mkKeymapOptions "dap-ui" {
edit = "e";
expand = [
"<CR>"
"<2-LeftMouse>"
];
open = "o";
remove = "d";
repl = "r";
toggle = "t";
};
}) "Keys to trigger actions in elements.";
render = {
indent = helpers.defaultNullOpts.mkInt 1 "Default indentation size.";
maxTypeLength = helpers.mkNullOrOption types.int "Maximum number of characters to allow a type name to fill before trimming.";
maxValueLines =
helpers.defaultNullOpts.mkInt 100
"Maximum number of lines to allow a value to fill before trimming.";
};
selectWindow = helpers.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
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("dapui").setup(${helpers.toLuaObject options});
'';
};
};
}

View file

@ -0,0 +1,101 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.dap.extensions.dap-virtual-text;
in
{
options.plugins.dap.extensions.dap-virtual-text = {
enable = mkEnableOption "dap-virtual-text";
package = lib.mkPackageOption pkgs "dap-virtual-text" {
default = [
"vimPlugins"
"nvim-dap-virtual-text"
];
};
enabledCommands = helpers.defaultNullOpts.mkBool true ''
Create commands `DapVirtualTextEnable`, `DapVirtualTextDisable`, `DapVirtualTextToggle`.
(`DapVirtualTextForceRefresh` for refreshing when debug adapter did not notify its termination).
'';
highlightChangedVariables = helpers.defaultNullOpts.mkBool true ''
Highlight changed values with `NvimDapVirtualTextChanged`, else always `NvimDapVirtualText`.
'';
highlightNewAsChanged = helpers.defaultNullOpts.mkBool false ''
Highlight new variables in the same way as changed variables (if highlightChangedVariables).
'';
showStopReason = helpers.defaultNullOpts.mkBool true "Show stop reason when stopped for exceptions.";
commented = helpers.defaultNullOpts.mkBool false "Prefix virtual text with comment string.";
onlyFirstDefinition = helpers.defaultNullOpts.mkBool true "Only show virtual text at first definition (if there are multiple).";
allReferences = helpers.defaultNullOpts.mkBool false "Show virtual text on all all references of the variable (not only definitions).";
clearOnContinue = helpers.defaultNullOpts.mkBool false "Clear virtual text on `continue` (might cause flickering when stepping).";
displayCallback = helpers.defaultNullOpts.mkLuaFn ''
function(variable, buf, stackframe, node, options)
if options.virt_text_pos == 'inline' then
return ' = ' .. variable.value
else
return variable.name .. ' = ' .. variable.value
end
end,
'' "A callback that determines how a variable is displayed or whether it should be omitted.";
virtTextPos = helpers.defaultNullOpts.mkStr "vim.fn.has 'nvim-0.10' == 1 and 'inline' or 'eol'" ''
Position of virtual text, see `:h nvim_buf_set_extmark()`.
Default tries to inline the virtual text. Use 'eol' to set to end of line.
'';
allFrames = helpers.defaultNullOpts.mkBool false "Show virtual text for all stack frames not only current.";
virtLines = helpers.defaultNullOpts.mkBool false "Show virtual lines instead of virtual text (will flicker!).";
virtTextWinCol = helpers.mkNullOrOption types.int ''
Position the virtual text at a fixed window column (starting from the first text column).
See `:h nvim_buf_set_extmark()`.
'';
};
config =
let
options = with cfg; {
inherit commented;
enabled_commands = enabledCommands;
highlight_changed_variables = highlightChangedVariables;
highlight_new_as_changed = highlightNewAsChanged;
show_stop_reason = showStopReason;
only_first_definition = onlyFirstDefinition;
all_references = allReferences;
clear_on_continue = clearOnContinue;
display_callback = displayCallback;
virt_text_pos = virtTextPos;
all_frames = allFrames;
virt_lines = virtLines;
virt_text_win_col = virtTextWinCol;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
plugins.dap = {
enable = true;
extensionConfigLua = ''
require("nvim-dap-virtual-text").setup(${helpers.toLuaObject options});
'';
};
};
}

View file

@ -0,0 +1,140 @@
{ lib, helpers }:
with lib;
rec {
mkAdapterType =
attrs:
types.submodule {
options = {
id = helpers.mkNullOrOption types.str ''
Identifier of the adapter. This is used for the
`adapterId` property of the initialize request.
For most debug adapters setting this is not necessary.
'';
enrichConfig = helpers.mkNullOrLuaFn ''
A lua function (`func(config, on_config)`) which allows an adapter to enrich a
configuration with additional information. It receives a configuration as first
argument, and a callback that must be called with the final configuration as second argument.
'';
options = {
initializeTimeoutSec = helpers.defaultNullOpts.mkInt 4 ''
How many seconds the client waits for a response on a initialize request before emitting a warning.
'';
disconnectTimeoutSec = helpers.defaultNullOpts.mkInt 3 ''
How many seconds the client waits for a disconnect response from the debug
adapter before emitting a warning and closing the connection.
'';
sourceFiletype = helpers.mkNullOrOption types.str ''
The filetype to use for content retrieved via a source request.
'';
};
} // attrs;
};
executableAdapterOption = mkAdapterType {
command = helpers.mkNullOrOption types.str "The command to invoke.";
args = helpers.mkNullOrOption (types.listOf types.str) "Arguments for the command.";
options = {
env = helpers.mkNullOrOption types.attrs "Set the environment variables for the command.";
cwd = helpers.mkNullOrOption types.str "Set the working directory for the command.";
detached = helpers.defaultNullOpts.mkBool true "Start the debug adapter in a detached state.";
};
};
serverAdapterOption = mkAdapterType {
host = helpers.defaultNullOpts.mkStr "127.0.0.1" "Host to connect to.";
port = helpers.mkNullOrOption (types.either types.int (types.enum [ "$\{port}" ])) ''
Port to connect to.
If "$\{port}" dap resolves a free port.
This is intended to be used with `executable.args`.
'';
executable = {
command = helpers.mkNullOrOption types.str "Command that spawns the adapter.";
args = helpers.mkNullOrOption (types.listOf types.str) "Command arguments.";
detached = helpers.defaultNullOpts.mkBool true "Spawn the debug adapter in detached state.";
cwd = helpers.mkNullOrOption types.str "Working directory.";
};
options.maxRetries = helpers.defaultNullOpts.mkInt 14 ''
Amount of times the client should attempt to connect before erroring out.
There is a 250ms delay between each retry.
'';
};
mkAdapterOption =
name: type:
helpers.mkNullOrOption (with types; attrsOf (either str type)) ''
Debug adapters of `${name}` type.
The adapters can also be set to a function which takes three arguments:
- A `on_config` callback. This must be called with the actual adapter table.
- The |dap-configuration| which the user wants to use.
- An optional parent session. This is only available if the debug-adapter
wants to start a child-session via a `startDebugging` request.
This can be used to defer the resolving of the values to when a configuration
is used. A use-case for this is starting an adapter asynchronous.
'';
configurationOption = types.submodule {
freeformType = types.attrs;
options = {
type = mkOption {
description = "Which debug adapter to use.";
type = types.str;
};
request = 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 = mkOption {
type = types.str;
description = "A user readable name for the configuration.";
};
};
};
mkSignOption = default: desc: {
text = helpers.defaultNullOpts.mkStr default desc;
texthl = helpers.mkNullOrOption types.str "`texthl` for sign.";
linehl = helpers.mkNullOrOption types.str "`linehl` for sign.";
numhl = helpers.mkNullOrOption types.str "`numhl` for sign.";
};
processAdapters =
type: adapters:
with builtins;
mapAttrs (
_: adapter:
if isString adapter then
helpers.mkRaw adapter
else
filterAttrs (n: _: n != "enrichConfig") (
adapter
// {
inherit type;
enrich_config = adapter.enrichConfig;
}
)
) adapters;
}

View file

@ -0,0 +1,106 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.dap;
dapHelpers = import ./dapHelpers.nix { inherit lib helpers; };
in
with dapHelpers;
{
imports = [
./dap-go.nix
./dap-python.nix
./dap-ui.nix
./dap-virtual-text.nix
];
options.plugins.dap = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "dap";
package = lib.mkPackageOption pkgs "dap" {
default = [
"vimPlugins"
"nvim-dap"
];
};
adapters = helpers.mkCompositeOption "Dap adapters." {
executables = mkAdapterOption "executable" executableAdapterOption;
servers = mkAdapterOption "server" serverAdapterOption;
};
configurations =
helpers.mkNullOrOption (with types; attrsOf (listOf dapHelpers.configurationOption))
''
Debuggee configurations, see `:h dap-configuration` for more info.
'';
signs = helpers.mkCompositeOption "Signs for dap." {
dapBreakpoint = mkSignOption "B" "Sign for breakpoints.";
dapBreakpointCondition = mkSignOption "C" "Sign for conditional breakpoints.";
dapLogPoint = mkSignOption "L" "Sign for log points.";
dapStopped = mkSignOption "" "Sign to indicate where the debuggee is stopped.";
dapBreakpointRejected = mkSignOption "R" "Sign to indicate breakpoints rejected by the debug adapter.";
};
extensionConfigLua = mkOption {
type = types.lines;
description = ''
Extension configuration for dap. Don't use this directly !
'';
default = "";
internal = true;
};
};
config =
let
options =
with cfg;
{
inherit configurations;
adapters =
(lib.optionalAttrs (adapters.executables != null) (
processAdapters "executable" adapters.executables
))
// (lib.optionalAttrs (adapters.servers != null) (processAdapters "server" adapters.servers));
signs = with signs; {
DapBreakpoint = dapBreakpoint;
DapBreakpointCondition = dapBreakpointCondition;
DapLogPoint = dapLogPoint;
DapStopped = dapStopped;
DapBreakpointRejected = dapBreakpointRejected;
};
}
// cfg.extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua =
(optionalString (cfg.adapters != null) ''
require("dap").adapters = ${helpers.toLuaObject options.adapters}
'')
+ (optionalString (options.configurations != null) ''
require("dap").configurations = ${helpers.toLuaObject options.configurations}
'')
+ (optionalString (cfg.signs != null) ''
local __dap_signs = ${helpers.toLuaObject options.signs}
for sign_name, sign in pairs(__dap_signs) do
vim.fn.sign_define(sign_name, sign)
end
'')
+ cfg.extensionConfigLua;
};
}