A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Overview

PHP Language Server

Version Linux Build Status Windows Build status Coverage semantic-release Minimum PHP Version License Gitter

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Uses the great Tolerant PHP Parser, phpDocumentor's DocBlock reflection and an event loop for concurrency.

Table of Contents

Features

Completion

Completion search demo

Signature Help

Signature help demo

Go To Definition

Go To Definition demo

Find References

Find References demo

Hover

Hover class demo

Hover parameter demo

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.

Document Symbols

Document Symbols demo

Workspace Symbols

Workspace Symbols demo

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

Error reporting demo

PHP parse errors are reported as errors, parse errors of docblocks are reported as warnings. Errors/Warnings from the vendor directory are ignored.

Stubs for PHP built-ins

Completion, type resolval etc. will use the standard PHP library and common extensions.

What is considered a definition?

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.

What is considered a reference?

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
  • Reassigned variables
  • Nested access/calls on return values, properties, array access

Protocol Extensions

This language server implements the files protocol extension. If the client expresses support through ClientCapabilities.xfilesProvider and ClientCapabilities.xcontentProvider, the server will request files in the workspace and file contents through requests from the client and never access the file system directly. This allows the server to operate in an isolated environment like a container, on a remote workspace or any a different protocol than file://.

Performance

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.

Having XDebug enabled heavily impacts performance and can even crash the server if the max_nesting_level setting is too low.

Versioning

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.

Installation

The recommended installation method is through Composer. Simply run

composer require felixfbecker/language-server

and you will get the latest stable release and all dependencies.
Running composer update will update the server to the latest non-breaking version.

After installing the language server and its dependencies, you must parse the stubs for standard PHP symbols and save the index for fast initialization.

 composer run-script --working-dir=vendor/felixfbecker/language-server parse-stubs

Running

Start the language server with

php vendor/felixfbecker/language-server/bin/php-language-server.php

Command line arguments

--tcp=host:port (optional)

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

--tcp-server=host:port (optional)

Causes the server to use a tcp connection for communicating with the language client instead of using STDIN/STDOUT. The server will listen on the given address for a connection. If PCNTL is available, will fork a child process for every connection. If not, will only accept one connection and the connection cannot be reestablished once closed, spawn a new process instead.

Example:

php bin/php-language-server.php --tcp-server=127.0.0.1:12345

--memory-limit=integer (optional)

Sets memory limit for language server. Equivalent to memory-limit php.ini directive. The default is 4GB (which is way more than needed).

Example:

php bin/php-language-server.php --memory-limit=256M

Used by

Contributing

You need at least PHP 7.0 and Composer installed. Clone the repository and run

composer install

to install dependencies.

Run the tests with

composer test

Lint with

composer lint

The project parses PHPStorm's PHP stubs to get support for PHP builtins. It re-parses them as needed after Composer processes, but after some code changes (such as ones involving the index or parsing) you may have to explicitly re-parse them:

composer run-script parse-stubs

To debug with xDebug ensure that you have this set as an environment variable

PHPLS_ALLOW_XDEBUG=1

This tells the Language Server to not restart without XDebug if it detects that XDebug is enabled (XDebug has a high performance impact).

You might also like...
Find undefined and unused variables with the PHP Codesniffer static analysis tool.

PHP_CodeSniffer VariableAnalysis Plugin for PHP_CodeSniffer static analysis tool that adds analysis of problematic variable use. Warns if variables ar

Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

WooCommerce function and class declaration stubs for static analysis.

WooCommerce Stubs This package provides stub declarations for WooCommerce functions, classes and interfaces. These stubs can help plugin and theme dev

⚗️ Adds code analysis to Laravel improving developer productivity and code quality.
⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

⚗️ About Larastan Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Vik

An extension for PHPStan for adding analysis for PHP Language Extensions.

PHPStan PHP Language Extensions (currently in BETA) This is an extension for PHPStan for adding analysis for PHP Language Extensions. Language feature

A pure PHP implementation of the MessagePack serialization format / msgpack.org[PHP]

msgpack.php A pure PHP implementation of the MessagePack serialization format. Features Fully compliant with the latest MessagePack specification, inc

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab.

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab. This implementation conforms to the official Unleash standards and implement

An implementation of the Minecraft: Bedrock Edition protocol in PHP

BedrockProtocol An implementation of the Minecraft: Bedrock Edition protocol in PHP This library implements all of the packets in the Minecraft: Bedro

Static Web App to train Filipinos in using MS Word with the use of Filipino language
Static Web App to train Filipinos in using MS Word with the use of Filipino language

MS Word Filipino Isang static web application na layuning magturo ng paggamit ng MS Word sa wikang Filipino. Ito ay isang proyekto na bahagi ng panana

