TysonAndre / vscode-php-phan

Phan - PHP Static Analysis for VS Code
Other
24 stars 4 forks source link

Default "phan.analyzedProjectDirectory" to project root #79

Open 9brada6 opened 4 years ago

9brada6 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

I would do when I have time.

far-blue commented 1 year ago

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.