A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.
Uses the great PHP-Parser, phpDocumentor's DocBlock reflection and an event loop for concurrency.
A hover request returns a declaration line (marked with language php
) and the summary of the docblock.
For Parameters, it will return the @param
tag.
The query is matched case-insensitively against the fully qualified name of the symbol.
Non-Standard: An empty query will return all symbols found in the workspace.
Error reporting through Publish Diagnostics
PHP parse errors are reported as errors, parse errors of docblocks are reported as warnings.
Globally searchable definitions are:
- classes
- interfaces
- traits
- properties
- methods
- class constants
- constants with
const
keyword
Definitions resolved just-in-time when needed:
- variable assignments
- parameters
- closure
use
statements
Not supported yet:
- constants with
define()
Namespaces are not considerd a declaration by design because they only make up a part of the fully qualified name and don't map to one unique declaration.
Definitions/references/hover currently work for
- class instantiations
- static method calls
- class constant access
- static property access
- parameter type hints
- return type hints
- method calls, if the variable was assigned to a new object in the same scope
- property access, if the variable was assigned to a new object in the same scope
- variables
- parameters
- imported closure variables (
use
) use
statements for classes, constants and functions- class-like after
implements
/extends
- function calls
- constant access
instanceof
checks
They do not work yet for:
- Reassigned variables
- Nested access/calls on return values or properties
Upon initialization, the server will recursively scan the project directory for PHP files, parse them and add all definitions and references to an in-memory index. The time this takes depends on the project size. At the time of writing, this project contains 78 files + 1560 files in dependencies which take 97s to parse and consume 76 MB on a Surface Pro 3. The language server is fully operational while indexing and can respond to requests with the definitions already indexed. Follow-up requests will be almost instant because the index is kept in memory.
This project follows semver for the protocol communication and command line parameters, e.g. a major version increase of the LSP will result in a major version increase of the PHP LS. New features like request implementations will result in a new minor version. Everything else will be a patch release. All classes are considered internal and are not subject to semver.
You need at least PHP 7.0 and Composer installed. Clone the repository and run
composer install
to install dependencies.
Run the tests with
vendor/bin/phpunit
Lint with
vendor/bin/phpcs
Causes the server to use a tcp connection for communicating with the language client instead of using STDIN/STDOUT. The server will try to connect to the specified address. Strongly recommended on Windows because of blocking STDIO.
Example:
php bin/php-language-server.php --tcp=127.0.0.1:12345
Sets memory limit for language server. Equivalent to memory-limit php.ini directive. By default there is no memory limit.
Example:
php bin/php-language-server.php --memory-limit=256M