Skip to content

Added relative workspace setting. #89

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
21 changes: 18 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map to be easier to test (not modify original input) but otherwise seems reasonable.

Now that vs code supports marking folders as trusted outside of extensions there's less of a need to manually list workplaces to trust.

conf[i] = conf[i].replace(/\$\{workspaceFolder\}/gi, vscode.workspace.workspaceFolders[0].uri.fsPath).replace(/\\/gi, '/');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could deduplicate if strings are exactly the same if workspaceFolder is the same directory as a hardcoded path

(e.g. convert to Set and back, or https://lodash.com/docs#uniq, or manually)


return conf;
}

/**
Expand Down