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

Default "phan.analyzedProjectDirectory" to project root #79

Open
9brada6 opened this issue Mar 15, 2020 · 4 comments · May be fixed by #83
Open

Default "phan.analyzedProjectDirectory" to project root #79

9brada6 opened this issue Mar 15, 2020 · 4 comments · May be fixed by #83

Comments

@9brada6
Copy link

9brada6 commented Mar 15, 2020

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
Copy link
Author

9brada6 commented Jun 16, 2020

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.

@odahcam
Copy link

odahcam commented Jun 26, 2021

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.

@9brada6
Copy link
Author

9brada6 commented Jun 26, 2021

I would do when I have time.

@far-blue
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants