From d4202875831a2d1b9dd3002d89b8c794af9e5a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Sat, 30 Jan 2021 01:00:58 +0100 Subject: [PATCH] vscode: add `args` option to keybindings Also make `when` optional. --- modules/programs/vscode.nix | 16 ++++++++++--- tests/modules/programs/vscode/keybindings.nix | 23 +++++++++++-------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 5f440025..473cd170 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 b03ec9a4..57931c43 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}"