Merge branch 'master' into remove-definitions
commit
8349116fe7
|
@ -13,6 +13,12 @@ test_function();
|
||||||
$var = 123;
|
$var = 123;
|
||||||
echo $var;
|
echo $var;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aute duis elit reprehenderit tempor cillum proident anim laborum eu laboris reprehenderit ea incididunt.
|
||||||
|
*
|
||||||
|
* @param TestClass $param Adipisicing non non cillum sint incididunt cillum enim mollit.
|
||||||
|
* @return TestClass
|
||||||
|
*/
|
||||||
function whatever(TestClass $param): TestClass {
|
function whatever(TestClass $param): TestClass {
|
||||||
echo $param;
|
echo $param;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,59 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
const TEST_CONST = 123;
|
const TEST_CONST = 123;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pariatur ut laborum tempor voluptate consequat ea deserunt.
|
||||||
|
*
|
||||||
|
* Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud
|
||||||
|
* laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam
|
||||||
|
* veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat
|
||||||
|
* consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem
|
||||||
|
* sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.
|
||||||
|
*/
|
||||||
class TestClass implements TestInterface
|
class TestClass implements TestInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
const TEST_CLASS_CONST = 123;
|
const TEST_CLASS_CONST = 123;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lorem excepteur officia sit anim velit veniam enim.
|
||||||
|
*
|
||||||
|
* @var TestClass
|
||||||
|
*/
|
||||||
public static $staticTestProperty;
|
public static $staticTestProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reprehenderit magna velit mollit ipsum do.
|
||||||
|
*
|
||||||
|
* @var TestClass
|
||||||
|
*/
|
||||||
public $testProperty;
|
public $testProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do magna consequat veniam minim proident eiusmod incididunt aute proident.
|
||||||
|
*/
|
||||||
public static function staticTestMethod()
|
public static function staticTestMethod()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.
|
||||||
|
*
|
||||||
|
* @param TestClass $testParameter Lorem sunt velit incididunt mollit
|
||||||
|
* @return TestClass
|
||||||
|
*/
|
||||||
public function testMethod($testParameter)
|
public function testMethod($testParameter)
|
||||||
{
|
{
|
||||||
$testVariable = 123;
|
$testVariable = 123;
|
||||||
|
@ -31,6 +71,11 @@ interface TestInterface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Officia aliquip adipisicing et nulla et laboris dolore labore.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function test_function()
|
function test_function()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,12 @@ test_function();
|
||||||
$var = 123;
|
$var = 123;
|
||||||
echo $var;
|
echo $var;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aute duis elit reprehenderit tempor cillum proident anim laborum eu laboris reprehenderit ea incididunt.
|
||||||
|
*
|
||||||
|
* @param TestClass $param Adipisicing non non cillum sint incididunt cillum enim mollit.
|
||||||
|
* @return TestClass
|
||||||
|
*/
|
||||||
function whatever(TestClass $param): TestClass {
|
function whatever(TestClass $param): TestClass {
|
||||||
echo $param;
|
echo $param;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,59 @@
|
||||||
|
|
||||||
namespace TestNamespace;
|
namespace TestNamespace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
const TEST_CONST = 123;
|
const TEST_CONST = 123;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pariatur ut laborum tempor voluptate consequat ea deserunt.
|
||||||
|
*
|
||||||
|
* Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud
|
||||||
|
* laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam
|
||||||
|
* veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat
|
||||||
|
* consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem
|
||||||
|
* sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.
|
||||||
|
*/
|
||||||
class TestClass implements TestInterface
|
class TestClass implements TestInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
const TEST_CLASS_CONST = 123;
|
const TEST_CLASS_CONST = 123;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lorem excepteur officia sit anim velit veniam enim.
|
||||||
|
*
|
||||||
|
* @var TestClass
|
||||||
|
*/
|
||||||
public static $staticTestProperty;
|
public static $staticTestProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reprehenderit magna velit mollit ipsum do.
|
||||||
|
*
|
||||||
|
* @var TestClass
|
||||||
|
*/
|
||||||
public $testProperty;
|
public $testProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do magna consequat veniam minim proident eiusmod incididunt aute proident.
|
||||||
|
*/
|
||||||
public static function staticTestMethod()
|
public static function staticTestMethod()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.
|
||||||
|
*
|
||||||
|
* @param TestClass $testParameter Lorem sunt velit incididunt mollit
|
||||||
|
* @return TestClass
|
||||||
|
*/
|
||||||
public function testMethod($testParameter)
|
public function testMethod($testParameter)
|
||||||
{
|
{
|
||||||
$testVariable = 123;
|
$testVariable = 123;
|
||||||
|
@ -31,6 +71,11 @@ interface TestInterface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Officia aliquip adipisicing et nulla et laboris dolore labore.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function test_function()
|
function test_function()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,8 @@ class LanguageServer extends \AdvancedJsonRpc\Dispatcher
|
||||||
$serverCapabilities->definitionProvider = true;
|
$serverCapabilities->definitionProvider = true;
|
||||||
// Support "Find all references"
|
// Support "Find all references"
|
||||||
$serverCapabilities->referencesProvider = true;
|
$serverCapabilities->referencesProvider = true;
|
||||||
|
// Support "Hover"
|
||||||
|
$serverCapabilities->hoverProvider = true;
|
||||||
|
|
||||||
return new InitializeResult($serverCapabilities);
|
return new InitializeResult($serverCapabilities);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace LanguageServer\NodeVisitor;
|
||||||
|
|
||||||
|
use PhpParser;
|
||||||
|
use PhpParser\{NodeVisitorAbstract, Node, Comment};
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decorates all nodes with a docBlock attribute that is an instance of phpDocumentor\Reflection\DocBlock
|
||||||
|
*/
|
||||||
|
class DocBlockParser extends NodeVisitorAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var DocBlockFactory
|
||||||
|
*/
|
||||||
|
private $docBlockFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current namespace context
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $namespace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace aliases in the current context
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
private $aliases;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PhpParser\Error[]
|
||||||
|
*/
|
||||||
|
public $errors = [];
|
||||||
|
|
||||||
|
public function __construct(DocBlockFactory $docBlockFactory)
|
||||||
|
{
|
||||||
|
$this->docBlockFactory = $docBlockFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function beforeTraverse(array $nodes)
|
||||||
|
{
|
||||||
|
$this->namespace = '';
|
||||||
|
$this->aliases = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enterNode(Node $node)
|
||||||
|
{
|
||||||
|
if ($node instanceof Node\Stmt\Namespace_) {
|
||||||
|
$this->namespace = (string)$node->name;
|
||||||
|
} else if ($node instanceof Node\Stmt\UseUse) {
|
||||||
|
$this->aliases[(string)$node->name] = $node->alias;
|
||||||
|
}
|
||||||
|
$docComment = $node->getDocComment();
|
||||||
|
if ($docComment === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$context = new Context($this->namespace, $this->aliases);
|
||||||
|
try {
|
||||||
|
$docBlock = $this->docBlockFactory->create($docComment->getText(), $context);
|
||||||
|
$node->setAttribute('docBlock', $docBlock);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->errors[] = new PhpParser\Error($e->getMessage(), [
|
||||||
|
'startFilePos' => $docComment->getFilePos(),
|
||||||
|
'endFilePos' => $docComment->getFilePos() + strlen($docComment->getText()),
|
||||||
|
'startLine' => $docComment->getLine(),
|
||||||
|
'endLine' => $docComment->getLine() + preg_match_all('/[\\n\\r]/', $docComment->getText()) + 1
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leaveNode(Node $node)
|
||||||
|
{
|
||||||
|
if ($node instanceof Node\Stmt\Namespace_) {
|
||||||
|
$this->namespace = '';
|
||||||
|
$this->aliases = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position, Te
|
||||||
use LanguageServer\NodeVisitor\{
|
use LanguageServer\NodeVisitor\{
|
||||||
NodeAtPositionFinder,
|
NodeAtPositionFinder,
|
||||||
ReferencesAdder,
|
ReferencesAdder,
|
||||||
|
DocBlockParser,
|
||||||
DefinitionCollector,
|
DefinitionCollector,
|
||||||
ColumnCalculator,
|
ColumnCalculator,
|
||||||
ReferencesCollector,
|
ReferencesCollector,
|
||||||
|
@ -14,6 +15,7 @@ use LanguageServer\NodeVisitor\{
|
||||||
};
|
};
|
||||||
use PhpParser\{Error, Node, NodeTraverser, Parser};
|
use PhpParser\{Error, Node, NodeTraverser, Parser};
|
||||||
use PhpParser\NodeVisitor\NameResolver;
|
use PhpParser\NodeVisitor\NameResolver;
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
|
|
||||||
class PhpDocument
|
class PhpDocument
|
||||||
{
|
{
|
||||||
|
@ -40,6 +42,13 @@ class PhpDocument
|
||||||
*/
|
*/
|
||||||
private $parser;
|
private $parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DocBlockFactory instance to parse docblocks
|
||||||
|
*
|
||||||
|
* @var DocBlockFactory
|
||||||
|
*/
|
||||||
|
private $docBlockFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URI of the document
|
* The URI of the document
|
||||||
*
|
*
|
||||||
|
@ -81,13 +90,15 @@ class PhpDocument
|
||||||
* @param Project $project The Project this document belongs to (to register definitions etc)
|
* @param Project $project The Project this document belongs to (to register definitions etc)
|
||||||
* @param LanguageClient $client The LanguageClient instance (to report errors etc)
|
* @param LanguageClient $client The LanguageClient instance (to report errors etc)
|
||||||
* @param Parser $parser The PHPParser instance
|
* @param Parser $parser The PHPParser instance
|
||||||
|
* @param DocBlockFactory $docBlockFactory The DocBlockFactory instance to parse docblocks
|
||||||
*/
|
*/
|
||||||
public function __construct(string $uri, string $content, Project $project, LanguageClient $client, Parser $parser)
|
public function __construct(string $uri, string $content, Project $project, LanguageClient $client, Parser $parser, DocBlockFactory $docBlockFactory)
|
||||||
{
|
{
|
||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
$this->docBlockFactory = $docBlockFactory;
|
||||||
$this->updateContent($content);
|
$this->updateContent($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,19 +138,8 @@ class PhpDocument
|
||||||
|
|
||||||
$diagnostics = [];
|
$diagnostics = [];
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
$diagnostic = new Diagnostic();
|
$diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::ERROR, 'php');
|
||||||
$startLine = max($error->getStartLine() - 1, 0);
|
|
||||||
$startColumn = $error->hasColumnInfo() ? $error->getStartColumn($this->content) - 1 : 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->source = 'php';
|
|
||||||
// Do not include "on line ..." in the error message
|
|
||||||
$diagnostic->message = $error->getRawMessage();
|
|
||||||
$diagnostics[] = $diagnostic;
|
|
||||||
}
|
}
|
||||||
$this->client->textDocument->publishDiagnostics($this->uri, $diagnostics);
|
|
||||||
|
|
||||||
// $stmts can be null in case of a fatal parsing error
|
// $stmts can be null in case of a fatal parsing error
|
||||||
if ($stmts) {
|
if ($stmts) {
|
||||||
|
@ -154,7 +154,17 @@ class PhpDocument
|
||||||
// Add column attributes to nodes
|
// Add column attributes to nodes
|
||||||
$traverser->addVisitor(new ColumnCalculator($content));
|
$traverser->addVisitor(new ColumnCalculator($content));
|
||||||
|
|
||||||
|
// Parse docblocks and add docBlock attributes to nodes
|
||||||
|
$docBlockParser = new DocBlockParser($this->docBlockFactory);
|
||||||
|
$traverser->addVisitor($docBlockParser);
|
||||||
|
|
||||||
$traverser->traverse($stmts);
|
$traverser->traverse($stmts);
|
||||||
|
|
||||||
|
// Report errors from parsing docblocks
|
||||||
|
foreach ($docBlockParser->errors as $error) {
|
||||||
|
$diagnostics[] = Diagnostic::fromError($error, $this->content, DiagnosticSeverity::WARNING, 'php');
|
||||||
|
}
|
||||||
|
|
||||||
$traverser = new NodeTraverser;
|
$traverser = new NodeTraverser;
|
||||||
|
|
||||||
// Collect all definitions
|
// Collect all definitions
|
||||||
|
@ -193,6 +203,8 @@ class PhpDocument
|
||||||
|
|
||||||
$this->stmts = $stmts;
|
$this->stmts = $stmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->client->textDocument->publishDiagnostics($this->uri, $diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer;
|
namespace LanguageServer;
|
||||||
|
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
use PhpParser\{ParserFactory, Lexer};
|
use PhpParser\{ParserFactory, Lexer};
|
||||||
|
|
||||||
class Project
|
class Project
|
||||||
|
@ -36,6 +37,13 @@ class Project
|
||||||
*/
|
*/
|
||||||
private $parser;
|
private $parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DocBlockFactory instance to parse docblocks
|
||||||
|
*
|
||||||
|
* @var DocBlockFactory
|
||||||
|
*/
|
||||||
|
private $docBlockFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the language server client interface
|
* Reference to the language server client interface
|
||||||
*
|
*
|
||||||
|
@ -49,6 +57,7 @@ class Project
|
||||||
|
|
||||||
$lexer = new Lexer(['usedAttributes' => ['comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos']]);
|
$lexer = new Lexer(['usedAttributes' => ['comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos']]);
|
||||||
$this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer, ['throwOnError' => false]);
|
$this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer, ['throwOnError' => false]);
|
||||||
|
$this->docBlockFactory = DocBlockFactory::createInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +90,7 @@ class Project
|
||||||
$document = $this->documents[$uri];
|
$document = $this->documents[$uri];
|
||||||
$document->updateContent($content);
|
$document->updateContent($content);
|
||||||
} else {
|
} else {
|
||||||
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser);
|
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser, $this->docBlockFactory);
|
||||||
}
|
}
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +108,7 @@ class Project
|
||||||
$document = $this->documents[$uri];
|
$document = $this->documents[$uri];
|
||||||
$document->updateContent($content);
|
$document->updateContent($content);
|
||||||
} else {
|
} else {
|
||||||
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser);
|
$document = new PhpDocument($uri, $content, $this, $this->client, $this->parser, $this->docBlockFactory);
|
||||||
$this->documents[$uri] = $document;
|
$this->documents[$uri] = $document;
|
||||||
}
|
}
|
||||||
return $document;
|
return $document;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace LanguageServer\Protocol;
|
namespace LanguageServer\Protocol;
|
||||||
|
|
||||||
|
use PhpParser\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a
|
* Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a
|
||||||
* resource.
|
* resource.
|
||||||
|
@ -44,4 +46,40 @@ class Diagnostic
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $message;
|
public $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a diagnostic from a PhpParser Error
|
||||||
|
*
|
||||||
|
* @param Error $error Message and code will be used
|
||||||
|
* @param string $content The file content to calculate the column info
|
||||||
|
* @param int $severity DiagnosticSeverity
|
||||||
|
* @param string $source A human-readable string describing the source of this diagnostic
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public static function fromError(Error $error, string $content, int $severity = null, string $source = null): self
|
||||||
|
{
|
||||||
|
return new self(
|
||||||
|
$error->getRawMessage(), // Do not include "on line ..." in the error message
|
||||||
|
Range::fromError($error, $content),
|
||||||
|
$error->getCode(),
|
||||||
|
$severity,
|
||||||
|
$source
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message The diagnostic's message
|
||||||
|
* @param Range $range The range at which the message applies
|
||||||
|
* @param int $code The diagnostic's code
|
||||||
|
* @param int $severity DiagnosticSeverity
|
||||||
|
* @param string $source A human-readable string describing the source of this diagnostic
|
||||||
|
*/
|
||||||
|
public function __construct(string $message = null, Range $range = null, int $code = null, int $severity = null, string $source = null)
|
||||||
|
{
|
||||||
|
$this->message = $message;
|
||||||
|
$this->range = $range;
|
||||||
|
$this->code = $code;
|
||||||
|
$this->severity = $severity;
|
||||||
|
$this->source = $source;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Hover
|
||||||
/**
|
/**
|
||||||
* The hover's content
|
* The hover's content
|
||||||
*
|
*
|
||||||
* @var string|string[]|MarkedString|MarkedString[]
|
* @var string|MarkedString|string[]|MarkedString[]
|
||||||
*/
|
*/
|
||||||
public $contents;
|
public $contents;
|
||||||
|
|
||||||
|
@ -20,4 +20,14 @@ class Hover
|
||||||
* @var Range|null
|
* @var Range|null
|
||||||
*/
|
*/
|
||||||
public $range;
|
public $range;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|MarkedString|string[]|MarkedString[] $contents The hover's content
|
||||||
|
* @param Range $range An optional range
|
||||||
|
*/
|
||||||
|
public function __construct($contents = null, $range = null)
|
||||||
|
{
|
||||||
|
$this->contents = $contents;
|
||||||
|
$this->range = $range;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LanguageServer\Protocol;
|
||||||
|
|
||||||
|
class MarkedString
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $value;
|
||||||
|
|
||||||
|
public function __construct(string $language = null, string $value = null)
|
||||||
|
{
|
||||||
|
$this->language = $language;
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace LanguageServer\Protocol;
|
namespace LanguageServer\Protocol;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\{Error, Node};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A range in a text document expressed as (zero-based) start and end positions.
|
* A range in a text document expressed as (zero-based) start and end positions.
|
||||||
|
@ -37,6 +37,22 @@ class Range
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the range where an error occured
|
||||||
|
*
|
||||||
|
* @param \PhpParser\Error $error
|
||||||
|
* @param string $content
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public static function fromError(Error $error, string $content)
|
||||||
|
{
|
||||||
|
$startLine = max($error->getStartLine() - 1, 0);
|
||||||
|
$endLine = max($error->getEndLine() - 1, $startLine);
|
||||||
|
$startColumn = $error->hasColumnInfo() ? $error->getStartColumn($content) - 1 : 0;
|
||||||
|
$endColumn = $error->hasColumnInfo() ? $error->getEndColumn($content) : 0;
|
||||||
|
return new self(new Position($startLine, $startColumn), new Position($endLine, $endColumn));
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct(Position $start = null, Position $end = null)
|
public function __construct(Position $start = null, Position $end = null)
|
||||||
{
|
{
|
||||||
$this->start = $start;
|
$this->start = $start;
|
||||||
|
|
|
@ -73,4 +73,18 @@ class SymbolInformation
|
||||||
}
|
}
|
||||||
return $symbol;
|
return $symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param int $kind
|
||||||
|
* @param Location $location
|
||||||
|
* @param string $containerName
|
||||||
|
*/
|
||||||
|
public function __construct($name = null, $kind = null, $location = null, $containerName = null)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->kind = $kind;
|
||||||
|
$this->location = $location;
|
||||||
|
$this->containerName = $containerName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,21 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Server;
|
namespace LanguageServer\Server;
|
||||||
|
|
||||||
use LanguageServer\{LanguageClient, Project};
|
use LanguageServer\{LanguageClient, Project};
|
||||||
|
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
|
||||||
|
use PhpParser\Node;
|
||||||
use LanguageServer\Protocol\{
|
use LanguageServer\Protocol\{
|
||||||
TextDocumentItem,
|
TextDocumentItem,
|
||||||
TextDocumentIdentifier,
|
TextDocumentIdentifier,
|
||||||
VersionedTextDocumentIdentifier,
|
VersionedTextDocumentIdentifier,
|
||||||
Position,
|
Position,
|
||||||
|
Range,
|
||||||
FormattingOptions,
|
FormattingOptions,
|
||||||
TextEdit,
|
TextEdit,
|
||||||
Location,
|
Location,
|
||||||
SymbolInformation,
|
SymbolInformation,
|
||||||
ReferenceContext
|
ReferenceContext,
|
||||||
|
Hover,
|
||||||
|
MarkedString
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,10 +38,16 @@ class TextDocument
|
||||||
*/
|
*/
|
||||||
private $project;
|
private $project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PrettyPrinter
|
||||||
|
*/
|
||||||
|
private $prettyPrinter;
|
||||||
|
|
||||||
public function __construct(Project $project, LanguageClient $client)
|
public function __construct(Project $project, LanguageClient $client)
|
||||||
{
|
{
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
|
$this->prettyPrinter = new PrettyPrinter();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,4 +159,72 @@ class TextDocument
|
||||||
}
|
}
|
||||||
return Location::fromNode($def);
|
return Location::fromNode($def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hover request is sent from the client to the server to request hover information at a given text document position.
|
||||||
|
*
|
||||||
|
* @param TextDocumentIdentifier $textDocument The text document
|
||||||
|
* @param Position $position The position inside the text document
|
||||||
|
* @return Hover
|
||||||
|
*/
|
||||||
|
public function hover(TextDocumentIdentifier $textDocument, Position $position): Hover
|
||||||
|
{
|
||||||
|
$document = $this->project->getDocument($textDocument->uri);
|
||||||
|
// Find the node under the cursor
|
||||||
|
$node = $document->getNodeAtPosition($position);
|
||||||
|
if ($node === null) {
|
||||||
|
return new Hover([]);
|
||||||
|
}
|
||||||
|
$range = Range::fromNode($node);
|
||||||
|
// Get the definition node for whatever node is under the cursor
|
||||||
|
$def = $document->getDefinitionByNode($node);
|
||||||
|
if ($def === null) {
|
||||||
|
return new Hover([], $range);
|
||||||
|
}
|
||||||
|
$contents = [];
|
||||||
|
|
||||||
|
// Build a declaration string
|
||||||
|
if ($def instanceof Node\Stmt\PropertyProperty || $def instanceof Node\Const_) {
|
||||||
|
// Properties and constants can have multiple declarations
|
||||||
|
// Use the parent node (that includes the modifiers), but only render the requested declaration
|
||||||
|
$child = $def;
|
||||||
|
$def = $def->getAttribute('parentNode');
|
||||||
|
$defLine = clone $def;
|
||||||
|
$defLine->props = [$child];
|
||||||
|
} else {
|
||||||
|
$defLine = clone $def;
|
||||||
|
}
|
||||||
|
// Don't include the docblock in the declaration string
|
||||||
|
$defLine->setAttribute('comments', []);
|
||||||
|
if (isset($defLine->stmts)) {
|
||||||
|
$defLine->stmts = [];
|
||||||
|
}
|
||||||
|
$defText = $this->prettyPrinter->prettyPrint([$defLine]);
|
||||||
|
$lines = explode("\n", $defText);
|
||||||
|
if (isset($lines[0])) {
|
||||||
|
$contents[] = new MarkedString('php', "<?php\n" . $lines[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the documentation string
|
||||||
|
if ($def instanceof Node\Param) {
|
||||||
|
$fn = $def->getAttribute('parentNode');
|
||||||
|
$docBlock = $fn->getAttribute('docBlock');
|
||||||
|
if ($docBlock !== null) {
|
||||||
|
$tags = $docBlock->getTagsByName('param');
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if ($tag->getVariableName() === $def->name) {
|
||||||
|
$contents[] = $tag->getDescription()->render();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$docBlock = $def->getAttribute('docBlock');
|
||||||
|
if ($docBlock !== null) {
|
||||||
|
$contents[] = $docBlock->getSummary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Hover($contents, $range);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LanguageServerTest extends TestCase
|
||||||
'capabilities' => (object)[
|
'capabilities' => (object)[
|
||||||
'textDocumentSync' => TextDocumentSyncKind::FULL,
|
'textDocumentSync' => TextDocumentSyncKind::FULL,
|
||||||
'documentSymbolProvider' => true,
|
'documentSymbolProvider' => true,
|
||||||
'hoverProvider' => null,
|
'hoverProvider' => true,
|
||||||
'completionProvider' => null,
|
'completionProvider' => null,
|
||||||
'signatureHelpProvider' => null,
|
'signatureHelpProvider' => null,
|
||||||
'definitionProvider' => true,
|
'definitionProvider' => true,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
@ -9,13 +9,18 @@ use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{Position, Location, Range};
|
use LanguageServer\Protocol\{Position, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
abstract class TextDocumentTestCase extends TestCase
|
abstract class ServerTestCase extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Server\TextDocument
|
* @var Server\TextDocument
|
||||||
*/
|
*/
|
||||||
protected $textDocument;
|
protected $textDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Server\Workspace
|
||||||
|
*/
|
||||||
|
protected $workspace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Project
|
* @var Project
|
||||||
*/
|
*/
|
||||||
|
@ -40,12 +45,13 @@ abstract class TextDocumentTestCase extends TestCase
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
$client = new LanguageClient(new MockProtocolStream());
|
||||||
$this->project = new Project($client);
|
$this->project = new Project($client);
|
||||||
$this->textDocument = new Server\TextDocument($this->project, $client);
|
$this->textDocument = new Server\TextDocument($this->project, $client);
|
||||||
|
$this->workspace = new Server\Workspace($this->project, $client);
|
||||||
|
|
||||||
$globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_symbols.php'));
|
$globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
|
||||||
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/global_references.php'));
|
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/symbols.php'));
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/references.php'));
|
||||||
$useUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/use.php'));
|
$useUri = pathToUri(realpath(__DIR__ . '/../../fixtures/use.php'));
|
||||||
|
|
||||||
$this->project->loadDocument($symbolsUri);
|
$this->project->loadDocument($symbolsUri);
|
||||||
$this->project->loadDocument($referencesUri);
|
$this->project->loadDocument($referencesUri);
|
||||||
|
@ -56,48 +62,52 @@ abstract class TextDocumentTestCase extends TestCase
|
||||||
$this->definitionLocations = [
|
$this->definitionLocations = [
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 4, 6), new Position(4, 22))),
|
'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 9, 6), new Position( 9, 22))),
|
||||||
'TestClass' => new Location($globalSymbolsUri, new Range(new Position( 6, 0), new Position(21, 1))),
|
'TestClass' => new Location($globalSymbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
|
||||||
'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(28, 0), new Position(31, 1))),
|
'TestTrait' => new Location($globalSymbolsUri, new Range(new Position(63, 0), new Position(66, 1))),
|
||||||
'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position( 8, 10), new Position(8, 32))),
|
'TestInterface' => new Location($globalSymbolsUri, new Range(new Position(68, 0), new Position(71, 1))),
|
||||||
'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
'TestClass::TEST_CLASS_CONST' => new Location($globalSymbolsUri, new Range(new Position(27, 10), new Position(27, 32))),
|
||||||
'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
'TestClass::testProperty' => new Location($globalSymbolsUri, new Range(new Position(41, 11), new Position(41, 24))),
|
||||||
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
'TestClass::staticTestProperty' => new Location($globalSymbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
|
||||||
'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(17, 4), new Position(20, 5))),
|
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
|
||||||
'test_function()' => new Location($globalSymbolsUri, new Range(new Position(33, 0), new Position(36, 1))),
|
'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
|
||||||
|
'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
|
||||||
|
'whatever()' => new Location($globalReferencesUri, new Range(new Position(21, 0), new Position(23, 1))),
|
||||||
|
|
||||||
// Namespaced
|
// Namespaced
|
||||||
'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 4, 6), new Position(4, 22))),
|
'TestNamespace\\TEST_CONST' => new Location($symbolsUri, new Range(new Position( 9, 6), new Position( 9, 22))),
|
||||||
'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position( 6, 0), new Position(21, 1))),
|
'TestNamespace\\TestClass' => new Location($symbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
|
||||||
'TestNamespace\\TestInterface' => new Location($symbolsUri, new Range(new Position(28, 0), new Position(31, 1))),
|
'TestNamespace\\TestTrait' => new Location($symbolsUri, new Range(new Position(63, 0), new Position(66, 1))),
|
||||||
'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position( 8, 10), new Position(8, 32))),
|
'TestNamespace\\TestInterface' => new Location($symbolsUri, new Range(new Position(68, 0), new Position(71, 1))),
|
||||||
'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(10, 11), new Position(10, 24))),
|
'TestNamespace\\TestClass::TEST_CLASS_CONST' => new Location($symbolsUri, new Range(new Position(27, 10), new Position(27, 32))),
|
||||||
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position( 9, 18), new Position(9, 37))),
|
'TestNamespace\\TestClass::testProperty' => new Location($symbolsUri, new Range(new Position(41, 11), new Position(41, 24))),
|
||||||
'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(12, 4), new Position(15, 5))),
|
'TestNamespace\\TestClass::staticTestProperty' => new Location($symbolsUri, new Range(new Position(34, 18), new Position(34, 37))),
|
||||||
'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(17, 4), new Position(20, 5))),
|
'TestNamespace\\TestClass::staticTestMethod()' => new Location($symbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
|
||||||
'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(33, 0), new Position(36, 1)))
|
'TestNamespace\\TestClass::testMethod()' => new Location($symbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
|
||||||
|
'TestNamespace\\test_function()' => new Location($symbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
|
||||||
|
'TestNamespace\\whatever()' => new Location($referencesUri, new Range(new Position(21, 0), new Position(23, 1)))
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->referenceLocations = [
|
$this->referenceLocations = [
|
||||||
|
|
||||||
// Namespaced
|
// Namespaced
|
||||||
'TestNamespace\\TEST_CONST' => [
|
'TestNamespace\\TEST_CONST' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position(23, 5), new Position(23, 15)))
|
0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15)))
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestClass' => [
|
'TestNamespace\\TestClass' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
0 => new Location($referencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
||||||
1 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
1 => new Location($referencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
||||||
2 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
2 => new Location($referencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
||||||
3 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
3 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
||||||
4 => new Location($referencesUri, new Range(new Position(15, 18), new Position(15, 27))), // function whatever(TestClass $param)
|
4 => new Location($referencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
|
||||||
5 => new Location($referencesUri, new Range(new Position(15, 37), new Position(15, 46))), // function whatever(TestClass $param): TestClass
|
5 => new Location($referencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
|
||||||
6 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass;
|
6 => new Location($useUri, new Range(new Position( 4, 4), new Position( 4, 27))), // use TestNamespace\TestClass;
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestInterface' => [
|
'TestNamespace\\TestInterface' => [
|
||||||
0 => new Location($symbolsUri, new Range(new Position( 6, 27), new Position( 6, 40))) // class TestClass implements TestInterface
|
0 => new Location($symbolsUri, new Range(new Position(20, 27), new Position(20, 40))) // class TestClass implements TestInterface
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
|
'TestNamespace\\TestClass::TEST_CLASS_CONST' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position( 9, 16), new Position( 9, 32)))
|
0 => new Location($referencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
||||||
],
|
],
|
||||||
'TestNamespace\\TestClass::testProperty' => [
|
'TestNamespace\\TestClass::testProperty' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
0 => new Location($referencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
||||||
|
@ -117,22 +127,22 @@ abstract class TextDocumentTestCase extends TestCase
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
'TEST_CONST' => [
|
'TEST_CONST' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position(23, 5), new Position(23, 15))),
|
0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15))),
|
||||||
1 => new Location($globalReferencesUri, new Range(new Position(23, 5), new Position(23, 15)))
|
1 => new Location($globalReferencesUri, new Range(new Position(29, 5), new Position(29, 15)))
|
||||||
],
|
],
|
||||||
'TestClass' => [
|
'TestClass' => [
|
||||||
0 => new Location($globalReferencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
0 => new Location($globalReferencesUri, new Range(new Position( 4, 11), new Position( 4, 20))), // $obj = new TestClass();
|
||||||
1 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
1 => new Location($globalReferencesUri, new Range(new Position( 7, 0), new Position( 7, 9))), // TestClass::staticTestMethod();
|
||||||
2 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
2 => new Location($globalReferencesUri, new Range(new Position( 8, 5), new Position( 8, 14))), // echo TestClass::$staticTestProperty;
|
||||||
3 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
3 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 14))), // TestClass::TEST_CLASS_CONST;
|
||||||
4 => new Location($globalReferencesUri, new Range(new Position(15, 18), new Position(15, 27))), // function whatever(TestClass $param)
|
4 => new Location($globalReferencesUri, new Range(new Position(21, 18), new Position(21, 27))), // function whatever(TestClass $param)
|
||||||
5 => new Location($globalReferencesUri, new Range(new Position(15, 37), new Position(15, 46))), // function whatever(TestClass $param): TestClass
|
5 => new Location($globalReferencesUri, new Range(new Position(21, 37), new Position(21, 46))), // function whatever(TestClass $param): TestClass
|
||||||
],
|
],
|
||||||
'TestInterface' => [
|
'TestInterface' => [
|
||||||
0 => new Location($globalSymbolsUri, new Range(new Position( 6, 27), new Position( 6, 40))) // class TestClass implements TestInterface
|
0 => new Location($globalSymbolsUri, new Range(new Position(20, 27), new Position(20, 40))) // class TestClass implements TestInterface
|
||||||
],
|
],
|
||||||
'TestClass::TEST_CLASS_CONST' => [
|
'TestClass::TEST_CLASS_CONST' => [
|
||||||
0 => new Location($globalReferencesUri, new Range(new Position( 9, 16), new Position( 9, 32)))
|
0 => new Location($globalReferencesUri, new Range(new Position( 9, 5), new Position( 9, 32)))
|
||||||
],
|
],
|
||||||
'TestClass::testProperty' => [
|
'TestClass::testProperty' => [
|
||||||
0 => new Location($globalReferencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
0 => new Location($globalReferencesUri, new Range(new Position( 6, 5), new Position( 6, 23)))
|
|
@ -3,18 +3,13 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location};
|
||||||
|
|
||||||
class GlobalFallbackTest extends TestCase
|
class GlobalFallbackTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
$client = new LanguageClient(new MockProtocolStream());
|
||||||
|
@ -37,19 +32,7 @@ class GlobalFallbackTest extends TestCase
|
||||||
// echo TEST_CONST;
|
// echo TEST_CONST;
|
||||||
// Get definition for TEST_CONST
|
// Get definition for TEST_CONST
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(6, 10));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(6, 10));
|
||||||
$this->assertEquals([
|
$this->assertEquals(new Location('global_symbols', new Range(new Position(9, 6), new Position(9, 22))), $result);
|
||||||
'uri' => 'global_symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 6
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 4,
|
|
||||||
'character' => 22
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFallsBackForFunctions()
|
public function testFallsBackForFunctions()
|
||||||
|
@ -57,18 +40,6 @@ class GlobalFallbackTest extends TestCase
|
||||||
// test_function();
|
// test_function();
|
||||||
// Get definition for test_function
|
// Get definition for test_function
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(5, 6));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier('global_fallback'), new Position(5, 6));
|
||||||
$this->assertEquals([
|
$this->assertEquals(new Location('global_symbols', new Range(new Position(78, 0), new Position(81, 1))), $result);
|
||||||
'uri' => 'global_symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 33,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 36,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
namespace LanguageServer\Tests\Server\TextDocument\Definition;
|
||||||
|
|
||||||
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends TextDocumentTestCase
|
class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testDefinitionFileBeginning() {
|
public function testDefinitionFileBeginning() {
|
||||||
// |<?php
|
// |<?php
|
||||||
|
@ -32,7 +32,7 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
|
|
||||||
public function testDefinitionForClassOnStaticMethodCall()
|
public function testDefinitionForClassOnStaticMethodCall()
|
||||||
{
|
{
|
||||||
// $obj = new TestClass();
|
// TestClass::staticTestMethod();
|
||||||
// Get definition for TestClass
|
// Get definition for TestClass
|
||||||
$reference = $this->getReferenceLocations('TestClass')[1];
|
$reference = $this->getReferenceLocations('TestClass')[1];
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
|
@ -71,7 +71,7 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// echo TestClass::TEST_CLASS_CONST;
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
// Get definition for TEST_CLASS_CONST
|
// Get definition for TEST_CLASS_CONST
|
||||||
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
$this->assertEquals($this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +152,8 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// echo $param;
|
// echo $param;
|
||||||
// Get definition for $param
|
// Get definition for $param
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(16, 13));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(22, 13));
|
||||||
$this->assertEquals(new Location($uri, new Range(new Position(15, 18), new Position(15, 34))), $result);
|
$this->assertEquals(new Location($uri, new Range(new Position(21, 18), new Position(21, 34))), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForUsedVariables()
|
public function testDefinitionForUsedVariables()
|
||||||
|
@ -161,8 +161,8 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// echo $var;
|
// echo $var;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(20, 11));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier($uri), new Position(26, 11));
|
||||||
$this->assertEquals(new Location($uri, new Range(new Position(19, 22), new Position(19, 26))), $result);
|
$this->assertEquals(new Location($uri, new Range(new Position(25, 22), new Position(25, 26))), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionForFunctions()
|
public function testDefinitionForFunctions()
|
||||||
|
|
|
@ -3,211 +3,30 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\TextDocument;
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolKind};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolInformation, SymbolKind, Position, Location, Range};
|
||||||
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class DocumentSymbolTest extends TestCase
|
class DocumentSymbolTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Server\TextDocument
|
|
||||||
*/
|
|
||||||
private $textDocument;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
|
||||||
$project = new Project($client);
|
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
|
||||||
$project->openDocument('symbols', file_get_contents(__DIR__ . '/../../../fixtures/symbols.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test()
|
public function test()
|
||||||
{
|
{
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier('symbols'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
||||||
|
$result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri));
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
[
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
|
||||||
'name' => 'TEST_CONST',
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
|
||||||
'kind' => SymbolKind::CONSTANT,
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
|
||||||
'location' => [
|
new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
|
||||||
'uri' => 'symbols',
|
new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
|
||||||
'range' => [
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'start' => [
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'line' => 4,
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
|
||||||
'character' => 6
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
|
||||||
],
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
|
||||||
'end' => [
|
], $result);
|
||||||
'line' => 4,
|
|
||||||
'character' => 22
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TestClass',
|
|
||||||
'kind' => SymbolKind::CLASS_,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TEST_CLASS_CONST',
|
|
||||||
'kind' => SymbolKind::CONSTANT,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 10
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'staticTestProperty',
|
|
||||||
'kind' => SymbolKind::FIELD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 37
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'testProperty',
|
|
||||||
'kind' => SymbolKind::FIELD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 24
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'staticTestMethod',
|
|
||||||
'kind' => SymbolKind::METHOD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'testMethod',
|
|
||||||
'kind' => SymbolKind::METHOD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TestTrait',
|
|
||||||
'kind' => SymbolKind::CLASS_,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 26,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TestInterface',
|
|
||||||
'kind' => SymbolKind::INTERFACE,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 28,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 31,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'test_function',
|
|
||||||
'kind' => SymbolKind::FUNCTION,
|
|
||||||
'location' => [
|
|
||||||
'uri' => 'symbols',
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 33,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 36,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace LanguageServer\Tests\Server\TextDocument;
|
||||||
|
|
||||||
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Hover, MarkedString};
|
||||||
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
|
class HoverTest extends ServerTestCase
|
||||||
|
{
|
||||||
|
public function testHoverForClassLike()
|
||||||
|
{
|
||||||
|
// $obj = new TestClass();
|
||||||
|
// Get hover for TestClass
|
||||||
|
$reference = $this->getReferenceLocations('TestClass')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->start);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
||||||
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForMethod()
|
||||||
|
{
|
||||||
|
// $obj->testMethod();
|
||||||
|
// Get hover for testMethod
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::testMethod()')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\npublic function testMethod(\$testParameter)"),
|
||||||
|
'Non culpa nostrud mollit esse sunt laboris in irure ullamco cupidatat amet.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForProperty()
|
||||||
|
{
|
||||||
|
// echo $obj->testProperty;
|
||||||
|
// Get hover for testProperty
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::testProperty')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\npublic \$testProperty;"),
|
||||||
|
'Reprehenderit magna velit mollit ipsum do.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForStaticMethod()
|
||||||
|
{
|
||||||
|
// TestClass::staticTestMethod();
|
||||||
|
// Get hover for staticTestMethod
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::staticTestMethod()')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\npublic static function staticTestMethod()"),
|
||||||
|
'Do magna consequat veniam minim proident eiusmod incididunt aute proident.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForStaticProperty()
|
||||||
|
{
|
||||||
|
// echo TestClass::staticTestProperty;
|
||||||
|
// Get hover for staticTestProperty
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::staticTestProperty')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\npublic static \$staticTestProperty;"),
|
||||||
|
'Lorem excepteur officia sit anim velit veniam enim.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForClassConstant()
|
||||||
|
{
|
||||||
|
// echo TestClass::TEST_CLASS_CONST;
|
||||||
|
// Get hover for TEST_CLASS_CONST
|
||||||
|
$reference = $this->getReferenceLocations('TestClass::TEST_CLASS_CONST')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\nconst TEST_CLASS_CONST = 123;"),
|
||||||
|
'Anim labore veniam consectetur laboris minim quis aute aute esse nulla ad.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForFunction()
|
||||||
|
{
|
||||||
|
// test_function();
|
||||||
|
// Get hover for test_function
|
||||||
|
$reference = $this->getReferenceLocations('test_function()')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\nfunction test_function()"),
|
||||||
|
'Officia aliquip adipisicing et nulla et laboris dolore labore.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForConstant()
|
||||||
|
{
|
||||||
|
// echo TEST_CONST;
|
||||||
|
// Get hover for TEST_CONST
|
||||||
|
$reference = $this->getReferenceLocations('TEST_CONST')[0];
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($reference->uri), $reference->range->end);
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\nconst TEST_CONST = 123;"),
|
||||||
|
'Esse commodo excepteur pariatur Lorem est aute incididunt reprehenderit.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForVariable()
|
||||||
|
{
|
||||||
|
// echo $var;
|
||||||
|
// Get hover for $var
|
||||||
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(13, 7));
|
||||||
|
$this->assertEquals(new Hover(
|
||||||
|
[new MarkedString('php', "<?php\n\$var = 123;")],
|
||||||
|
new Range(new Position(13, 5), new Position(13, 9))
|
||||||
|
), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHoverForParam()
|
||||||
|
{
|
||||||
|
// echo $param;
|
||||||
|
// Get hover for $param
|
||||||
|
$uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(22, 11));
|
||||||
|
$this->assertEquals(new Hover(
|
||||||
|
[
|
||||||
|
new MarkedString('php', "<?php\n\TestNamespace\TestClass \$param"),
|
||||||
|
'Adipisicing non non cillum sint incididunt cillum enim mollit.'
|
||||||
|
],
|
||||||
|
new Range(new Position(22, 9), new Position(22, 15))
|
||||||
|
), $result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase;
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
use LanguageServer\{Server, LanguageClient, Project};
|
use LanguageServer\{Server, LanguageClient, Project};
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
|
|
||||||
class GlobalFallbackTest extends TextDocumentTestCase
|
class GlobalFallbackTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ class GlobalFallbackTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
// const TEST_CONST = 123;
|
// const TEST_CONST = 123;
|
||||||
// Get references for TEST_CONST
|
// Get references for TEST_CONST
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(4, 13));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(9, 13));
|
||||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(6, 5), new Position(6, 15)))], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class GlobalFallbackTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
// function test_function()
|
// function test_function()
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(33, 16));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier('global_symbols'), new Position(78, 16));
|
||||||
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
$this->assertEquals([new Location('global_fallback', new Range(new Position(5, 0), new Position(5, 13)))], $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Tests\Server\TextDocument\References;
|
namespace LanguageServer\Tests\Server\TextDocument\References;
|
||||||
|
|
||||||
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
|
||||||
use LanguageServer\Tests\Server\TextDocument\TextDocumentTestCase;
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends TextDocumentTestCase
|
class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testReferencesForClassLike()
|
public function testReferencesForClassLike()
|
||||||
{
|
{
|
||||||
|
@ -22,9 +22,9 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
{
|
{
|
||||||
// const TEST_CLASS_CONST = 123;
|
// const TEST_CLASS_CONST = 123;
|
||||||
// Get references for TEST_CLASS_CONST
|
// Get references for TEST_CLASS_CONST
|
||||||
$definition = $this->getDefinitionLocation('TestClass');
|
$definition = $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST');
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($definition->uri), $definition->range->start);
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass::TEST_CLASS_CONST'), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForConstants()
|
public function testReferencesForConstants()
|
||||||
|
@ -77,11 +77,11 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// $var = 123;
|
// $var = 123;
|
||||||
// Get definition for $var
|
// Get definition for $var
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(13, 7));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(12, 3));
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
|
new Location($uri, new Range(new Position(12, 0), new Position(12, 4))),
|
||||||
new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
|
new Location($uri, new Range(new Position(13, 5), new Position(13, 9))),
|
||||||
new Location($uri, new Range(new Position(20, 9), new Position(20, 13)))
|
new Location($uri, new Range(new Position(26, 9), new Position(26, 13)))
|
||||||
], $result);
|
], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// function whatever(TestClass $param): TestClass
|
// function whatever(TestClass $param): TestClass
|
||||||
// Get references for $param
|
// Get references for $param
|
||||||
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$uri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(15, 32));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($uri), new Position(21, 32));
|
||||||
$this->assertEquals([new Location($uri, new Range(new Position(16, 9), new Position(16, 15)))], $result);
|
$this->assertEquals([new Location($uri, new Range(new Position(22, 9), new Position(22, 15)))], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReferencesForFunctions()
|
public function testReferencesForFunctions()
|
||||||
|
@ -100,7 +100,7 @@ class GlobalTest extends TextDocumentTestCase
|
||||||
// Get references for test_function
|
// Get references for test_function
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'));
|
||||||
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/symbols.php'));
|
||||||
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(33, 16));
|
$result = $this->textDocument->references(new ReferenceContext, new TextDocumentIdentifier($symbolsUri), new Position(78, 16));
|
||||||
$this->assertEquals([new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))], $result);
|
$this->assertEquals([new Location($referencesUri, new Range(new Position(10, 0), new Position(10, 13)))], $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,245 +3,45 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\Workspace;
|
namespace LanguageServer\Tests\Server\Workspace;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
|
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
|
||||||
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolKind, DiagnosticSeverity, FormattingOptions};
|
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, SymbolInformation, SymbolKind, DiagnosticSeverity, FormattingOptions};
|
||||||
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
|
||||||
use function LanguageServer\pathToUri;
|
use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class SymbolTest extends TestCase
|
class SymbolTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var LanguageServer\Workspace $workspace
|
|
||||||
*/
|
|
||||||
private $workspace;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $symbolsUri;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $referencesUri;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
$client = new LanguageClient(new MockProtocolStream());
|
|
||||||
$project = new Project($client);
|
|
||||||
$this->workspace = new Server\Workspace($project, $client);
|
|
||||||
$this->symbolsUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php'));
|
|
||||||
$this->referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
|
||||||
$project->loadDocument($this->symbolsUri);
|
|
||||||
$project->loadDocument($this->referencesUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEmptyQueryReturnsAllSymbols()
|
public function testEmptyQueryReturnsAllSymbols()
|
||||||
{
|
{
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->workspace->symbol('');
|
$result = $this->workspace->symbol('');
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
[
|
// Namespaced
|
||||||
'name' => 'TEST_CONST',
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'),
|
||||||
'kind' => SymbolKind::CONSTANT,
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'),
|
||||||
'location' => [
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TestClass::TEST_CLASS_CONST'), 'TestNamespace\\TestClass'),
|
||||||
'uri' => $this->symbolsUri,
|
new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestProperty'), 'TestNamespace\\TestClass'),
|
||||||
'range' => [
|
new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestNamespace\\TestClass::testProperty'), 'TestNamespace\\TestClass'),
|
||||||
'start' => [
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'line' => 4,
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'character' => 6
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestTrait'), 'TestNamespace'),
|
||||||
],
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'),
|
||||||
'end' => [
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'),
|
||||||
'line' => 4,
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\whatever()'), 'TestNamespace'),
|
||||||
'character' => 22
|
// Global
|
||||||
]
|
new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_CONST'), ''),
|
||||||
]
|
new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestClass'), ''),
|
||||||
],
|
new SymbolInformation('TEST_CLASS_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestClass::TEST_CLASS_CONST'), 'TestClass'),
|
||||||
'containerName' => 'TestNamespace'
|
new SymbolInformation('staticTestProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestClass::staticTestProperty'), 'TestClass'),
|
||||||
],
|
new SymbolInformation('testProperty', SymbolKind::FIELD, $this->getDefinitionLocation('TestClass::testProperty'), 'TestClass'),
|
||||||
[
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
|
||||||
'name' => 'TestClass',
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass'),
|
||||||
'kind' => SymbolKind::CLASS_,
|
new SymbolInformation('TestTrait', SymbolKind::CLASS_, $this->getDefinitionLocation('TestTrait'), ''),
|
||||||
'location' => [
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
|
||||||
'uri' => $this->symbolsUri,
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
|
||||||
'range' => [
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), '')
|
||||||
'start' => [
|
], $result);
|
||||||
'line' => 6,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 21,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TEST_CLASS_CONST',
|
|
||||||
'kind' => SymbolKind::CONSTANT,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 10
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 8,
|
|
||||||
'character' => 32
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'staticTestProperty',
|
|
||||||
'kind' => SymbolKind::FIELD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 18
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 9,
|
|
||||||
'character' => 37
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'testProperty',
|
|
||||||
'kind' => SymbolKind::FIELD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 11
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 10,
|
|
||||||
'character' => 24
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'staticTestMethod',
|
|
||||||
'kind' => SymbolKind::METHOD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'testMethod',
|
|
||||||
'kind' => SymbolKind::METHOD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TestTrait',
|
|
||||||
'kind' => SymbolKind::CLASS_,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 23,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 26,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'TestInterface',
|
|
||||||
'kind' => SymbolKind::INTERFACE,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 28,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 31,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'test_function',
|
|
||||||
'kind' => SymbolKind::FUNCTION,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 33,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 36,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'whatever',
|
|
||||||
'kind' => SymbolKind::FUNCTION,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->referencesUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 0
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 1
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace'
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryFiltersResults()
|
public function testQueryFiltersResults()
|
||||||
|
@ -249,42 +49,10 @@ class SymbolTest extends TestCase
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->workspace->symbol('testmethod');
|
$result = $this->workspace->symbol('testmethod');
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
[
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'name' => 'staticTestMethod',
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'),
|
||||||
'kind' => SymbolKind::METHOD,
|
new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'),
|
||||||
'location' => [
|
new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass')
|
||||||
'uri' => $this->symbolsUri,
|
], $result);
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 12,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 15,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'testMethod',
|
|
||||||
'kind' => SymbolKind::METHOD,
|
|
||||||
'location' => [
|
|
||||||
'uri' => $this->symbolsUri,
|
|
||||||
'range' => [
|
|
||||||
'start' => [
|
|
||||||
'line' => 17,
|
|
||||||
'character' => 4
|
|
||||||
],
|
|
||||||
'end' => [
|
|
||||||
'line' => 20,
|
|
||||||
'character' => 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'containerName' => 'TestNamespace\\TestClass'
|
|
||||||
]
|
|
||||||
], json_decode(json_encode($result), true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue