mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-16 05:51:10 +01:00
plugins/dap: allow lua for adapters
Support `mkRaw` for adapter definitions to support more flexible configuration.
This commit is contained in:
parent
a80557e142
commit
d5b2ba8f2a
3 changed files with 112 additions and 12 deletions
|
|
@ -98,7 +98,11 @@ rec {
|
||||||
|
|
||||||
mkAdapterOption =
|
mkAdapterOption =
|
||||||
name: type:
|
name: type:
|
||||||
mkNullOrOption (with types; attrsOf (either str type)) ''
|
let
|
||||||
|
# TODO: Added 2025-12-11 (26.05)
|
||||||
|
strToRawLua = lib.nixvim.deprecation.transitionType types.str lib.nixvim.mkRaw types.rawLua;
|
||||||
|
in
|
||||||
|
mkNullOrOption (with types; attrsOf (either strToRawLua type)) ''
|
||||||
Debug adapters of `${name}` type.
|
Debug adapters of `${name}` type.
|
||||||
The adapters can also be set to a function which takes three arguments:
|
The adapters can also be set to a function which takes three arguments:
|
||||||
|
|
||||||
|
|
@ -150,8 +154,8 @@ rec {
|
||||||
type: adapters:
|
type: adapters:
|
||||||
lib.mapAttrs (
|
lib.mapAttrs (
|
||||||
_: adapter:
|
_: adapter:
|
||||||
if builtins.isString adapter then
|
if lib.types.isRawType adapter then
|
||||||
lib.nixvim.mkRaw adapter
|
adapter
|
||||||
else
|
else
|
||||||
lib.filterAttrs (n: _: n != "enrichConfig") (
|
lib.filterAttrs (n: _: n != "enrichConfig") (
|
||||||
adapter
|
adapter
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,64 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
deprecateExtraOptions = true;
|
deprecateExtraOptions = true;
|
||||||
|
|
||||||
extraOptions = {
|
extraOptions = {
|
||||||
adapters = lib.nixvim.mkCompositeOption "Dap adapters." {
|
adapters = lib.nixvim.mkNullOrOption' {
|
||||||
executables = dapHelpers.mkAdapterOption "executable" dapHelpers.executableAdapterOption;
|
type = types.submodule {
|
||||||
servers = dapHelpers.mkAdapterOption "server" dapHelpers.serverAdapterOption;
|
freeformType = types.attrsOf types.rawLua;
|
||||||
pipes = dapHelpers.mkAdapterOption "pipe" dapHelpers.pipeAdapterOption;
|
options = {
|
||||||
|
executables = dapHelpers.mkAdapterOption "executable" dapHelpers.executableAdapterOption;
|
||||||
|
servers = dapHelpers.mkAdapterOption "server" dapHelpers.serverAdapterOption;
|
||||||
|
pipes = dapHelpers.mkAdapterOption "pipe" dapHelpers.pipeAdapterOption;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
description = ''
|
||||||
|
Debug Adapter Protocol adapters.
|
||||||
|
|
||||||
|
Adapters can be defined as dynamic functions or categorized structured configs.
|
||||||
|
See `Example` for usage patterns.
|
||||||
|
'';
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
{
|
||||||
|
# Dynamic adapter using raw lua function
|
||||||
|
# Useful when adapter type is determined at runtime
|
||||||
|
python.__raw = '''
|
||||||
|
function(cb, config)
|
||||||
|
if config.request == 'attach' then
|
||||||
|
local port = (config.connect or config).port
|
||||||
|
local host = (config.connect or config).host or '127.0.0.1'
|
||||||
|
cb({
|
||||||
|
type = 'server',
|
||||||
|
port = assert(port, '`connect.port` is required for a godot `attach` configuration'),
|
||||||
|
host = host,
|
||||||
|
options = {
|
||||||
|
source_filetype = 'gdscript',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
else
|
||||||
|
cb({
|
||||||
|
type = 'executable',
|
||||||
|
command = 'godot',
|
||||||
|
args = { '--path', config.project_path or vim.fn.getcwd(), '--remote-debug', '127.0.0.1:6006' },
|
||||||
|
options = {
|
||||||
|
source_filetype = 'gdscript',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
''';
|
||||||
|
|
||||||
|
# Categorized structured config for executable adapter
|
||||||
|
executables.python = {
|
||||||
|
command = "python";
|
||||||
|
args = [ "-m" "debugpy" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Categorized structured config for server adapter
|
||||||
|
servers.netcoredbg = {
|
||||||
|
port = 4711;
|
||||||
|
executable.command = "netcoredbg";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
configurations =
|
configurations =
|
||||||
|
|
@ -64,16 +118,22 @@ lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
options = {
|
options = {
|
||||||
inherit (cfg) configurations;
|
inherit (cfg) configurations;
|
||||||
|
|
||||||
adapters =
|
adapters = lib.mkMerge [
|
||||||
|
(lib.removeAttrs (cfg.adapters or { }) [
|
||||||
|
"executables"
|
||||||
|
"servers"
|
||||||
|
"pipes"
|
||||||
|
])
|
||||||
(lib.optionalAttrs (cfg.adapters.executables != null) (
|
(lib.optionalAttrs (cfg.adapters.executables != null) (
|
||||||
dapHelpers.processAdapters "executable" cfg.adapters.executables
|
dapHelpers.processAdapters "executable" cfg.adapters.executables
|
||||||
))
|
))
|
||||||
// (lib.optionalAttrs (cfg.adapters.servers != null) (
|
(lib.optionalAttrs (cfg.adapters.servers != null) (
|
||||||
dapHelpers.processAdapters "server" cfg.adapters.servers
|
dapHelpers.processAdapters "server" cfg.adapters.servers
|
||||||
))
|
))
|
||||||
// (lib.optionalAttrs (cfg.adapters.pipes != null) (
|
(lib.optionalAttrs (cfg.adapters.pipes != null) (
|
||||||
dapHelpers.processAdapters "pipe" cfg.adapters.pipes
|
dapHelpers.processAdapters "pipe" cfg.adapters.pipes
|
||||||
));
|
))
|
||||||
|
];
|
||||||
|
|
||||||
signs = with cfg.signs; {
|
signs = with cfg.signs; {
|
||||||
DapBreakpoint = dapBreakpoint;
|
DapBreakpoint = dapBreakpoint;
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,50 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
adapters = {
|
adapters = {
|
||||||
|
python.__raw = ''
|
||||||
|
function(cb, config)
|
||||||
|
if config.request == 'attach' then
|
||||||
|
local port = (config.connect or config).port
|
||||||
|
local host = (config.connect or config).host or '127.0.0.1'
|
||||||
|
cb({
|
||||||
|
type = 'server',
|
||||||
|
port = assert(port, '`connect.port` is required for a python `attach` configuration'),
|
||||||
|
host = host,
|
||||||
|
options = {
|
||||||
|
source_filetype = 'python',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
else
|
||||||
|
cb({
|
||||||
|
type = 'executable',
|
||||||
|
command = 'path/to/virtualenvs/debugpy/bin/python',
|
||||||
|
args = { '-m', 'debugpy.adapter' },
|
||||||
|
options = {
|
||||||
|
source_filetype = 'python',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
|
||||||
executables = {
|
executables = {
|
||||||
python = {
|
pythonStructured = {
|
||||||
command = ".virtualenvs/tools/bin/python";
|
command = ".virtualenvs/tools/bin/python";
|
||||||
args = [
|
args = [
|
||||||
"-m"
|
"-m"
|
||||||
"debugpy.adapter"
|
"debugpy.adapter"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
lldb.__raw = ''
|
||||||
|
function(on_config, config)
|
||||||
|
local command = config.lldbCommand or "lldb-vscode"
|
||||||
|
on_config({
|
||||||
|
type = "executable",
|
||||||
|
command = command,
|
||||||
|
name = "lldb",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
servers = {
|
servers = {
|
||||||
java = ''
|
java = ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue