From f64c1e896eb31aa4319c9b5b9e8120212f2696eb Mon Sep 17 00:00:00 2001 From: 9brada6 <9brada6@users.noreply.github.com> Date: Sat, 18 Jul 2020 10:38:15 +0300 Subject: [PATCH] Added relative workspace setting. --- README.md | 4 ++++ src/extension.ts | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5835c56..e502cde 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ Add these entries to your VSCode config (Open the menu at File > Preferences > S // (including files to parse and analyze). // On windows, a project folder would be a path such as // "C:\\Users\\MyUser\\path\\to\\analyzed\\folder" + // + // Additionally ${workspaceFolder} can be used or prefixed to a path, as in + // launch.json or tasks.json: + // "phan.analyzedProjectDirectory": "${workspaceFolder}", "phan.analyzedProjectDirectory": "/path/to/folder/to/analyze", // Limit events sent to the language server to those within `phan.analyzedProjectDirectory` diff --git a/src/extension.ts b/src/extension.ts index 662e4df..b76c749 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -180,15 +180,30 @@ async function checkValidAnalyzedProjectDirectory(context: vscode.ExtensionConte return true; } -// Converts the directory to analyze to an array of directories, if necessary. +// Converts the directory to analyze to an array of directories if necessary, +// and replace ${workspaceFolder} with the root workspace vscode directory. function normalizeDirsToAnalyze(conf: string|string[]|undefined): string[] { if (!conf) { return []; } - if (conf instanceof Array) { + + if (!(conf instanceof Array)) { + conf = [conf]; + } + + if (!vscode.workspace.workspaceFolders) { return conf; } - return [conf]; + + if (typeof vscode.workspace.workspaceFolders[0].uri.fsPath !== 'string') { + return conf; + } + + for (let i = 0; i < conf.length; i++) { + conf[i] = conf[i].replace(/\$\{workspaceFolder\}/gi, vscode.workspace.workspaceFolders[0].uri.fsPath).replace(/\\/gi, '/'); + } + + return conf; } /**