Next Next commit
Use untildify for ~ in cwd and additionalPowerShellExes
This makes them way less annoying. I'm ok taking a dependency on
untildify as it's a very simple package, and the Python extension for VS
Code also uses it. However, it must remain at v4.0.0, as the latest
version, v5.0.0, is pure ESM and therefore cannot be loaded by VS Code.

https://.com/sindresorhus/untildify/releases/tag/v5.0.0
  • Loading branch information
@andyleejordan
andyleejordan committedAug 8, 2023
commit abb5ef65f045265a4e223031198960f22eda1399
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,9 @@ updates:
- "esbuild"
- "eslint"
- "@typescript-eslint/*"
ignore:
- dependency-name: "untildify"
versions: ["5.x"]
- package-ecosystem: -actions
directory: "/"
schedule:
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import vscode = require("vscode");
import { integer } from "vscode-languageserver-protocol";
import { ILogger } from "./logging";
import { changeSetting, getSettings, PowerShellAdditionalExePathSettings } from "./settings";
import untildify from "untildify";

// This uses require so we can rewire it in unit tests!
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires
Expand DownExpand Up@@ -232,11 +233,13 @@ export class PowerShellExeFinder {
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
for (const versionName in this.additionalPowerShellExes) {
if (Object..hasOwnProperty.call(this.additionalPowerShellExes, versionName)) {
const exePath = utils.stripQuotePair(this.additionalPowerShellExes[versionName]);
let exePath = utils.stripQuotePair(this.additionalPowerShellExes[versionName]);
if (!exePath) {
continue;
}

exePath = untildify(exePath);

// Always search for what the user gave us first
yield new PossiblePowerShellExe(exePath, versionName);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import vscode = require("vscode");
import utils = require("./utils");
import os = require("os");
import { ILogger } from "./logging";
import untildify from "untildify";

// TODO: Quite a few of these settings are unused in the client and instead
// exist just for the server. Those settings do not need to be represented in
Expand DownExpand Up@@ -221,8 +222,11 @@ export async function validateCwdSetting(logger: ILogger): Promise<string> {
vscode.workspace.getConfiguration(utils.PowerShellLanguageId).get<string>("cwd"));

// Only use the cwd setting if it exists.
if (cwd !== undefined && await utils.checkIfDirectoryExists(cwd)) {
return cwd;
if (cwd !== undefined) {
cwd = untildify(cwd);
if (await utils.checkIfDirectoryExists(cwd)) {
return cwd;
}
}

// If there is no workspace, or there is but it has no folders, fallback.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -451,6 +451,7 @@ if (process.platform === "win32") {

additionalPowerShellExes = {
"pwsh": "C:\\Users\\test\\pwsh\\pwsh.exe",
"pwsh-tilde": "~\\pwsh\\pwsh.exe",
"pwsh-no-exe": "C:\\Users\\test\\pwsh\\pwsh",
"pwsh-folder": "C:\\Users\\test\\pwsh\\",
"pwsh-folder-no-slash": "C:\\Users\\test\\pwsh",
Expand All@@ -466,15 +467,18 @@ if (process.platform === "win32") {
isOS64Bit: true,
isProcess64Bit: true,
},
environmentVars: {
"USERPROFILE": "C:\\Users\\test",
},
environmentVars: {},
expectedPowerShellSequence: [
{
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
displayName: "pwsh",
supportsProperArguments: true
},
{
exePath: path.join(os.homedir(), "pwsh", "pwsh.exe"),
displayName: "pwsh-tilde",
supportsProperArguments: true
},
{
exePath: "C:\\Users\\test\\pwsh\\pwsh",
displayName: "pwsh-no-exe",
Expand DownExpand Up@@ -747,6 +751,7 @@ if (process.platform === "win32") {

additionalPowerShellExes = {
"pwsh": "/home/bin/pwsh",
"pwsh-tilde": "~/bin/pwsh",
"pwsh-folder": "/home/bin/",
"pwsh-folder-no-slash": "/home/bin",
"pwsh-single-quotes": "'/home/bin/pwsh'",
Expand All@@ -761,15 +766,18 @@ if (process.platform === "win32") {
isOS64Bit: true,
isProcess64Bit: true,
},
environmentVars: {
"HOME": "/home/test",
},
environmentVars: {},
expectedPowerShellSequence: [
{
exePath: "/home/bin/pwsh",
displayName: "pwsh",
supportsProperArguments: true
},
{
exePath: path.join(os.homedir(), "bin", "pwsh"),
displayName: "pwsh-tilde",
supportsProperArguments: true
},
{
exePath: "/home/bin/",
displayName: "pwsh-folder",
Expand Down