vscode-php-phan icon indicating copy to clipboard operation
vscode-php-phan copied to clipboard

Default "phan.analyzedProjectDirectory" to project root

Open 9brada6 opened this issue 5 years ago • 4 comments

A nice improvement I find is to default the option "phan.analyzedProjectDirectory" to the main workspace root folder(or in case of a workspace with multi-folders environment search the first workspace folder that has .phan folder).

Another improvement is to make the path possibility to be relative to the main workspace root folder.

This improvement will help when the project is switched across, as a lot of times the .phan folder is placed anyway in the project root folder. Having always to change this is a pain, not too bad for me, but a lot for other people.

Thanks.

9brada6 avatar Mar 15 '20 13:03 9brada6

I saw that the version of phan on vscode was update, and here not(so I can;t create a pull request), however as there were a lot ppl wanting for a relative way to define phanAnalyzeDirectory, so now can be defined as ${workspaceFolder} to replace the workspace folder. This is by default how the settings works in vscode in launch.json or tasks.json or another extensions(like PHPUnit)

Ex:

		// New
		"phan.analyzedProjectDirectory": "${workspaceFolder}",

		// Old
		// Windows:
		// "phan.analyzedProjectDirectory": "W:/Projects/wp-plugin-twrp/wordpress/wp-content/plugins/tabs-with-recommended-posts/",
		// WSL:
		// "phan.analyzedProjectDirectory": "/mnt/w/Projects/wp-plugin-twrp/wordpress/wp-content/plugins/tabs-with-recommended-posts/",
		// Linux:
		//"phan.analyzedProjectDirectory": "/media/brada/Work/Projects/wp-plugin-twrp/wordpress/wp-content/plugins/tabs-with-recommended-posts/",

Function to replace:

// Converts the directory to analyze to an array of directories, if necessary.
function normalizeDirsToAnalyze(conf: string|string[]|undefined): string[] {
    if (!conf) {
        return [];
    }

    if (!(conf instanceof Array)) {
        conf = [conf];
    }

    if (!vscode.workspace.workspaceFolders) {
        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
}

Tested onWindows and WSL.

9brada6 avatar Jun 16 '20 18:06 9brada6

Could you make a PR for this? I would like this option to work like you described so I could use PHAN in my team.

odahcam avatar Jun 26 '21 12:06 odahcam

I would do when I have time.

9brada6 avatar Jun 26 '21 14:06 9brada6

It would be very useful to have this capability because I work on lots of different php codebases, often with multiple open at once. It's not possible for me to use the vscode phan plugin with a single absolute path to a single project in the settings.

far-blue avatar Nov 28 '22 11:11 far-blue