From db6f4f7e5d63435fca018592c9346e466c1ec14b Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 7 Dec 2016 21:17:55 +0100 Subject: [PATCH 1/3] Don't filter properties on typed prefix (#207) --- src/CompletionProvider.php | 43 ++++++++------------ tests/Server/TextDocument/CompletionTest.php | 32 ++++++++++++++- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index 261bc1d..5d65ea3 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -4,12 +4,10 @@ declare(strict_types = 1); namespace LanguageServer; use PhpParser\Node; -use phpDocumentor\Reflection\Types; use LanguageServer\Protocol\{ TextEdit, Range, Position, - SymbolKind, CompletionList, CompletionItem, CompletionItemKind @@ -134,30 +132,25 @@ class CompletionProvider || $node instanceof Node\Expr\StaticPropertyFetch || $node instanceof Node\Expr\ClassConstFetch ) { - if (!is_string($node->name)) { - // If the name is an Error node, just filter by the class - if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { - // For instances, resolve the variable type - $prefixes = DefinitionResolver::getFqnsFromType( - $this->definitionResolver->resolveExpressionNodeToType($node->var) - ); - } else { - $prefixes = [$node->class instanceof Node\Name ? (string)$node->class : '']; - } - // If we are just filtering by the class, add the appropiate operator to the prefix - // to filter the type of symbol - foreach ($prefixes as &$prefix) { - if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { - $prefix .= '->'; - } else if ($node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\ClassConstFetch) { - $prefix .= '::'; - } else if ($node instanceof Node\Expr\StaticPropertyFetch) { - $prefix .= '::$'; - } - } + // If the name is an Error node, just filter by the class + if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { + // For instances, resolve the variable type + $prefixes = DefinitionResolver::getFqnsFromType( + $this->definitionResolver->resolveExpressionNodeToType($node->var) + ); } else { - $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node); - $prefixes = $fqn !== null ? [$fqn] : []; + $prefixes = [$node->class instanceof Node\Name ? (string)$node->class : '']; + } + // If we are just filtering by the class, add the appropiate operator to the prefix + // to filter the type of symbol + foreach ($prefixes as &$prefix) { + if ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\PropertyFetch) { + $prefix .= '->'; + } else if ($node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\ClassConstFetch) { + $prefix .= '::'; + } else if ($node instanceof Node\Expr\StaticPropertyFetch) { + $prefix .= '::$'; + } } foreach ($this->project->getDefinitions() as $fqn => $def) { diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index 7b5dd0a..f32503c 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -254,10 +254,25 @@ class CompletionTest extends TestCase new Position(2, 13) )->wait(); $this->assertEquals(new CompletionList([ + new CompletionItem( + 'TEST_CLASS_CONST', + CompletionItemKind::VARIABLE, + 'int', + 'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.' + ), + new CompletionItem( + 'staticTestProperty', + CompletionItemKind::PROPERTY, + '\TestClass[]', + 'Lorem excepteur officia sit anim velit veniam enim.', + null, + null, + '$staticTestProperty' + ), new CompletionItem( 'staticTestMethod', CompletionItemKind::METHOD, - 'mixed', // Method return type + 'mixed', 'Do magna consequat veniam minim proident eiusmod incididunt aute proident.' ) ], true), $items); @@ -277,6 +292,21 @@ class CompletionTest extends TestCase CompletionItemKind::VARIABLE, 'int', 'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.' + ), + new CompletionItem( + 'staticTestProperty', + CompletionItemKind::PROPERTY, + '\TestClass[]', + 'Lorem excepteur officia sit anim velit veniam enim.', + null, + null, + '$staticTestProperty' + ), + new CompletionItem( + 'staticTestMethod', + CompletionItemKind::METHOD, + 'mixed', + 'Do magna consequat veniam minim proident eiusmod incididunt aute proident.' ) ], true), $items); } From ebd1cc613304cc35fd6896320d196064eca6d40d Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Thu, 8 Dec 2016 01:51:32 +0100 Subject: [PATCH 2/3] Refactor content retrieval (#208) --- .../ClientContentRetriever.php | 36 +++++++++++++++++++ src/ContentRetriever/ContentRetriever.php | 20 +++++++++++ .../FileSystemContentRetriever.php | 24 +++++++++++++ src/Project.php | 30 +++++++++------- 4 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 src/ContentRetriever/ClientContentRetriever.php create mode 100644 src/ContentRetriever/ContentRetriever.php create mode 100644 src/ContentRetriever/FileSystemContentRetriever.php diff --git a/src/ContentRetriever/ClientContentRetriever.php b/src/ContentRetriever/ClientContentRetriever.php new file mode 100644 index 0000000..b88042c --- /dev/null +++ b/src/ContentRetriever/ClientContentRetriever.php @@ -0,0 +1,36 @@ +client = $client; + } + + /** + * Retrieves the content of a text document identified by the URI through a textDocument/xcontent request + * + * @param string $uri The URI of the document + * @return Promise Resolved with the content as a string + */ + public function retrieve(string $uri): Promise + { + return $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri)) + ->then(function (TextDocumentItem $textDocument) { + return $textDocument->text; + }); + } +} diff --git a/src/ContentRetriever/ContentRetriever.php b/src/ContentRetriever/ContentRetriever.php new file mode 100644 index 0000000..4d16b98 --- /dev/null +++ b/src/ContentRetriever/ContentRetriever.php @@ -0,0 +1,20 @@ + Resolved with the content as a string + */ + public function retrieve(string $uri): Promise; +} diff --git a/src/ContentRetriever/FileSystemContentRetriever.php b/src/ContentRetriever/FileSystemContentRetriever.php new file mode 100644 index 0000000..82e7002 --- /dev/null +++ b/src/ContentRetriever/FileSystemContentRetriever.php @@ -0,0 +1,24 @@ + Resolved with the content as a string + */ + public function retrieve(string $uri): Promise + { + return Promise\resolve(file_get_contents(uriToPath($uri))); + } +} diff --git a/src/Project.php b/src/Project.php index 3021a1c..b62b295 100644 --- a/src/Project.php +++ b/src/Project.php @@ -5,6 +5,7 @@ namespace LanguageServer; use LanguageServer\Protocol\{SymbolInformation, TextDocumentIdentifier, ClientCapabilities}; use phpDocumentor\Reflection\DocBlockFactory; +use LanguageServer\ContentRetriever\{ContentRetriever, ClientContentRetriever, FileSystemContentRetriever}; use Sabre\Event\Promise; use function Sabre\Event\coroutine; @@ -67,6 +68,13 @@ class Project */ private $clientCapabilities; + /** + * The content retriever + * + * @var ContentRetriever + */ + private $contentRetriever; + public function __construct(LanguageClient $client, ClientCapabilities $clientCapabilities) { $this->client = $client; @@ -74,6 +82,11 @@ class Project $this->parser = new Parser; $this->docBlockFactory = DocBlockFactory::createInstance(); $this->definitionResolver = new DefinitionResolver($this); + if ($clientCapabilities->xcontentProvider) { + $this->contentRetriever = new ClientContentRetriever($client); + } else { + $this->contentRetriever = new FileSystemContentRetriever; + } } /** @@ -112,19 +125,10 @@ class Project { return coroutine(function () use ($uri) { $limit = 150000; - if ($this->clientCapabilities->xcontentProvider) { - $content = (yield $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri)))->text; - $size = strlen($content); - if ($size > $limit) { - throw new ContentTooLargeException($uri, $size, $limit); - } - } else { - $path = uriToPath($uri); - $size = filesize($path); - if ($size > $limit) { - throw new ContentTooLargeException($uri, $size, $limit); - } - $content = file_get_contents($path); + $content = yield $this->contentRetriever->retrieve($uri); + $size = strlen($content); + if ($size > $limit) { + throw new ContentTooLargeException($uri, $size, $limit); } if (isset($this->documents[$uri])) { $document = $this->documents[$uri]; From b9f9871156642afaf42f75d8e2637a8d80c19484 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Thu, 8 Dec 2016 02:33:48 +0100 Subject: [PATCH 3/3] Files finder (#209) --- src/FilesFinder/ClientFilesFinder.php | 49 ++++++++++++ src/FilesFinder/FileSystemFilesFinder.php | 31 +++++++ src/FilesFinder/FilesFinder.php | 21 +++++ src/LanguageServer.php | 80 ++++++++----------- src/Project.php | 18 +---- tests/NodeVisitor/DefinitionCollectorTest.php | 5 +- tests/PhpDocumentTest.php | 3 +- tests/ProjectTest.php | 3 +- tests/Server/ServerTestCase.php | 3 +- tests/Server/TextDocument/CompletionTest.php | 3 +- .../Definition/GlobalFallbackTest.php | 3 +- tests/Server/TextDocument/DidChangeTest.php | 3 +- tests/Server/TextDocument/DidCloseTest.php | 3 +- tests/Server/TextDocument/FormattingTest.php | 5 +- tests/Server/TextDocument/ParseErrorsTest.php | 3 +- .../References/GlobalFallbackTest.php | 3 +- 16 files changed, 162 insertions(+), 74 deletions(-) create mode 100644 src/FilesFinder/ClientFilesFinder.php create mode 100644 src/FilesFinder/FileSystemFilesFinder.php create mode 100644 src/FilesFinder/FilesFinder.php diff --git a/src/FilesFinder/ClientFilesFinder.php b/src/FilesFinder/ClientFilesFinder.php new file mode 100644 index 0000000..4315ede --- /dev/null +++ b/src/FilesFinder/ClientFilesFinder.php @@ -0,0 +1,49 @@ +client = $client; + } + + /** + * Returns all files in the workspace that match a glob. + * If the client does not support workspace/files, it falls back to searching the file system directly. + * + * @param string $glob + * @return Promise The URIs + */ + public function find(string $glob): Promise + { + return $this->client->workspace->xfiles()->then(function (array $textDocuments) use ($glob) { + $uris = []; + foreach ($textDocuments as $textDocument) { + $path = Uri\parse($textDocument->uri)['path']; + if (Glob::match($path, $glob)) { + $uris[] = $textDocument->uri; + } + } + return $uris; + }); + } +} diff --git a/src/FilesFinder/FileSystemFilesFinder.php b/src/FilesFinder/FileSystemFilesFinder.php new file mode 100644 index 0000000..52df4b6 --- /dev/null +++ b/src/FilesFinder/FileSystemFilesFinder.php @@ -0,0 +1,31 @@ + + */ + public function find(string $glob): Promise + { + return coroutine(function () use ($glob) { + $uris = []; + foreach (new GlobIterator($glob) as $path) { + $uris[] = pathToUri($path); + yield timeout(); + } + return $uris; + }); + } +} diff --git a/src/FilesFinder/FilesFinder.php b/src/FilesFinder/FilesFinder.php new file mode 100644 index 0000000..81d6de5 --- /dev/null +++ b/src/FilesFinder/FilesFinder.php @@ -0,0 +1,21 @@ + + */ + public function find(string $glob): Promise; +} diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 42a1b64..6cda587 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -14,13 +14,13 @@ use LanguageServer\Protocol\{ TextDocumentIdentifier, CompletionOptions }; +use LanguageServer\FilesFinder\{FilesFinder, ClientFilesFinder, FileSystemFilesFinder}; +use LanguageServer\ContentRetriever\{ContentRetriever, ClientContentRetriever, FileSystemContentRetriever}; use AdvancedJsonRpc; use Sabre\Event\{Loop, Promise}; use function Sabre\Event\coroutine; use Exception; use Throwable; -use Webmozart\Glob\Iterator\GlobIterator; -use Webmozart\Glob\Glob; use Webmozart\PathUtil\Path; use Sabre\Uri; @@ -45,11 +45,6 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher public $completionItem; public $codeLens; - /** - * ClientCapabilities - */ - private $clientCapabilities; - private $protocolReader; private $protocolWriter; private $client; @@ -62,6 +57,16 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher private $rootPath; private $project; + /** + * @var FilesFinder + */ + private $filesFinder; + + /** + * @var ContentRetriever + */ + private $contentRetrieverFinder; + public function __construct(ProtocolReader $reader, ProtocolWriter $writer) { parent::__construct($this, '/'); @@ -120,8 +125,20 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher public function initialize(ClientCapabilities $capabilities, string $rootPath = null, int $processId = null): InitializeResult { $this->rootPath = $rootPath; - $this->clientCapabilities = $capabilities; - $this->project = new Project($this->client, $capabilities); + + if ($capabilities->xfilesProvider) { + $this->filesFinder = new ClientFilesFinder($this->client); + } else { + $this->filesFinder = new FileSystemFilesFinder; + } + + if ($capabilities->xcontentProvider) { + $this->contentRetriever = new ClientContentRetriever($this->client); + } else { + $this->contentRetriever = new FileSystemContentRetriever; + } + + $this->project = new Project($this->client, $this->contentRetriever); $this->textDocument = new Server\TextDocument($this->project, $this->client); $this->workspace = new Server\Workspace($this->project, $this->client); @@ -183,29 +200,30 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher private function indexProject(): Promise { return coroutine(function () { - $textDocuments = yield $this->findPhpFiles(); - $count = count($textDocuments); + $pattern = Path::makeAbsolute('**/*.php', $this->rootPath); + $uris = yield $this->filesFinder->find($pattern); + $count = count($uris); $startTime = microtime(true); - foreach ($textDocuments as $i => $textDocument) { + foreach ($uris as $i => $uri) { // Give LS to the chance to handle requests while indexing yield timeout(); $this->client->window->logMessage( MessageType::LOG, - "Parsing file $i/$count: {$textDocument->uri}" + "Parsing file $i/$count: {$uri}" ); try { - yield $this->project->loadDocument($textDocument->uri); + yield $this->project->loadDocument($uri); } catch (ContentTooLargeException $e) { $this->client->window->logMessage( MessageType::INFO, - "Ignoring file {$textDocument->uri} because it exceeds size limit of {$e->limit} bytes ({$e->size})" + "Ignoring file {$uri} because it exceeds size limit of {$e->limit} bytes ({$e->size})" ); } catch (Exception $e) { $this->client->window->logMessage( MessageType::ERROR, - "Error parsing file {$textDocument->uri}: " . (string)$e + "Error parsing file {$uri}: " . (string)$e ); } } @@ -218,34 +236,4 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher ); }); } - - /** - * Returns all PHP files in the workspace. - * If the client does not support workspace/files, it falls back to searching the file system directly. - * - * @return Promise - */ - private function findPhpFiles(): Promise - { - return coroutine(function () { - $textDocuments = []; - $pattern = Path::makeAbsolute('**/*.php', $this->rootPath); - if ($this->clientCapabilities->xfilesProvider) { - // Use xfiles request - foreach (yield $this->client->workspace->xfiles() as $textDocument) { - $path = Uri\parse($textDocument->uri)['path']; - if (Glob::match($path, $pattern)) { - $textDocuments[] = $textDocument; - } - } - } else { - // Use the file system - foreach (new GlobIterator($pattern) as $path) { - $textDocuments[] = new TextDocumentIdentifier(pathToUri($path)); - yield timeout(); - } - } - return $textDocuments; - }); - } } diff --git a/src/Project.php b/src/Project.php index b62b295..0582301 100644 --- a/src/Project.php +++ b/src/Project.php @@ -5,7 +5,7 @@ namespace LanguageServer; use LanguageServer\Protocol\{SymbolInformation, TextDocumentIdentifier, ClientCapabilities}; use phpDocumentor\Reflection\DocBlockFactory; -use LanguageServer\ContentRetriever\{ContentRetriever, ClientContentRetriever, FileSystemContentRetriever}; +use LanguageServer\ContentRetriever\ContentRetriever; use Sabre\Event\Promise; use function Sabre\Event\coroutine; @@ -61,13 +61,6 @@ class Project */ private $client; - /** - * The client's capabilities - * - * @var ClientCapabilities - */ - private $clientCapabilities; - /** * The content retriever * @@ -75,18 +68,13 @@ class Project */ private $contentRetriever; - public function __construct(LanguageClient $client, ClientCapabilities $clientCapabilities) + public function __construct(LanguageClient $client, ContentRetriever $contentRetriever) { $this->client = $client; - $this->clientCapabilities = $clientCapabilities; $this->parser = new Parser; $this->docBlockFactory = DocBlockFactory::createInstance(); $this->definitionResolver = new DefinitionResolver($this); - if ($clientCapabilities->xcontentProvider) { - $this->contentRetriever = new ClientContentRetriever($client); - } else { - $this->contentRetriever = new FileSystemContentRetriever; - } + $this->contentRetriever = $contentRetriever; } /** diff --git a/tests/NodeVisitor/DefinitionCollectorTest.php b/tests/NodeVisitor/DefinitionCollectorTest.php index 74e0d5c..800373d 100644 --- a/tests/NodeVisitor/DefinitionCollectorTest.php +++ b/tests/NodeVisitor/DefinitionCollectorTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use PhpParser\{NodeTraverser, Node}; use PhpParser\NodeVisitor\NameResolver; use LanguageServer\{LanguageClient, Project, PhpDocument, Parser, DefinitionResolver}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\ClientCapabilities; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\NodeVisitor\{ReferencesAdder, DefinitionCollector}; @@ -17,7 +18,7 @@ class DefinitionCollectorTest extends TestCase public function testCollectsSymbols() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $parser = new Parser; $uri = pathToUri(realpath(__DIR__ . '/../../fixtures/symbols.php')); $document = $project->loadDocument($uri)->wait(); @@ -57,7 +58,7 @@ class DefinitionCollectorTest extends TestCase public function testDoesNotCollectReferences() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $parser = new Parser; $uri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php')); $document = $project->loadDocument($uri)->wait(); diff --git a/tests/PhpDocumentTest.php b/tests/PhpDocumentTest.php index 057551e..a4e8ffa 100644 --- a/tests/PhpDocumentTest.php +++ b/tests/PhpDocumentTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{LanguageClient, Project}; use LanguageServer\NodeVisitor\NodeAtPositionFinder; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{SymbolKind, Position, ClientCapabilities}; use PhpParser\Node; @@ -20,7 +21,7 @@ class PhpDocumentTest extends TestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $this->project = new Project($client, new ClientCapabilities); + $this->project = new Project($client, new FileSystemContentRetriever); } public function testParsesVariableVariables() diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index 161370c..6fef176 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{ TextDocumentItem, TextDocumentIdentifier, @@ -27,7 +28,7 @@ class ProjectTest extends TestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $this->project = new Project($client, new ClientCapabilities); + $this->project = new Project($client, new FileSystemContentRetriever); } public function testGetOrLoadDocumentLoadsDocument() diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 23d1763..38e2c8a 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, LanguageClient, Project}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities}; use function LanguageServer\pathToUri; use Sabre\Event\Promise; @@ -44,7 +45,7 @@ abstract class ServerTestCase extends TestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $this->project = new Project($client, new ClientCapabilities); + $this->project = new Project($client, new FileSystemContentRetriever); $this->textDocument = new Server\TextDocument($this->project, $client); $this->workspace = new Server\Workspace($this->project, $client); diff --git a/tests/Server/TextDocument/CompletionTest.php b/tests/Server/TextDocument/CompletionTest.php index f32503c..587f171 100644 --- a/tests/Server/TextDocument/CompletionTest.php +++ b/tests/Server/TextDocument/CompletionTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, LanguageClient, Project, CompletionProvider}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{ TextDocumentIdentifier, TextEdit, @@ -33,7 +34,7 @@ class CompletionTest extends TestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $this->project = new Project($client, new ClientCapabilities); + $this->project = new Project($client, new FileSystemContentRetriever); $this->project->loadDocument(pathToUri(__DIR__ . '/../../../fixtures/global_symbols.php'))->wait(); $this->project->loadDocument(pathToUri(__DIR__ . '/../../../fixtures/symbols.php'))->wait(); $this->textDocument = new Server\TextDocument($this->project, $client); diff --git a/tests/Server/TextDocument/Definition/GlobalFallbackTest.php b/tests/Server/TextDocument/Definition/GlobalFallbackTest.php index c4b021d..20ea70b 100644 --- a/tests/Server/TextDocument/Definition/GlobalFallbackTest.php +++ b/tests/Server/TextDocument/Definition/GlobalFallbackTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument\Definition; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\Tests\Server\ServerTestCase; use LanguageServer\{Server, LanguageClient, Project}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location, ClientCapabilities}; use Sabre\Event\Promise; @@ -14,7 +15,7 @@ class GlobalFallbackTest extends ServerTestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $this->textDocument = new Server\TextDocument($project, $client); $project->openDocument('global_fallback', file_get_contents(__DIR__ . '/../../../../fixtures/global_fallback.php')); $project->openDocument('global_symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php')); diff --git a/tests/Server/TextDocument/DidChangeTest.php b/tests/Server/TextDocument/DidChangeTest.php index 1df0505..9df301a 100644 --- a/tests/Server/TextDocument/DidChangeTest.php +++ b/tests/Server/TextDocument/DidChangeTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, Client, LanguageClient, Project}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{ TextDocumentIdentifier, TextDocumentItem, @@ -21,7 +22,7 @@ class DidChangeTest extends TestCase public function test() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $textDocument = new Server\TextDocument($project, $client); $phpDocument = $project->openDocument('whatever', "openDocument('whatever', 'hello world'); diff --git a/tests/Server/TextDocument/FormattingTest.php b/tests/Server/TextDocument/FormattingTest.php index b7d0609..32aee22 100644 --- a/tests/Server/TextDocument/FormattingTest.php +++ b/tests/Server/TextDocument/FormattingTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, Client, LanguageClient, Project}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{ TextDocumentIdentifier, TextDocumentItem, @@ -27,14 +28,14 @@ class FormattingTest extends TestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $this->textDocument = new Server\TextDocument($project, $client); } public function testFormatting() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $textDocument = new Server\TextDocument($project, $client); $path = realpath(__DIR__ . '/../../../fixtures/format.php'); $uri = pathToUri($path); diff --git a/tests/Server/TextDocument/ParseErrorsTest.php b/tests/Server/TextDocument/ParseErrorsTest.php index 2a02efe..af2bdd8 100644 --- a/tests/Server/TextDocument/ParseErrorsTest.php +++ b/tests/Server/TextDocument/ParseErrorsTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, Client, LanguageClient, Project, ClientHandler}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{TextDocumentIdentifier, TextDocumentItem, DiagnosticSeverity, ClientCapabilities}; use Sabre\Event\Promise; use JsonMapper; @@ -35,7 +36,7 @@ class ParseErrorsTest extends TestCase return Promise\resolve(null); } }; - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $this->textDocument = new Server\TextDocument($project, $client); } diff --git a/tests/Server/TextDocument/References/GlobalFallbackTest.php b/tests/Server/TextDocument/References/GlobalFallbackTest.php index 9f68cb9..4e6d07a 100644 --- a/tests/Server/TextDocument/References/GlobalFallbackTest.php +++ b/tests/Server/TextDocument/References/GlobalFallbackTest.php @@ -6,6 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument\References; use PHPUnit\Framework\TestCase; use LanguageServer\Tests\MockProtocolStream; use LanguageServer\{Server, LanguageClient, Project}; +use LanguageServer\ContentRetriever\FileSystemContentRetriever; use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range, ClientCapabilities}; use LanguageServer\Tests\Server\ServerTestCase; @@ -14,7 +15,7 @@ class GlobalFallbackTest extends ServerTestCase public function setUp() { $client = new LanguageClient(new MockProtocolStream, new MockProtocolStream); - $project = new Project($client, new ClientCapabilities); + $project = new Project($client, new FileSystemContentRetriever); $this->textDocument = new Server\TextDocument($project, $client); $project->openDocument('global_fallback', file_get_contents(__DIR__ . '/../../../../fixtures/global_fallback.php')); $project->openDocument('global_symbols', file_get_contents(__DIR__ . '/../../../../fixtures/global_symbols.php'));