vscode: add profiles support (#5640)
Adds support for VSCode Profiles configuration. Allowing you to define custom extensions and settings per profile.
This commit is contained in:
parent
4949081d1e
commit
e860bd49ea
6 changed files with 337 additions and 144 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# Test that keybindings.json is created correctly.
|
||||
{ pkgs, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
bindings = [
|
||||
|
|
@ -25,15 +25,25 @@ let
|
|||
}
|
||||
];
|
||||
|
||||
keybindingsPath = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/keybindings.json"
|
||||
else
|
||||
".config/Code/User/keybindings.json";
|
||||
keybindingsPath = name:
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}keybindings.json"
|
||||
else
|
||||
".config/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}keybindings.json";
|
||||
|
||||
settingsPath = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/settings.json"
|
||||
else
|
||||
".config/Code/User/settings.json";
|
||||
settingsPath = name:
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}settings.json"
|
||||
else
|
||||
".config/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}settings.json";
|
||||
|
||||
expectedKeybindings = pkgs.writeText "expected.json" ''
|
||||
[
|
||||
|
|
@ -65,14 +75,29 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
keybindings = bindings;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
profiles = {
|
||||
default.keybindings = bindings;
|
||||
test.keybindings = bindings;
|
||||
};
|
||||
package = pkgs.writeScriptBin "vscode" "" // {
|
||||
pname = "vscode";
|
||||
version = "1.75.0";
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists "home-files/${keybindingsPath}"
|
||||
assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}"
|
||||
assertFileExists "home-files/${keybindingsPath "default"}"
|
||||
assertFileContent "home-files/${
|
||||
keybindingsPath "default"
|
||||
}" "${expectedKeybindings}"
|
||||
|
||||
assertPathNotExists "home-files/${settingsPath}"
|
||||
assertPathNotExists "home-files/${settingsPath "default"}"
|
||||
|
||||
assertFileExists "home-files/${keybindingsPath "test"}"
|
||||
assertFileContent "home-files/${
|
||||
keybindingsPath "test"
|
||||
}" "${expectedKeybindings}"
|
||||
|
||||
assertPathNotExists "home-files/${settingsPath "test"}"
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
{ pkgs, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
|
||||
snippetsDir = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/snippets"
|
||||
else
|
||||
".config/Code/User/snippets";
|
||||
snippetsDir = name:
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}/snippets"
|
||||
else
|
||||
".config/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}snippets";
|
||||
|
||||
globalSnippetsPath = "${snippetsDir}/global.code-snippets";
|
||||
globalSnippetsPath = name: "${snippetsDir name}/global.code-snippets";
|
||||
|
||||
globalSnippetsExpectedContent = pkgs.writeText "global.code-snippet" ''
|
||||
{
|
||||
|
|
@ -23,7 +28,7 @@ let
|
|||
}
|
||||
'';
|
||||
|
||||
haskellSnippetsPath = "${snippetsDir}/haskell.json";
|
||||
haskellSnippetsPath = name: "${snippetsDir name}/haskell.json";
|
||||
|
||||
haskellSnippetsExpectedContent = pkgs.writeText "haskell.json" ''
|
||||
{
|
||||
|
|
@ -39,10 +44,7 @@ let
|
|||
}
|
||||
'';
|
||||
|
||||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
snippets = {
|
||||
globalSnippets = {
|
||||
fixme = {
|
||||
prefix = [ "fixme" ];
|
||||
|
|
@ -61,11 +63,38 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists "home-files/${globalSnippetsPath}"
|
||||
assertFileContent "home-files/${globalSnippetsPath}" "${globalSnippetsExpectedContent}"
|
||||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // {
|
||||
pname = "vscode";
|
||||
version = "1.75.0";
|
||||
};
|
||||
profiles = {
|
||||
default = snippets;
|
||||
test = snippets;
|
||||
};
|
||||
};
|
||||
|
||||
assertFileExists "home-files/${haskellSnippetsPath}"
|
||||
assertFileContent "home-files/${haskellSnippetsPath}" "${haskellSnippetsExpectedContent}"
|
||||
nmt.script = ''
|
||||
assertFileExists "home-files/${globalSnippetsPath "default"}"
|
||||
assertFileContent "home-files/${
|
||||
globalSnippetsPath "default"
|
||||
}" "${globalSnippetsExpectedContent}"
|
||||
|
||||
assertFileExists "home-files/${globalSnippetsPath "test"}"
|
||||
assertFileContent "home-files/${
|
||||
globalSnippetsPath "test"
|
||||
}" "${globalSnippetsExpectedContent}"
|
||||
|
||||
assertFileExists "home-files/${haskellSnippetsPath "default"}"
|
||||
assertFileContent "home-files/${
|
||||
haskellSnippetsPath "default"
|
||||
}" "${haskellSnippetsExpectedContent}"
|
||||
|
||||
assertFileExists "home-files/${haskellSnippetsPath "test"}"
|
||||
assertFileContent "home-files/${
|
||||
haskellSnippetsPath "test"
|
||||
}" "${haskellSnippetsExpectedContent}"
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
{ pkgs, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
|
||||
tasksFilePath = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/tasks.json"
|
||||
else
|
||||
".config/Code/User/tasks.json";
|
||||
tasksFilePath = name:
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}tasks.json"
|
||||
else
|
||||
".config/Code/User/${
|
||||
lib.optionalString (name != "default") "profiles/${name}/"
|
||||
}tasks.json";
|
||||
|
||||
tasks = {
|
||||
version = "2.0.0";
|
||||
|
|
@ -32,12 +37,21 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
userTasks = tasks;
|
||||
package = pkgs.writeScriptBin "vscode" "" // {
|
||||
pname = "vscode";
|
||||
version = "1.75.0";
|
||||
};
|
||||
profiles = {
|
||||
default.userTasks = tasks;
|
||||
test.userTasks = tasks;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists "home-files/${tasksFilePath}"
|
||||
assertFileContent "home-files/${tasksFilePath}" "${expectedTasks}"
|
||||
assertFileExists "home-files/${tasksFilePath "default"}"
|
||||
assertFileContent "home-files/${tasksFilePath "default"}" "${expectedTasks}"
|
||||
|
||||
assertFileExists "home-files/${tasksFilePath "test"}"
|
||||
assertFileContent "home-files/${tasksFilePath "test"}" "${expectedTasks}"
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
enableUpdateCheck = false;
|
||||
enableExtensionUpdateCheck = false;
|
||||
package = pkgs.writeScriptBin "vscode" "" // {
|
||||
pname = "vscode";
|
||||
version = "1.75.0";
|
||||
};
|
||||
profiles.default = {
|
||||
enableUpdateCheck = false;
|
||||
enableExtensionUpdateCheck = false;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue