Return empty array instead of null for empty definitions result (#64)
parent
1f808c59e1
commit
d41cde2039
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,18 @@ class DefinitionTest extends TestCase
|
|||
$project->getDocument('use')->updateContent(file_get_contents(__DIR__ . '/../../../fixtures/use.php'));
|
||||
}
|
||||
|
||||
public function testDefinitionFileBeginning() {
|
||||
// |<?php
|
||||
$result = $this->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();
|
||||
|
|
Loading…
Reference in New Issue