From 6f494d1db9561e8bd188a082addf96c2bdffee02 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 13 Dec 2016 00:22:23 +0100 Subject: [PATCH] Cleanup --- README.md | 14 +++++++++++++- src/DefinitionResolver.php | 2 -- src/Index/AbstractAggregateIndex.php | 2 ++ src/Index/Index.php | 4 ---- src/Index/ProjectIndex.php | 6 ------ src/Index/ReadableIndex.php | 2 ++ src/LanguageServer.php | 27 ++++++++++++++++++++------- src/PhpDocument.php | 16 +++++++--------- src/Server/TextDocument.php | 11 +++++++++-- 9 files changed, 53 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index de9167b..b6afad8 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Non-Standard: An empty query will return _all_ symbols found in the workspace. 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: @@ -108,7 +112,7 @@ 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. +The language server is fully operational whilLe 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. @@ -131,6 +135,11 @@ Simply run 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 @@ -178,6 +187,9 @@ Clone the repository and run composer install to install dependencies. +Then parse the stubs with + + composer run-script parse-stubs Run the tests with diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 6682d81..a2f30e4 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -8,8 +8,6 @@ use PhpParser\PrettyPrinter\Standard as PrettyPrinter; use phpDocumentor\Reflection\{Types, Type, Fqsen, TypeResolver}; use LanguageServer\Protocol\SymbolInformation; use LanguageServer\Index\ReadableIndex; -use Sabre\Event\Promise; -use function Sabre\Event\coroutine; class DefinitionResolver { diff --git a/src/Index/AbstractAggregateIndex.php b/src/Index/AbstractAggregateIndex.php index 4da668c..f8934c6 100644 --- a/src/Index/AbstractAggregateIndex.php +++ b/src/Index/AbstractAggregateIndex.php @@ -3,6 +3,8 @@ declare(strict_types = 1); namespace LanguageServer\Index; +use LanguageServer\Definition; + abstract class AbstractAggregateIndex implements ReadableIndex { /** diff --git a/src/Index/Index.php b/src/Index/Index.php index 2a4ea4d..93630be 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -3,11 +3,7 @@ declare(strict_types = 1); namespace LanguageServer\Index; -use LanguageServer\Protocol\{SymbolInformation, TextDocumentIdentifier, ClientCapabilities}; use LanguageServer\Definition; -use phpDocumentor\Reflection\DocBlockFactory; -use Sabre\Event\Promise; -use function Sabre\Event\coroutine; /** * Represents the index of a project or dependency diff --git a/src/Index/ProjectIndex.php b/src/Index/ProjectIndex.php index 51fed85..8b42f8f 100644 --- a/src/Index/ProjectIndex.php +++ b/src/Index/ProjectIndex.php @@ -3,12 +3,6 @@ declare(strict_types = 1); namespace LanguageServer\Index; -use LanguageServer\Protocol\{SymbolInformation, TextDocumentIdentifier, ClientCapabilities}; -use phpDocumentor\Reflection\DocBlockFactory; -use LanguageServer\ContentRetriever\ContentRetriever; -use Sabre\Event\Promise; -use function Sabre\Event\coroutine; - /** * A project index manages the source and dependency indexes */ diff --git a/src/Index/ReadableIndex.php b/src/Index/ReadableIndex.php index 2a22ee3..40f4e40 100644 --- a/src/Index/ReadableIndex.php +++ b/src/Index/ReadableIndex.php @@ -3,6 +3,8 @@ declare(strict_types = 1); namespace LanguageServer\Index; +use LanguageServer\Definition; + /** * The ReadableIndex interface provides methods to lookup definitions and references */ diff --git a/src/LanguageServer.php b/src/LanguageServer.php index b9739d9..3fce1b0 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -42,19 +42,29 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher */ public $workspace; - public $telemetry; + /** + * @var Server\Window + */ public $window; + + public $telemetry; public $completionItem; public $codeLens; + /** + * @var ProtocolReader + */ private $protocolReader; - private $protocolWriter; - private $client; /** - * @var AggregateIndex + * @var ProtocolWriter */ - private $index; + private $protocolWriter; + + /** + * @var LanguageClient + */ + private $client; /** * @var FilesFinder @@ -64,8 +74,12 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher /** * @var ContentRetriever */ - private $contentRetrieverFinder; + private $contentRetriever; + /** + * @param PotocolReader $reader + * @param ProtocolWriter $writer + */ public function __construct(ProtocolReader $reader, ProtocolWriter $writer) { parent::__construct($this, '/'); @@ -232,7 +246,6 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher // Give LS to the chance to handle requests while indexing yield timeout(); - $path = Uri\parse($uri); $this->client->window->logMessage( MessageType::LOG, "Parsing file $i/$count: {$uri}" diff --git a/src/PhpDocument.php b/src/PhpDocument.php index 8b3f4fa..76009a9 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -10,16 +10,13 @@ use LanguageServer\NodeVisitor\{ DocBlockParser, DefinitionCollector, ColumnCalculator, - ReferencesCollector, - VariableReferencesCollector + ReferencesCollector }; use LanguageServer\Index\Index; use PhpParser\{Error, ErrorHandler, Node, NodeTraverser}; use PhpParser\NodeVisitor\NameResolver; use phpDocumentor\Reflection\DocBlockFactory; -use Sabre\Event\Promise; use Sabre\Uri; -use function Sabre\Event\coroutine; class PhpDocument { @@ -99,11 +96,12 @@ class PhpDocument private $diagnostics; /** - * @param string $uri The URI of the document - * @param string $content The content of the document - * @param Index $index The Index to register definitions and references to - * @param Parser $parser The PHPParser instance - * @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks + * @param string $uri The URI of the document + * @param string $content The content of the document + * @param Index $index The Index to register definitions and references to + * @param Parser $parser The PHPParser instance + * @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks + * @param DefinitionResolver $definitionResolver The DefinitionResolver to resolve definitions to symbols in the workspace */ public function __construct( string $uri, diff --git a/src/Server/TextDocument.php b/src/Server/TextDocument.php index 32f4449..32ec8e4 100644 --- a/src/Server/TextDocument.php +++ b/src/Server/TextDocument.php @@ -27,7 +27,6 @@ use LanguageServer\Protocol\{ use LanguageServer\Index\ReadableIndex; use Sabre\Event\Promise; use function Sabre\Event\coroutine; -use function LanguageServer\getReferenceNodesByNode; /** * Provides method handlers for all textDocument/* methods @@ -61,9 +60,17 @@ class TextDocument */ private $completionProvider; - private $openDocuments = []; + /** + * @var ReadableIndex + */ private $index; + /** + * @param PhpDocumentLoader $documentLoader + * @param DefinitionResolver $definitionResolver + * @param LanguageClient $client + * @param ReadableIndex $index + */ public function __construct( PhpDocumentLoader $documentLoader, DefinitionResolver $definitionResolver,