Skip to content

Commit 3ef57f9

Browse files
committed
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://github.com/sindresorhus/untildify/releases/tag/v5.0.0
1 parent 350eaff commit 3ef57f9

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"@vscode/extension-telemetry": "0.8.2",
7878
"node-fetch": "2.6.12",
7979
"semver": "7.5.4",
80+
"untildify": "4.0.0",
8081
"uuid": "9.0.0",
8182
"vscode-languageclient": "8.1.0",
8283
"vscode-languageserver-protocol": "3.17.3"

src/platform.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import vscode = require("vscode");
88
import { integer } from "vscode-languageserver-protocol";
99
import { ILogger } from "./logging";
1010
import { changeSetting, getSettings, PowerShellAdditionalExePathSettings } from "./settings";
11+
import untildify from "untildify";
1112

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

241+
exePath = untildify(exePath);
242+
240243
// Always search for what the user gave us first
241244
yield new PossiblePowerShellExe(exePath, versionName);
242245

src/settings.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import vscode = require("vscode");
55
import utils = require("./utils");
66
import os = require("os");
77
import { ILogger } from "./logging";
8+
import untildify from "untildify";
89

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

223224
// Only use the cwd setting if it exists.
224-
if (cwd !== undefined && await utils.checkIfDirectoryExists(cwd)) {
225-
return cwd;
225+
if (cwd !== undefined) {
226+
cwd = untildify(cwd);
227+
if (await utils.checkIfDirectoryExists(cwd)) {
228+
return cwd;
229+
}
226230
}
227231

228232
// If there is no workspace, or there is but it has no folders, fallback.

test/core/platform.test.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ if (process.platform === "win32") {
451451

452452
additionalPowerShellExes = {
453453
"pwsh": "C:\\Users\\test\\pwsh\\pwsh.exe",
454+
"pwsh-tilde": "~\\pwsh\\pwsh.exe",
454455
"pwsh-no-exe": "C:\\Users\\test\\pwsh\\pwsh",
455456
"pwsh-folder": "C:\\Users\\test\\pwsh\\",
456457
"pwsh-folder-no-slash": "C:\\Users\\test\\pwsh",
@@ -466,15 +467,18 @@ if (process.platform === "win32") {
466467
isOS64Bit: true,
467468
isProcess64Bit: true,
468469
},
469-
environmentVars: {
470-
"USERPROFILE": "C:\\Users\\test",
471-
},
470+
environmentVars: {},
472471
expectedPowerShellSequence: [
473472
{
474473
exePath: "C:\\Users\\test\\pwsh\\pwsh.exe",
475474
displayName: "pwsh",
476475
supportsProperArguments: true
477476
},
477+
{
478+
exePath: path.join(os.homedir(), "pwsh", "pwsh.exe"),
479+
displayName: "pwsh-tilde",
480+
supportsProperArguments: true
481+
},
478482
{
479483
exePath: "C:\\Users\\test\\pwsh\\pwsh",
480484
displayName: "pwsh-no-exe",
@@ -747,6 +751,7 @@ if (process.platform === "win32") {
747751

748752
additionalPowerShellExes = {
749753
"pwsh": "/home/bin/pwsh",
754+
"pwsh-tilde": "~/bin/pwsh",
750755
"pwsh-folder": "/home/bin/",
751756
"pwsh-folder-no-slash": "/home/bin",
752757
"pwsh-single-quotes": "'/home/bin/pwsh'",
@@ -761,15 +766,18 @@ if (process.platform === "win32") {
761766
isOS64Bit: true,
762767
isProcess64Bit: true,
763768
},
764-
environmentVars: {
765-
"HOME": "/home/test",
766-
},
769+
environmentVars: {},
767770
expectedPowerShellSequence: [
768771
{
769772
exePath: "/home/bin/pwsh",
770773
displayName: "pwsh",
771774
supportsProperArguments: true
772775
},
776+
{
777+
exePath: path.join(os.homedir(), "bin", "pwsh"),
778+
displayName: "pwsh-tilde",
779+
supportsProperArguments: true
780+
},
773781
{
774782
exePath: "/home/bin/",
775783
displayName: "pwsh-folder",

0 commit comments

Comments
 (0)