mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
zed-editor: options to generate debug.json
Add `mutableUserDebug` and `userDebug` options to generate `debug.json` file. The options are heavily inspired by `mutableUserTasks` and `userTasks` options implementation. Closes #8091
This commit is contained in:
parent
95d65dddae
commit
1f34c2c855
5 changed files with 285 additions and 0 deletions
|
|
@ -81,6 +81,15 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mutableUserDebug = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
example = false;
|
||||||
|
description = ''
|
||||||
|
Whether user debug configurations (debug.json) can be updated by zed.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
userSettings = mkOption {
|
userSettings = mkOption {
|
||||||
type = jsonFormat.type;
|
type = jsonFormat.type;
|
||||||
default = { };
|
default = { };
|
||||||
|
|
@ -140,6 +149,27 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
userDebug = mkOption {
|
||||||
|
type = jsonFormat.type;
|
||||||
|
default = [ ];
|
||||||
|
example = literalExpression ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label = "Go (Delve)";
|
||||||
|
adapter = "Delve";
|
||||||
|
program = "$ZED_FILE";
|
||||||
|
request = "launch";
|
||||||
|
mode = "debug";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Configuration written to Zed's {file}`debug.json`.
|
||||||
|
|
||||||
|
Global debug configurations for Zed's [Debugger](https://zed.dev/docs/debugger).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
extensions = mkOption {
|
extensions = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
|
@ -241,6 +271,14 @@ in
|
||||||
(jsonFormat.generate "zed-user-tasks" cfg.userTasks)
|
(jsonFormat.generate "zed-user-tasks" cfg.userTasks)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
(mkIf (cfg.mutableUserDebug && cfg.userDebug != [ ]) {
|
||||||
|
zedDebugActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||||
|
impureConfigMerger "[]"
|
||||||
|
"$dynamic + $static | group_by(.label) | map(reduce .[] as $item ({}; . * $item))"
|
||||||
|
"${config.xdg.configHome}/zed/debug.json"
|
||||||
|
(jsonFormat.generate "zed-user-debug" cfg.userDebug)
|
||||||
|
);
|
||||||
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
xdg.configFile = mkMerge [
|
xdg.configFile = mkMerge [
|
||||||
|
|
@ -265,6 +303,9 @@ in
|
||||||
(mkIf (!cfg.mutableUserTasks && cfg.userTasks != [ ]) {
|
(mkIf (!cfg.mutableUserTasks && cfg.userTasks != [ ]) {
|
||||||
"zed/tasks.json".source = jsonFormat.generate "zed-user-tasks" cfg.userTasks;
|
"zed/tasks.json".source = jsonFormat.generate "zed-user-tasks" cfg.userTasks;
|
||||||
})
|
})
|
||||||
|
(mkIf (!cfg.mutableUserDebug && cfg.userDebug != [ ]) {
|
||||||
|
"zed/debug.json".source = jsonFormat.generate "zed-user-debug" cfg.userDebug;
|
||||||
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
|
|
|
||||||
83
tests/modules/programs/zed-editor/debug-empty.nix
Normal file
83
tests/modules/programs/zed-editor/debug-empty.nix
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
programs.zed-editor = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage { };
|
||||||
|
userDebug = [
|
||||||
|
{
|
||||||
|
label = "PHP: Listen to Xdebug";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
port = 9003;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
label = "PHP: Debug this test";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
program = "vendor/bin/phpunit";
|
||||||
|
args = [
|
||||||
|
"--filter"
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
||||||
|
|
||||||
|
nmt.script =
|
||||||
|
let
|
||||||
|
preexistingDebug = builtins.toFile "preexisting.json" "";
|
||||||
|
|
||||||
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"args": [
|
||||||
|
"--filter",
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
],
|
||||||
|
"label": "PHP: Debug this test",
|
||||||
|
"program": "vendor/bin/phpunit",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"label": "PHP: Listen to Xdebug",
|
||||||
|
"port": 9003,
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
|
||||||
|
debugPath = ".config/zed/debug.json";
|
||||||
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedDebugActivation.data;
|
||||||
|
in
|
||||||
|
''
|
||||||
|
export HOME=$TMPDIR/hm-user
|
||||||
|
|
||||||
|
# Simulate preexisting debug
|
||||||
|
mkdir -p $HOME/.config/zed
|
||||||
|
cat ${preexistingDebug} > $HOME/${debugPath}
|
||||||
|
|
||||||
|
# Run the activation script
|
||||||
|
substitute ${activationScript} $TMPDIR/activate --subst-var TMPDIR
|
||||||
|
chmod +x $TMPDIR/activate
|
||||||
|
$TMPDIR/activate
|
||||||
|
|
||||||
|
# Validate the merged debug
|
||||||
|
assertFileExists "$HOME/${debugPath}"
|
||||||
|
assertFileContent "$HOME/${debugPath}" "${expectedContent}"
|
||||||
|
|
||||||
|
# Test idempotency
|
||||||
|
$TMPDIR/activate
|
||||||
|
assertFileExists "$HOME/${debugPath}"
|
||||||
|
assertFileContent "$HOME/${debugPath}" "${expectedContent}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
58
tests/modules/programs/zed-editor/debug-immutable.nix
Normal file
58
tests/modules/programs/zed-editor/debug-immutable.nix
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# Test custom keymap functionality
|
||||||
|
{ config, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
programs.zed-editor = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage { };
|
||||||
|
mutableUserDebug = false;
|
||||||
|
userDebug = [
|
||||||
|
{
|
||||||
|
label = "PHP: Listen to Xdebug";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
port = 9003;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
label = "PHP: Debug this test";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
program = "vendor/bin/phpunit";
|
||||||
|
args = [
|
||||||
|
"--filter"
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script =
|
||||||
|
let
|
||||||
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"label": "PHP: Listen to Xdebug",
|
||||||
|
"port": 9003,
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"args": [
|
||||||
|
"--filter",
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
],
|
||||||
|
"label": "PHP: Debug this test",
|
||||||
|
"program": "vendor/bin/phpunit",
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
|
||||||
|
settingsPath = ".config/zed/debug.json";
|
||||||
|
in
|
||||||
|
''
|
||||||
|
assertFileExists "home-files/${settingsPath}"
|
||||||
|
assertFileContent "home-files/${settingsPath}" "${expectedContent}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
100
tests/modules/programs/zed-editor/debug.nix
Normal file
100
tests/modules/programs/zed-editor/debug.nix
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
programs.zed-editor = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage { };
|
||||||
|
userDebug = [
|
||||||
|
{
|
||||||
|
label = "PHP: Listen to Xdebug";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
port = 9003;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
label = "PHP: Debug this test";
|
||||||
|
adapter = "Xdebug";
|
||||||
|
request = "launch";
|
||||||
|
program = "vendor/bin/phpunit";
|
||||||
|
args = [
|
||||||
|
"--filter"
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
||||||
|
|
||||||
|
nmt.script =
|
||||||
|
let
|
||||||
|
preexistingDebug = builtins.toFile "preexisting.json" ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"label": "Debug active Python file",
|
||||||
|
"adapter": "Debugpy",
|
||||||
|
"program": "$ZED_FILE",
|
||||||
|
"request": "launch",
|
||||||
|
"cwd": "$ZED_WORKTREE_ROOT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
|
||||||
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"label": "Debug active Python file",
|
||||||
|
"adapter": "Debugpy",
|
||||||
|
"program": "$ZED_FILE",
|
||||||
|
"request": "launch",
|
||||||
|
"cwd": "$ZED_WORKTREE_ROOT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"args": [
|
||||||
|
"--filter",
|
||||||
|
"$ZED_SYMBOL"
|
||||||
|
],
|
||||||
|
"label": "PHP: Debug this test",
|
||||||
|
"program": "vendor/bin/phpunit",
|
||||||
|
"request": "launch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"adapter": "Xdebug",
|
||||||
|
"label": "PHP: Listen to Xdebug",
|
||||||
|
"port": 9003,
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
|
||||||
|
debugPath = ".config/zed/debug.json";
|
||||||
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedDebugActivation.data;
|
||||||
|
in
|
||||||
|
''
|
||||||
|
export HOME=$TMPDIR/hm-user
|
||||||
|
|
||||||
|
# Simulate preexisting debug
|
||||||
|
mkdir -p $HOME/.config/zed
|
||||||
|
cat ${preexistingDebug} > $HOME/${debugPath}
|
||||||
|
|
||||||
|
# Run the activation script
|
||||||
|
substitute ${activationScript} $TMPDIR/activate --subst-var TMPDIR
|
||||||
|
chmod +x $TMPDIR/activate
|
||||||
|
$TMPDIR/activate
|
||||||
|
|
||||||
|
# Validate the merged debug
|
||||||
|
assertFileExists "$HOME/${debugPath}"
|
||||||
|
assertFileContent "$HOME/${debugPath}" "${expectedContent}"
|
||||||
|
|
||||||
|
# Test idempotency
|
||||||
|
$TMPDIR/activate
|
||||||
|
assertFileExists "$HOME/${debugPath}"
|
||||||
|
assertFileContent "$HOME/${debugPath}" "${expectedContent}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
@ -11,5 +11,8 @@
|
||||||
zed-tasks = ./tasks.nix;
|
zed-tasks = ./tasks.nix;
|
||||||
zed-tasks-immutable = ./tasks-immutable.nix;
|
zed-tasks-immutable = ./tasks-immutable.nix;
|
||||||
zed-tasks-empty = ./tasks-empty.nix;
|
zed-tasks-empty = ./tasks-empty.nix;
|
||||||
|
zed-debug = ./debug.nix;
|
||||||
|
zed-debug-immutable = ./debug-immutable.nix;
|
||||||
|
zed-debug-empty = ./debug-empty.nix;
|
||||||
zed-themes = ./themes;
|
zed-themes = ./themes;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue