1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-22 21:50:55 +00:00

vscode-extensions: editorconfig fixes

This commit is contained in:
zowoq 2020-08-31 09:17:48 +10:00 committed by Jon
parent 5c67236602
commit 322f0bd565
5 changed files with 30 additions and 31 deletions

View file

@ -16,7 +16,7 @@ let
updateVSCodeSettingsCmd = '' updateVSCodeSettingsCmd = ''
( (
echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...' echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...'
oldSettings=$(cat ${vscodeSettingsFile}) oldSettings=$(cat ${vscodeSettingsFile})
echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile} echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile}
)''; )'';
@ -25,10 +25,10 @@ let
fileName = builtins.baseNameOf vscodeSettingsFile; fileName = builtins.baseNameOf vscodeSettingsFile;
symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting
'' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" ''; '' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
in in
writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}''
(lib.optionalString (settings != {}) (lib.optionalString (settings != {})
(if createIfDoesNotExists then '' (if createIfDoesNotExists then ''
[ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd} [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd}
${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}

View file

@ -21,13 +21,13 @@
, user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'' , user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir''
# if file exists will use it and import the extensions in it into this dervation else will use empty extensions list # if file exists will use it and import the extensions in it into this dervation else will use empty extensions list
# this file will be created/updated by vscodeExts2nix when vscode exists # this file will be created/updated by vscodeExts2nix when vscode exists
, mutableExtensionsFile , mutableExtensionsFile
}: }:
let let
mutableExtensionsFilePath = toString mutableExtensionsFile; mutableExtensionsFilePath = toString mutableExtensionsFile;
mutableExtensions = if builtins.pathExists mutableExtensionsFile mutableExtensions = if builtins.pathExists mutableExtensionsFile
then import mutableExtensionsFilePath else []; then import mutableExtensionsFilePath else [];
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
inherit lib writeShellScriptBin extensionsFromVscodeMarketplace; inherit lib writeShellScriptBin extensionsFromVscodeMarketplace;
vscodeDefault = vscode; vscodeDefault = vscode;
} }
@ -63,19 +63,19 @@ let
symlinkFromUserSetting = (user-data-dir != ""); symlinkFromUserSetting = (user-data-dir != "");
}; };
vscodeExts2nix = import ./vscodeExts2nix.nix { vscodeExts2nix = import ./vscodeExts2nix.nix {
inherit lib writeShellScriptBin; inherit lib writeShellScriptBin;
vscodeDefault = vscodeWithConfiguration; vscodeDefault = vscodeWithConfiguration;
} }
{ {
extensionsToIgnore = nixExtensions; extensionsToIgnore = nixExtensions;
extensions = mutableExtensions; extensions = mutableExtensions;
}; };
code = writeShellScriptBin "code" '' code = writeShellScriptBin "code" ''
${updateSettingsCmd}/bin/vscodeNixUpdate-settings ${updateSettingsCmd}/bin/vscodeNixUpdate-settings
${updateLaunchCmd}/bin/vscodeNixUpdate-launch ${updateLaunchCmd}/bin/vscodeNixUpdate-launch
${updateKeybindingsCmd}/bin/vscodeNixUpdate-keybindings ${updateKeybindingsCmd}/bin/vscodeNixUpdate-keybindings
${vscodeWithConfiguration}/bin/code --wait "$@" ${vscodeWithConfiguration}/bin/code --wait "$@"
echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...'
${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath} ${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath}
''; '';

View file

@ -1,5 +1,5 @@
with import <nixpkgs>{}; with import <nixpkgs>{};
callPackage (import ./vscodeEnv.nix) { callPackage (import ./vscodeEnv.nix) {
extensionsFromVscodeMarketplace = vscode-utils.extensionsFromVscodeMarketplace; extensionsFromVscodeMarketplace = vscode-utils.extensionsFromVscodeMarketplace;
vscodeDefault = vscode; vscodeDefault = vscode;
} { } {
@ -9,4 +9,3 @@ callPackage (import ./vscodeEnv.nix) {
t = "test"; t = "test";
}; };
} }

View file

@ -1,24 +1,24 @@
# based on the passed vscode will stdout a nix expression with the installed vscode extensions # based on the passed vscode will stdout a nix expression with the installed vscode extensions
{ lib { lib
, vscodeDefault , vscodeDefault
, writeShellScriptBin , writeShellScriptBin
}: }:
##User input ##User input
{ vscode ? vscodeDefault { vscode ? vscodeDefault
, extensionsToIgnore ? [] , extensionsToIgnore ? []
# will use those extensions to get sha256 if still exists when executed. # will use those extensions to get sha256 if still exists when executed.
, extensions ? [] , extensions ? []
}: }:
let let
mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix; mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix;
in in
writeShellScriptBin "vscodeExts2nix" '' writeShellScriptBin "vscodeExts2nix" ''
echo '[' echo '['
for line in $(${vscode}/bin/code --list-extensions --show-versions \ for line in $(${vscode}/bin/code --list-extensions --show-versions \
${lib.optionalString (extensionsToIgnore != []) '' ${lib.optionalString (extensionsToIgnore != []) ''
| grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : ''${e.publisher}.${e.name}'') extensionsToIgnore}\)' | grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : ''${e.publisher}.${e.name}'') extensionsToIgnore}\)'
''} ''}
) ; do ) ; do
[[ $line =~ ([^.]*)\.([^@]*)@(.*) ]] [[ $line =~ ([^.]*)\.([^@]*)@(.*) ]]

View file

@ -1,22 +1,22 @@
# wrapper over vscode to control extensions per project (extensions folder will be created in execution path) # wrapper over vscode to control extensions per project (extensions folder will be created in execution path)
{ lib { lib
, writeShellScriptBin , writeShellScriptBin
, extensionsFromVscodeMarketplace , extensionsFromVscodeMarketplace
, vscodeDefault , vscodeDefault
}: }:
## User input ## User input
{ vscode ? vscodeDefault { vscode ? vscodeDefault
# extensions to be symlinked into the project's extensions folder # extensions to be symlinked into the project's extensions folder
, nixExtensions ? [] , nixExtensions ? []
# extensions to be copied into the project's extensions folder # extensions to be copied into the project's extensions folder
, mutableExtensions ? [] , mutableExtensions ? []
, vscodeExtsFolderName ? ".vscode-exts" , vscodeExtsFolderName ? ".vscode-exts"
, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"'' , user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"''
}: }:
let let
nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions; nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions;
mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions; mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions;
mutableExtsPaths = lib.forEach mutExtsDrvs ( e: mutableExtsPaths = lib.forEach mutExtsDrvs ( e:
{ {
origin = ''${e}/share/vscode/extensions/${e.vscodeExtUniqueId}''; origin = ''${e}/share/vscode/extensions/${e.vscodeExtUniqueId}'';
target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: ''${ext.publisher}.${ext.name}'' == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version}''; target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: ''${ext.publisher}.${ext.name}'' == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version}'';
@ -39,16 +39,16 @@ let
cp -a ${ePath.origin} ${ePath.target} cp -a ${ePath.origin} ${ePath.target}
chmod -R u+rwx ${ePath.target} chmod -R u+rwx ${ePath.target}
fi fi
'') mutableExtsPaths} '') mutableExtsPaths}
''; '';
in in
writeShellScriptBin "code" '' writeShellScriptBin "code" ''
if ! [[ "$@" =~ "--list-extension" ]]; then if ! [[ "$@" =~ "--list-extension" ]]; then
mkdir -p "${vscodeExtsFolderName}" mkdir -p "${vscodeExtsFolderName}"
${rmExtensions} ${rmExtensions}
${cpExtensions} ${cpExtensions}
fi fi
${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${ ${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${
lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }'' lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }''
} "$@" } "$@"
'' ''