• Stars
    star
    1,126
  • Rank 41,328 (Top 0.9 %)
  • Language
    PHP
  • License
    ISC License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP Implementation of the VS Code Language Server Protocol 🆚↔🖥

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).

More Repositories

1

svg-screenshots

📸🧩 Browser extension to take scalable, semantic, accessible screenshots of websites in SVG format.
TypeScript
834
star
2

node-sql-template-strings

ES6 tagged template strings for prepared SQL statements 📋
JavaScript
588
star
3

vscode-php-intellisense

Advanced PHP IntelliSense for Visual Studio Code 🆚💬
TypeScript
397
star
4

dom-to-svg

Library to convert a given HTML DOM node into an accessible SVG "screenshot".
TypeScript
378
star
5

iterare

Array methods + ES6 Iterators = ❤️
TypeScript
284
star
6

cli-highlight

Syntax highlighting for your terminal 💻✨
TypeScript
282
star
7

php-advanced-json-rpc

A more advanced PHP implementation of the JSONRPC Protocol 📞❗
PHP
245
star
8

php-language-server-protocol

Protocol classes for the Language Server Protocol in PHP
PHP
216
star
9

semantic-release-docker

🐳 Set of semantic-release plugins to publish to DockerHub
JavaScript
76
star
10

sequelize-decorators

Sequelize + Decorators = ❤
TypeScript
76
star
11

PSKubectl

kubectl with the power of the object pipeline
C#
61
star
12

merkel

Handles your database migration crisis 🛄
TypeScript
42
star
13

link-preview-sidebar

Browser extension to open links in a sidebar instead of a new tab.
TypeScript
39
star
14

PowerGit

Git with the power of the PowerShell object pipeline. For macOS, Linux and Windows.
PowerShell
31
star
15

vscode-php-pack

Visual Studio Code extension pack for PHP 📦
17
star
16

vscode-css-stacking-contexts

VS Code extension to highlight stacking contexts in CSS and ineffective z-index declarations 💤
TypeScript
17
star
17

abortable-rx

Drop-in replacements for RxJS Observable methods and operators that work with AbortSignal
TypeScript
13
star
18

semantic-release-firefox

🦊📦🚀 semantic-release plugin to automatically release Firefox extensions
HTML
10
star
19

angular-async-filter

Angular2's async pipe for Angular 1. Promise in controller, value in view.
JavaScript
6
star
20

aggregate-map

Read-only ES6 Map implementation that aggregates results from multiple Maps in O(n)
TypeScript
4
star
21

PowerShellXSD

XML schema definitions for PowerShell Format and Types.ps1xml files. NOTE: MOVED TO THE OFFICIAL POWERSHELL REPO
PowerShell
4
star
22

PSDefaults

Manage macOS preferences from PowerShell
PowerShell
4
star
23

PSBuildkite

Module to interact with the Buildkite API from PowerShell
PowerShell
3
star
24

rx-component

Functional, Reactive React Components
TypeScript
3
star
25

PSTravis

Interact with the Travis API from PowerShell
PowerShell
2
star
26

iterare-php

Functional utilities for Iterators
PHP
2
star
27

npm-changing-lockfile-repro

Minimal reproduction case for https://npm.community/t/package-lock-json-keeps-changing-between-platforms-and-runs/1129/4
2
star
28

vscode-postgresql-syntax

Better syntax highlighting for PostgreSQL in VSCode
2
star
29

lint-blame

Blames your lint complaints to enable incremental adoption of new lint rules
TypeScript
2
star
30

whatwg-url-custom-host-repro

Website to show inconsistent behavior of the WHATWG URL API in different browsers when parsing custom protocols
HTML
2
star
31

olfaction

Storage server for code smell analysis data
TypeScript
1
star
32

node-date-only

DONT USE THIS ATM, WILL SEE v2 SOON
JavaScript
1
star
33

rxx

Reactive JSX
TypeScript
1
star
34

stringscore

String scoring algorithm used by VS Code ported to Go
Go
1
star
35

lspindex

CLI tool to build a symbol graph by querying a language server
TypeScript
1
star
36

php-semantic-release-test

PHP
1
star
37

sourcegraph-css-stacking-contexts

Sourcegraph extension to highlight CSS declarations that introduce new stacking contexts.
TypeScript
1
star
38

react-resizable-css-grid

TypeScript
1
star
39

PSCodeCovIo

Helper to use in CI to convert test coverage data emitted by https://github.com/pester/Pester to JSON that can be uploaded to https://codecov.io
PowerShell
1
star