Skip to content

TysonAndre/vscode-php-phan

Repository files navigation

PHP Phan (Analyzer)

Latest Release Installs Rating Build Status Minimum PHP Version

Supports Unix/Linux.

Features

  • Adds improved error detection from Phan to Visual Studio Code.
  • Analyze code while you're typing.
  • Optionally analyze code with syntax errors.

Issue Tracker

Note: This is just the VS Code extension that spawns Phan. Phan is implemented purely in PHP in its own repository, bugs in Phan analysis need to be implemented there and all issues should be reported there.

However, bugs in this VS code extension (crashes, etc) or related to the language server protocol should be reported in this extension's issue tracker

Installation

Dependencies:

  1. PHP 7.1+ must be installed. You can either add it to your PATH or set the phan.executablePath setting.

  2. Your Operating System must be Unix/Linux (Phan support depends on pcntl module being installed, which is only available on those platforms)

    A future release may support Windows, but it won't be as fast.

  3. The php-ast PECL extension must be installed and enabled.

  4. Depends on using a checkout of Phan with phan/phan#1144 installed

Installing from source

This extension hasn't been published yet. It can be installed locally with the following method:

npm install
npm run build
node node_modules/.bin/vsce package

The generated VSIX file can be used locally with the steps from https://stackoverflow.com/a/38866913

Setup steps

This assumes you have already installed the dependencies.

Add these entries to your VSCode config (Open the menu at File > Preferences > Settings)

{
    // Currently, this extension is limited to analyzing only a single folder.
    // The config value must be the root of the project,
    // and contain a .phan/config.php file with a Phan config for that project
    // (including files to parse and analyze).
    "phan.analyzedProjectDirectory": "/path/to/folder/to/analyze",

    // Path to a php 7.1 binary with the php-ast PECL extension installed and enabled
    "phan.phpExecutablePath": "/path/to/php7.1",

    // Files which this should analyze
    "phan.analyzedFileExtensions": ["php"]
}

After adding these entries, close and re-open Visual Studio Code in order for Phan to pick up the new settings.

Examples

Error Detection

Phan error detection demo

Phan's capabilities are summarized in Phan's README

Error Detection (Tolerating Syntax Errors)

Phan error tolerant detection demo

Optional, enabled by the setting phan.useFallbackParser

Contributing

Clone whole repository and in root directory execute:

composer install
npm install
npm run build
code .

The last command will open the folder in VS Code. Hit F5 to launch an Extension Development Host with the extension. For working on the Phan language server, the easiest way is to override your config for the Phan language server installation from composer to point to the phan script within a git checkout of phan (Must set it up with composer install inside that checkout.).

First, checkout and setup a phan installation.

# Replace the placeholders /path/to/folder and phan_git_checkout with the folders you plan to use.

cd /path/to/folder/
git clone git@github.com:phan/phan phan_git_checkout
# Optionally, check out the branch being developed
# git checkout master
cd /path/to/folder/phan_git_checkout
composer install

And then point to that phan installation:

{
    "phan.phanScriptPath": "/path/to/folder/phan_git_checkout/phan"
}

For guidance on how to set up a Phan project, please see phan/phan.

Release History

0.0.4

  • Bump Phan version in composer.lock. Support new Phan plugin types. Include History in README.md

0.0.3

  • Improve documentation. Mention that Visual Studio Code must be restarted in order to pick up any changes to this editor's phan settings.

0.0.2

  • Reword README, rename extension to php-phan

Credits

This VS Code extension and many parts of the language server protocol implementation are based on PHP IntelliSense

This uses Phan

About

Phan - PHP Static Analysis for VS Code

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 8