1
0
Fork 0

Merge branch 'master' into lazy-load-alternative

pull/63/head
Felix Becker 2016-10-11 11:37:27 +02:00
commit 891c60c74e
5 changed files with 63 additions and 23 deletions

View File

@ -0,0 +1,5 @@
<?php
echo "Hello";
namespace A;

View File

@ -113,10 +113,11 @@ class PhpDocument
$diagnostics = []; $diagnostics = [];
foreach ($errors as $error) { foreach ($errors as $error) {
$diagnostic = new Diagnostic(); $diagnostic = new Diagnostic();
$diagnostic->range = new Range( $startLine = max($error->getStartLine() - 1, 0);
new Position($error->getStartLine() - 1, $error->hasColumnInfo() ? $error->getStartColumn($content) - 1 : 0), $startColumn = $error->hasColumnInfo() ? $error->getStartColumn($this->content) - 1 : 0;
new Position($error->getEndLine() - 1, $error->hasColumnInfo() ? $error->getEndColumn($content) : 0) $endLine = max($error->getEndLine() - 1, $startLine);
); $endColumn = $error->hasColumnInfo() ? $error->getEndColumn($this->content) : 0;
$diagnostic->range = new Range(new Position($startLine, $startColumn), new Position($endLine, $endColumn));
$diagnostic->severity = DiagnosticSeverity::ERROR; $diagnostic->severity = DiagnosticSeverity::ERROR;
$diagnostic->source = 'php'; $diagnostic->source = 'php';
// Do not include "on line ..." in the error message // Do not include "on line ..." in the error message

View File

@ -113,18 +113,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);
} }

View File

@ -25,6 +25,18 @@ class DefinitionTest extends TestCase
$project->openDocument('use', file_get_contents(__DIR__ . '/../../../fixtures/use.php')); $project->openDocument('use', 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();

View File

@ -15,18 +15,12 @@ class ParseErrorsTest extends TestCase
*/ */
private $textDocument; private $textDocument;
private $args;
public function setUp() public function setUp()
{ {
$client = new LanguageClient(new MockProtocolStream()); $client = new LanguageClient(new MockProtocolStream());
$project = new Project($client); $client->textDocument = new class($this->args) extends Client\TextDocument {
$this->textDocument = new Server\TextDocument($project, $client);
}
public function testParseErrorsArePublishedAsDiagnostics()
{
$args = null;
$client = new LanguageClient(new MockProtocolStream());
$client->textDocument = new class($args) extends Client\TextDocument {
private $args; private $args;
public function __construct(&$args) public function __construct(&$args)
{ {
@ -38,18 +32,22 @@ class ParseErrorsTest extends TestCase
$this->args = func_get_args(); $this->args = func_get_args();
} }
}; };
$project = new Project($client); $project = new Project($client);
$this->textDocument = new Server\TextDocument($project, $client);
}
$textDocument = new Server\TextDocument($project, $client); private function openFile($file) {
// Trigger parsing of source
$textDocumentItem = new TextDocumentItem(); $textDocumentItem = new TextDocumentItem();
$textDocumentItem->uri = 'whatever'; $textDocumentItem->uri = 'whatever';
$textDocumentItem->languageId = 'php'; $textDocumentItem->languageId = 'php';
$textDocumentItem->version = 1; $textDocumentItem->version = 1;
$textDocumentItem->text = file_get_contents(__DIR__ . '/../../../fixtures/invalid_file.php'); $textDocumentItem->text = file_get_contents($file);
$textDocument->didOpen($textDocumentItem); $this->textDocument->didOpen($textDocumentItem);
}
public function testParseErrorsArePublishedAsDiagnostics()
{
$this->openFile(__DIR__ . '/../../../fixtures/invalid_file.php');
$this->assertEquals([ $this->assertEquals([
'whatever', 'whatever',
[[ [[
@ -68,6 +66,30 @@ class ParseErrorsTest extends TestCase
'source' => 'php', 'source' => 'php',
'message' => "Syntax error, unexpected T_CLASS, expecting T_STRING" 'message' => "Syntax error, unexpected T_CLASS, expecting T_STRING"
]] ]]
], json_decode(json_encode($args), true)); ], json_decode(json_encode($this->args), true));
}
public function testParseErrorsWithOnlyStartLine()
{
$this->openFile(__DIR__ . '/../../../fixtures/namespace_not_first.php');
$this->assertEquals([
'whatever',
[[
'range' => [
'start' => [
'line' => 4,
'character' => 0
],
'end' => [
'line' => 4,
'character' => 0
]
],
'severity' => DiagnosticSeverity::ERROR,
'code' => null,
'source' => 'php',
'message' => "Namespace declaration statement has to be the very first statement in the script"
]]
], json_decode(json_encode($this->args), true));
} }
} }