Comments
  • "type is missing before a type separator"

    When following the installation instructions, I get to the step:

    composer run-script --working-dir=vendor/felixfbecker/language-server parse-stub

    The command runs for a while and then ends, notifying of an exception:

    Parsing file:///home/mantis/opt/php-language-server/vendor/jetbrains/phpstorm-stubs/http/http.php
    
    Script LanguageServer\ComposerScripts::parseStubs handling the parse-stubs event terminated with an exception
    
    In TypeResolver.php line 203:
                                                 
      A type is missing before a type separator  
    
    
    
    
    opened by bobdobbs 1
  • more open source funding available from Gitpod

    more open source funding available from Gitpod

    👋 from Gitpod,

    Your open-source project was one of the competition entrants at DevX Conf and there are funds outstanding that can be claimed by the project steward. If you wish to divert the funds to a cause that helps improve diversity in open-source such as Outreachy then that's possible!

    Last year was the first year of the DevX Conference, and over USD $10,000 was raised and donated to unpaid volunteers and the maintainers of Open-source projects that underpin our digital infrastructure. This year, thanks to the support of the conference sponsors AtomicJar, CodeSee, JetBrains, slim.ai, Tailscale, WorkOS, okteto and swimm we are pleased to share that we raised more than twice the amount of last year, that is, $22,600 USD. Like last year, attendees voted on how to distribute profits from DevX Conf between Open-source tools maintained almost exclusively by unpaid volunteers.

    Sponsors

    For more information and a breakdown of how attendees voted to distribute this year’s funds see https://www.gitpod.io/blog/devxconf-2022-wrap

    opened by ghuntley 1
  • Plugin Not Starting? - Help me please

    Plugin Not Starting? - Help me please

    I have just installed PHP IntelliSense v2.3.14 on VSCodium (AppImage build) for Kubuntu 21.04 On the system $PATH is PHP 7.4.16

    When I load up a Symfony project or any other PHP project When I try and go to a definition I see a tooltip saying : No definition found When I go to Runtime Status I see Not yet activated.

    What am I not doing right?

    opened by nshiell 1
  • Requirements could not be resolved.

    Requirements could not be resolved.

    Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Conclusion: don't install felixfbecker/language-server v5.4.6 - Conclusion: don't install felixfbecker/language-server v5.4.5 - Conclusion: don't install felixfbecker/language-server v5.4.4 - Conclusion: don't install felixfbecker/language-server v5.4.3 - Conclusion: don't install felixfbecker/language-server v5.4.2 - Conclusion: don't install felixfbecker/language-server v5.4.1 - Conclusion: remove composer/xdebug-handler 2.0.1 - Installation request for felixfbecker/language-server ^5.4 -> satisfiable by felixfbecker/language-server[v5.4.0, v5.4.1, v5.4.2, v5.4.3, v5.4.4, v5.4.5, v5.4.6]. - Conclusion: don't install composer/xdebug-handler 2.0.1 - felixfbecker/language-server v5.4.0 requires composer/xdebug-handler ^1.0 -> satisfiable by composer/xdebug-handler[1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.x-dev]. - Can only install one of: composer/xdebug-handler[1.1.0, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.2.0, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.2.1, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.3.0, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.3.1, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.3.2, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.3.3, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.0, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.1, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.2, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.3, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.4, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.5, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.6, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.4.x-dev, 2.0.1]. - Can only install one of: composer/xdebug-handler[1.0.0, 2.0.1]. - Installation request for composer/xdebug-handler (locked at 2.0.1) -> satisfiable by composer/xdebug-handler[2.0.1].

    opened by andrewjwolf 0
Releases(v5.4.6)
Owner
Felix Becker
Felix Becker
The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

QOSSMIC GmbH 389 Nov 24, 2022
Attributes to define PHP language extensions (to be enforced by static analysis)

PHP Language Extensions (currently in BETA) This library provides attributes for extending the PHP language (e.g. adding package visibility). The inte

Dave Liddament 70 Dec 19, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
Docker image that provides static analysis tools for PHP

Static Analysis Tools for PHP Docker image providing static analysis tools for PHP. The list of available tools and the installer are actually managed

Jakub Zalas 1.1k Jan 1, 2023
TypeScript and Javascript language support for Atom-IDE

IDE-TypeScript package TypeScript and JavaScript language support for Atom-IDE, powered by the Theia TypeScript Language Server. Early access This pac

Atom 369 Dec 15, 2022
Perform static analysis of Drupal PHP code with phpstan-drupal.

Perform static analysis of Drupal PHP code with PHPStan and PHPStan-Drupal on Drupal using PHP 8. For example: docker run --rm \ -v $(pwd)/example01

Dcycle 0 Dec 10, 2021
Magento 2 Debug Helper Module for easy debugging with Xdebug and PHPStorm or any other IDE

Magento 2 Debug Helper Information and Usage Magento 2 Debug Helper Module usage with PHPStorm and Xdebug Installation To install the Magento 2 Debug

Dmitry Shkoliar 13 May 24, 2022
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Jan 5, 2023