Skip to content
Generic Language Server
Branch: master
Clone or download
dantleech Merge pull request #9 from muglug/patch-1
Fix typo preventing promise end
Latest commit 1c4d59f Jan 19, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin updated README Jan 5, 2019
lib Fix typo Jan 18, 2019
.gitignore tests reader Sep 23, 2018
.php_cs.dist adds missing docblocks Dec 29, 2018
.travis.yml do not phpstan tests Sep 16, 2018 added changelog Jan 5, 2019
LICENSE initial Sep 15, 2018 updated README Jan 5, 2019
composer.json removed unnecessary dependencies Jan 4, 2019
phpstan.neon futher refactoring... Jan 3, 2019
phpunit.xml.dist added method documentation to builder Jan 4, 2019

Phpactor Language Server

Build Status

This package provides a language server platform:

  • Language server platform upon which you can implement language server features.
  • Can run as either a TCP server (accepting many connections) or a STDIO server (invoked by the client).
  • Can handle multiple sessions.
  • Can manage text document synchronization.

See the Language Server Specification for a list of methods which you can implement with this package.


Create a dumb language server which can respond to the initialize command and nothing more:

$server = LanguageServerBuilder::create()


Add TextDocument Handling

We provide a handler for text document synchronization:

$server = LanguageServerBuilder::create()
    ->addSystemHandler(new TextDocumentHandler(new Workspace()));


The text document handler will keep track of the files the client is managing. The workspace will contain these files, and can be used by other handlers.

Creating Custom Handlers

Handlers simply declare a map of Language Server RPC metods to instance methods:

class MyCompletionHandler implements Handler
    public function methods(): array
        return [
            'textDocument/completion' => 'completion',

    public function completion(): Generator
         $list = new CompletionList();
         $list->items[] = new CompletionItem('hello');
         $list->items[] = new CompletionItem('goodbye');

         yield $list;

Create Per-Session Handlers

Above we created a global text document handler, which isn't great as it means multiple clients share the same workspace.

You can use HandlerLoader implementations to lazily create handlers each time a client connects to the server. It is passed the initialization parmeters supplied by the client (which includes the root path of the clients project):

class MyHandlerLoader
    public function load(InitializeParams $params): Handlers
        $workspace = new Workspace();

        return new Handlers([
            new MyHandler($workspace)
            new MyOtherHandler($workspace)
You can’t perform that action at this time.