nix-community.nixvim/plugins/by-name/dap/dapHelpers.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

143 lines
4.6 KiB
Nix
Raw Normal View History

2025-01-23 20:11:11 -06:00
{ lib }:
2025-01-23 20:02:06 -06:00
let
inherit (lib) types;
2025-01-23 20:11:11 -06:00
inherit (lib.nixvim) mkNullOrOption;
2025-01-23 20:02:06 -06:00
in
rec {
mkAdapterType =
attrs:
types.submodule {
options = {
2025-01-23 20:11:11 -06:00
id = 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.
2024-05-05 19:39:35 +02:00
'';
2025-01-23 20:11:11 -06:00
enrichConfig = lib.nixvim.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.
2024-05-05 19:39:35 +02:00
'';
options = {
2025-01-23 20:11:11 -06:00
initializeTimeoutSec = lib.nixvim.defaultNullOpts.mkInt 4 ''
How many seconds the client waits for a response on a initialize request before emitting a warning.
'';
2025-01-23 20:11:11 -06:00
disconnectTimeoutSec = lib.nixvim.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.
'';
2025-01-23 20:11:11 -06:00
sourceFiletype = mkNullOrOption types.str ''
The filetype to use for content retrieved via a source request.
'';
};
} // attrs;
};
executableAdapterOption = mkAdapterType {
2025-01-23 20:11:11 -06:00
command = mkNullOrOption types.str "The command to invoke.";
2025-01-23 20:11:11 -06:00
args = mkNullOrOption (types.listOf types.str) "Arguments for the command.";
options = {
2025-01-23 20:11:11 -06:00
env = mkNullOrOption types.attrs "Set the environment variables for the command.";
2025-01-23 20:11:11 -06:00
cwd = mkNullOrOption types.str "Set the working directory for the command.";
2025-01-23 20:11:11 -06:00
detached = lib.nixvim.defaultNullOpts.mkBool true "Start the debug adapter in a detached state.";
};
};
serverAdapterOption = mkAdapterType {
2025-01-23 20:11:11 -06:00
host = lib.nixvim.defaultNullOpts.mkStr "127.0.0.1" "Host to connect to.";
2025-01-23 20:11:11 -06:00
port = 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 = {
2025-01-23 20:11:11 -06:00
command = mkNullOrOption types.str "Command that spawns the adapter.";
2025-01-23 20:11:11 -06:00
args = mkNullOrOption (types.listOf types.str) "Command arguments.";
2025-01-23 20:11:11 -06:00
detached = lib.nixvim.defaultNullOpts.mkBool true "Spawn the debug adapter in detached state.";
2025-01-23 20:11:11 -06:00
cwd = mkNullOrOption types.str "Working directory.";
};
2025-01-23 20:11:11 -06:00
options.maxRetries = lib.nixvim.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:
2025-01-23 20:11:11 -06:00
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.
'';
configurationType = types.submodule {
freeformType = types.attrs;
options = {
2025-01-23 20:02:06 -06:00
type = lib.mkOption {
description = "Which debug adapter to use.";
type = types.str;
};
2025-01-23 20:02:06 -06:00
request = lib.mkOption {
type = types.enum [
"attach"
"launch"
];
description = ''
2024-03-07 19:44:13 +01:00
Indicates whether the debug adapter should launch a debuggee or attach to one that is already running.
'';
};
2025-01-23 20:02:06 -06:00
name = lib.mkOption {
type = types.str;
description = "A user readable name for the configuration.";
};
};
};
mkSignOption = default: desc: {
2025-01-23 20:11:11 -06:00
text = lib.nixvim.defaultNullOpts.mkStr default desc;
texthl = mkNullOrOption types.str "`texthl` for sign.";
linehl = mkNullOrOption types.str "`linehl` for sign.";
numhl = mkNullOrOption types.str "`numhl` for sign.";
};
processAdapters =
type: adapters:
2025-01-23 20:11:11 -06:00
lib.mapAttrs (
_: adapter:
2025-01-23 20:11:11 -06:00
if builtins.isString adapter then
lib.nixvim.mkRaw adapter
else
2025-01-23 20:11:11 -06:00
lib.filterAttrs (n: _: n != "enrichConfig") (
adapter
// {
inherit type;
enrich_config = adapter.enrichConfig;
}
)
) adapters;
}