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 TextDocumentIdentifier $textDocument The text document
|
||||||
* @param Position $position The position inside 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)
|
public function definition(TextDocumentIdentifier $textDocument, Position $position)
|
||||||
{
|
{
|
||||||
$document = $this->project->getDocument($textDocument->uri);
|
$document = $this->project->getDocument($textDocument->uri);
|
||||||
$node = $document->getNodeAtPosition($position);
|
$node = $document->getNodeAtPosition($position);
|
||||||
if ($node === null) {
|
if ($node === null) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
$def = $document->getDefinitionByNode($node);
|
$def = $document->getDefinitionByNode($node);
|
||||||
if ($def === null) {
|
if ($def === null) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
return Location::fromNode($def);
|
return Location::fromNode($def);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,18 @@ class DefinitionTest extends TestCase
|
||||||
$project->getDocument('use')->updateContent(file_get_contents(__DIR__ . '/../../../fixtures/use.php'));
|
$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()
|
public function testDefinitionForClassLike()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// $obj = new TestClass();
|
||||||
|
|
Loading…
Reference in New Issue