Skip to content

Commit

Permalink
Modified version of php language server, supporting Phan static analyzer
Browse files Browse the repository at this point in the history
This extension allows analyzing a single PHP project.
(Each project with a .phan/config.php requires a different Phan
server running in the background. It's simplest to implement support for
just one).
In the future, it may allow analyzing multiple projects.

- Require users to provide a single folder for a project to analyze.
  Unfortunately, the phan server will autostart right now, even if the
  file is outside of that project.
- With more work, it should be possible to set up multiple folders,
  but I'm not familiar with the VS code extension API.

Change config options, refactor the extension to check for Phan and its
dependencies.

- Support `phan.` as the config prefix for VS code.

Update README, LICENSE

Update documentation

Add composer.lock

Update documentation, add options, document option for syntax error tolerance

update .travis.yml
- Remove deploy section
- install php-ast
- Add travis build status
  • Loading branch information
TysonAndre-tmg authored and TysonAndre committed Oct 1, 2017
1 parent 211890f commit 3876a8c
Show file tree
Hide file tree
Showing 21 changed files with 1,180 additions and 2,320 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
out/
node_modules/
vendor/
composer.lock
typings/
.DS_Store
package-lock.json
21 changes: 10 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

php:
- '7.0'
- '7.1'

cache:
directories:
Expand All @@ -14,6 +14,8 @@ before_install:

install:
- npm install
- pecl install -f ast-0.1.5
- phpenv config-rm xdebug.ini
- composer install --prefer-dist

script:
Expand All @@ -25,13 +27,10 @@ before_deploy:
- ./node_modules/.bin/vsce package
- ./node_modules/.bin/vsce publish -p $VSCE_TOKEN

deploy:
provider: releases
skip_cleanup: true
api_key:
secure: Jxe2EeDH4+pd4e/GhwUz+CQo5W4K7qBjdXQce9v+hUJZzoZgcwfkxZny0EWM53YyC6W8/10OZlo06KB2ZyiS90vYk9h0Wy5qva4le0m+ekW6u2YNexUd22z+9n6eKr5T+wzx60TTSHNLIprGyJfWyK5Q1vJbOzX0eBartXvu4NgXFakrBgykbur+8NwHQuZSAsiAnjooSTrVV+IJruCNti1ZhkVbwyjMMOzMvXU7y7wx2KZ30p0UL0S0/DbPRtfKJeLrLhkUYSVaxcoNsExVJaWKWrWiu8GZ6WBL0uryhSptobxllrFWH93ox0IDw2WGJNKMronGdxbafle20ILLK/q/0HN0QRa0h8dcFEerLyMSLOxF/dgdVVvlqockCC4/fISreTjrFAd8o0RLL+BIgfvrTmSsHJ0dD1sOVVO2ZnMmYOia0Ehex1wBBO2PXE+yHQBqwVjIEqPx5cwdO94Js1RCFiMaJmAEMaF1+JceWobwCsIpGyhsq3202XtnbPxHyi5o1IcsQWeMDdo2GsNozJgCMf8IuWB+z5jKa6Vlz92TXmGEPUAzTERHyGKNMKN9oHw0WhUkgFVt4dn1wMLGnFjy+BSrlmBzg4UCYT1LD2HYCkhQPrOgHGLiCBiBENoRCXOr/01mZpu16ibpJxMf114udtwA2TThHrmnRgWNXms=
file: php-intellisense-*.vsix
file_glob: true
on:
repo: felixfbecker/vscode-php-intellisense
tags: true
# TODO: Re-introduce deploy section
branches:
only:
- master

notifications:
email: false
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
MIT License

vscode-php-phan
Copyright (c) 2017 Tyson Andre

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------------------------------------------

vscode-php-phan is based on the language server client for
https://github.com/felixfbecker/vscode-php-intellisense
which is also licensed under the MIT License

MIT License

Copyright (c) 2017 Felix Becker

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
116 changes: 85 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,114 @@
# PHP IntelliSense
# Phan for Visual Studio Code

