Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more of the missing predefined variables #16260

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/platform/common/variables/systemVariables.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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.
*/
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;
Expand All @@ -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;
Expand All @@ -38,6 +41,10 @@ export class SystemVariables extends AbstractSystemVariables {
});
}

public get userHome(): string {
return getUserHomeDir().fsPath;
}

public get cwd(): string {
return this.workspaceFolder;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading