diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 5f4400257..473cd1705 100644 --- a/modules/programs/vscode.nix +++ b/modules/programs/vscode.nix @@ -78,11 +78,19 @@ in { }; when = mkOption { - type = types.str; - default = ""; + type = types.nullOr (types.str); + default = null; example = "textInputFocus"; description = "Optional context filter."; }; + + # https://code.visualstudio.com/docs/getstarted/keybindings#_command-arguments + args = mkOption { + type = types.nullOr (types.attrs); + default = null; + example = { direction = "up"; }; + description = "Optional arguments for a command."; + }; }; }); default = [ ]; @@ -125,12 +133,14 @@ in { (k: _: { "${extensionPath}/${k}".source = "${path}/${subDir}/${k}"; }) (builtins.readDir (path + "/${subDir}")); toSymlink = concatMap toPaths cfg.extensions; + dropNullFields = filterAttrs (_: v: v != null); in foldr (a: b: a // b) { "${configFilePath}" = mkIf (cfg.userSettings != { }) { source = jsonFormat.generate "vscode-user-settings" cfg.userSettings; }; "${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) { - source = jsonFormat.generate "vscode-keybindings" cfg.keybindings; + source = jsonFormat.generate "vscode-keybindings" + (map dropNullFields cfg.keybindings); }; } toSymlink; }; diff --git a/tests/modules/programs/vscode/keybindings.nix b/tests/modules/programs/vscode/keybindings.nix index b03ec9a4e..57931c43f 100644 --- a/tests/modules/programs/vscode/keybindings.nix +++ b/tests/modules/programs/vscode/keybindings.nix @@ -20,6 +20,11 @@ let command = "deleteFile"; when = "explorerViewletVisible"; } + { + key = "ctrl+r"; + command = "run"; + args = { command = "echo file"; }; + } ]; targetPath = if pkgs.stdenv.hostPlatform.isDarwin then @@ -43,6 +48,13 @@ let "command": "deleteFile", "key": "d", "when": "explorerViewletVisible" + }, + { + "args": { + "command": "echo file" + }, + "command": "run", + "key": "ctrl+r" } ] ''; @@ -51,18 +63,9 @@ in { programs.vscode = { enable = true; keybindings = bindings; + package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; }; - nixpkgs.overlays = [ - (self: super: { - vscode = pkgs.runCommandLocal "vscode" { pname = "vscode"; } '' - mkdir -p $out/bin - touch $out/bin/code - chmod +x $out/bin/code; - ''; - }) - ]; - nmt.script = '' assertFileExists "home-files/${targetPath}" assertFileContent "home-files/${targetPath}" "${expectedJson}"