From 3aa8c2bc4a923bdef372df904fd9aa91d0f80b14 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 3 Dec 2024 12:47:48 +1100 Subject: [PATCH] Support more of the missing predefined variables --- .../common/variables/systemVariables.node.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/platform/common/variables/systemVariables.node.ts b/src/platform/common/variables/systemVariables.node.ts index d11fac6f3c2..94a741a61a7 100644 --- a/src/platform/common/variables/systemVariables.node.ts +++ b/src/platform/common/variables/systemVariables.node.ts @@ -6,6 +6,7 @@ import * as path from '../../vscode-path/path'; import { Uri, Range, workspace, window } from 'vscode'; import { AbstractSystemVariables } from './systemVariables'; +import { getUserHomeDir } from '../utils/platform.node'; /** * System variables for node.js. Node specific is necessary because of using the current process environment. @@ -13,6 +14,7 @@ import { AbstractSystemVariables } from './systemVariables'; export class SystemVariables extends AbstractSystemVariables { private _workspaceFolder: string; private _workspaceFolderName: string; + private _fileWorkspaceFolder: string; private _filePath: string | undefined; private _lineNumber: number | undefined; private _selectedText: string | undefined; @@ -23,6 +25,7 @@ export class SystemVariables extends AbstractSystemVariables { const workspaceFolder = file ? workspace.getWorkspaceFolder(file) : undefined; this._workspaceFolder = workspaceFolder ? workspaceFolder.uri.fsPath : rootFolder?.fsPath || __dirname; this._workspaceFolderName = path.basename(this._workspaceFolder); + this._fileWorkspaceFolder = this._workspaceFolder; this._filePath = file ? file.fsPath : undefined; if (window && window.activeTextEditor) { this._lineNumber = window.activeTextEditor.selection.anchor.line + 1; @@ -38,6 +41,10 @@ export class SystemVariables extends AbstractSystemVariables { }); } + public get userHome(): string { + return getUserHomeDir().fsPath; + } + public get cwd(): string { return this.workspaceFolder; } @@ -50,6 +57,10 @@ export class SystemVariables extends AbstractSystemVariables { return this._workspaceFolder; } + public get fileWorkspaceFolder(): string { + return this._fileWorkspaceFolder; + } + public get workspaceRootFolderName(): string { return this._workspaceFolderName; } @@ -82,6 +93,14 @@ export class SystemVariables extends AbstractSystemVariables { return this.file ? path.dirname(this.file) : undefined; } + public get fileDirnameBasename(): string | undefined { + return this.fileDirname ? path.basename(this.fileDirname) : undefined; + } + + public get pathSeparator(): string | undefined { + return path.sep; + } + public get fileExtname(): string | undefined { return this.file ? path.extname(this.file) : undefined; }