[![Latest Release](https://vsmarketplacebadge.apphb.com/version-short/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Installs](https://vsmarketplacebadge.apphb.com/installs/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Rating](https://vsmarketplacebadge.apphb.com/rating-short/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Build Status](https://travis-ci.org/felixfbecker/vscode-php-intellisense.svg?branch=master)](https://travis-ci.org/felixfbecker/vscode-php-intellisense) [![Dependency Status](https://gemnasium.com/felixfbecker/vscode-php-intellisense.svg)](https://gemnasium.com/felixfbecker/vscode-php-intellisense) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg)](https://php.net/) [![Gitter](https://badges.gitter.im/felixfbecker/vscode-php-intellisense.svg)](https://gitter.im/felixfbecker/vscode-php-intellisense?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Build Status](https://travis-ci.org/TysonAndre/vscode-php-phan.svg?branch=master)](https://travis-ci.org/TysonAndre/vscode-php-phan) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/)

Advanced PHP IntelliSense for Visual Studio Code.
Based on [PHP IntelliSense](https://github.com/felixfbecker/vscode-php-intellisense)

**Note: This is just the VS Code extension that spawns the actual language server. The language server itself is implemented purely in PHP [in its own repository](https://github.com/felixfbecker/php-language-server), all features need to be implemented there and all issues should be reported there.**
This adds improved [static analysis from Phan](https://github.com/phan/phan#features) to Visual Studio Code.

**Supports Unix/Linux.** Doesn't support Windows due to the server having a dependency on the `pcntl` PHP module.

**Note: This is just the VS Code extension that spawns Phan. Phan is implemented purely in PHP [in its own repository](https://github.com/phan/phan), all features need to be implemented there and all issues should be reported there.**

## Installation

You need at least PHP 7 installed for the extension to work. You can either add it to your PATH or set the `php.executablePath` setting.
### Dependencies:

I recommend to disable VS Code's built-in PHP IntelliSense by setting `php.suggest.basic` to `false` to avoid duplicate suggestions.
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)
3. [The `php-ast` PECL extension](https://pecl.php.net/package/ast) must be installed and enabled.
4. Depends on using a checkout of Phan with https://github.com/phan/phan/pull/1144 installed

## Features

### Completion
![Completion search demo](images/completion.gif)
### Installing from source

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

### Workspace symbol search
![Workspace symbol search demo](images/workspaceSymbol.gif)
```bash
npm install
npm run build
node node_modules/.bin/vsce package
```

### Find all References
![Find References demo](images/references.png)
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](#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"]
}
```

### Go to Definition
![Go To Definition demo](images/definition.gif)
## Features

### Hover
![Hover class demo](images/hoverClass.png)
### Error Detection

![Hover parameter demo](images/hoverParam.png)
![Phan error detection demo](./images/error_detection.png)

### Find all symbols
![Find all symbols demo](images/documentSymbol.gif)
Phan's capabilities are summarized in [Phan's README](https://github.com/phan/phan#features)

### Format code
![Format code demo](images/formatDocument.gif)
### Error Tolerant Parsing

### Column-accurate error reporting
![Error reporting demo](images/publishDiagnostics.png)
![Phan error tolerant detection demo](./images/tolerant_parsing.png)

Optional, enabled by `phan.useFallbackParser`

## Todo
- Rename
- Signature help

## Contributing

Clone whole repository and in root directory execute:

```bash
composer install
composer install
npm install
npm run compile
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 language server, the easiest way is to replace the language server installation from composer in `vendor/felixfbecker/language-server` with a symlink to your local clone.
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.

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

cd /path/to/folder/
git clone [email protected]: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:

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

**For guidance on how to set up a Phan project, please see [phan/phan](https://github.com/phan/phan).**

## Source

**For guidance on how to work on the language server, please see the [language server repository](https://github.com/felixfbecker/php-language-server).**
[github.com/TysonAndre/vscode-php-phan](https://github.com/TysonAndre/vscode-php-phan)
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"felixfbecker/language-server": "^4.6.0"
},
"scripts": {
"parse-stubs": "LanguageServer\\ComposerScripts::parseStubs",
"post-update-cmd": "@parse-stubs",
"post-install-cmd": "@parse-stubs"
"phan/phan": "dev-master"
}
}
Loading

0 comments on commit 3876a8c

Please sign in to comment.