Skip to content

Commit

Permalink
add $relativeDir and $relativeFileDirname
Browse files Browse the repository at this point in the history
  • Loading branch information
xlbljz committed Sep 9, 2023
1 parent 51eb7b1 commit 7e61e11
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ export class CodeManager implements vscode.Disposable {
return undefined;
}
}
private asRelativePath(): string {
if (vscode.workspace.workspaceFolders) {
if (this._document) {
const RelativePath = vscode.workspace.asRelativePath(this._document.uri);
if (RelativePath) {
return RelativePath.uri.fsPath;
}
}
return vscode.workspace.RelativePath[0].uri.fsPath;
} else {
return undefined;
}
}


private getCodeFileAndExecute(fileExtension: string, executor: string, appendFile: boolean = true): any {
let selection;
Expand Down Expand Up @@ -378,6 +392,11 @@ export class CodeManager implements vscode.Disposable {
{ regex: /\$dir/g, replaceValue: this.quoteFileName(codeFileDir) },
// A placeholder that has to be replaced by the path of Python interpreter
{ regex: /\$pythonPath/g, replaceValue: pythonPath },
// A placeholder that has to be replaced by the relative path of the code file to the workspace folder
{ regex: /\$relativeDir/g, replaceValue: this.quoteFileName(this.asRelativePath(this._codeFile)) },
// A placeholder that has to be replaced by the relative path of the code file's dirname to the workspace folder
{ regex: /\$relativeFileDirname/g, replaceValue: this.quoteFileName(this.asRelativePath(codeFileDir)) },

];

placeholders.forEach((placeholder) => {
Expand Down

0 comments on commit 7e61e11

Please sign in to comment.