diff --git a/src/Server/TextDocument.php b/src/Server/TextDocument.php index 39a9699..f98ec57 100644 --- a/src/Server/TextDocument.php +++ b/src/Server/TextDocument.php @@ -96,18 +96,18 @@ class TextDocument * * @param TextDocumentIdentifier $textDocument The text document * @param Position $position The position inside the text document - * @return Location|Location[]|null + * @return Location|Location[] */ public function definition(TextDocumentIdentifier $textDocument, Position $position) { $document = $this->project->getDocument($textDocument->uri); $node = $document->getNodeAtPosition($position); if ($node === null) { - return null; + return []; } $def = $document->getDefinitionByNode($node); if ($def === null) { - return null; + return []; } return Location::fromNode($def); } diff --git a/tests/Server/TextDocument/DefinitionTest.php b/tests/Server/TextDocument/DefinitionTest.php index 948fb35..455a2b3 100644 --- a/tests/Server/TextDocument/DefinitionTest.php +++ b/tests/Server/TextDocument/DefinitionTest.php @@ -25,6 +25,18 @@ class DefinitionTest extends TestCase $project->getDocument('use')->updateContent(file_get_contents(__DIR__ . '/../../../fixtures/use.php')); } + public function testDefinitionFileBeginning() { + // |textDocument->definition(new TextDocumentIdentifier('references'), new Position(0, 0)); + $this->assertEquals([], json_decode(json_encode($result), true)); + } + + public function testDefinitionEmptyResult() { + // namespace keyword + $result = $this->textDocument->definition(new TextDocumentIdentifier('references'), new Position(2, 4)); + $this->assertEquals([], json_decode(json_encode($result), true)); + } + public function testDefinitionForClassLike() { // $obj = new TestClass();