Merge 1b9d870eff
into de6aed608c
commit
54843d9030
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace HELLO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does something really cool!
|
||||||
|
*/
|
||||||
|
function world() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
\HE
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lorem ipsum dolor sit amet.
|
||||||
|
*/
|
||||||
|
define('HELLO', true);
|
||||||
|
|
||||||
|
HELLO\world();
|
||||||
|
}
|
|
@ -98,3 +98,10 @@ new class {
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChildClass extends TestClass {}
|
class ChildClass extends TestClass {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lorem ipsum dolor sit amet, consectetur.
|
||||||
|
*/
|
||||||
|
define('TEST_PROPERTY', false);
|
||||||
|
|
||||||
|
print TEST_PROPERTY ? 'true' : 'false';
|
||||||
|
|
|
@ -732,10 +732,12 @@ class DefinitionResolver
|
||||||
// Use @param tag
|
// Use @param tag
|
||||||
foreach ($docBlock->getTagsByName('param') as $paramTag) {
|
foreach ($docBlock->getTagsByName('param') as $paramTag) {
|
||||||
if ($paramTag->getVariableName() === $node->name) {
|
if ($paramTag->getVariableName() === $node->name) {
|
||||||
if ($paramTag->getType() === null) {
|
$type = $paramTag->getType();
|
||||||
|
|
||||||
|
if ($type === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $paramTag->getType();
|
return $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,6 +761,41 @@ class DefinitionResolver
|
||||||
}
|
}
|
||||||
return $type ?? new Types\Mixed;
|
return $type ?? new Types\Mixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($node instanceof Node\Var_) {
|
||||||
|
$docBlock = $node->getAttribute('docBlock');
|
||||||
|
if ($docBlock !== null) {
|
||||||
|
// use @var tag
|
||||||
|
foreach ($docBlock->getTagsByName('var') as $varTag) {
|
||||||
|
$type = $varTag->getType();
|
||||||
|
|
||||||
|
if ($type === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$type = null;
|
||||||
|
if ($node->type !== null) {
|
||||||
|
// Use PHP7 return type hint
|
||||||
|
if (is_string($node->type)) {
|
||||||
|
// Resolve a string like "bool" to a type object
|
||||||
|
$type = $this->typeResolver->resolve($node->type);
|
||||||
|
} else {
|
||||||
|
$type = new Types\Object_(new Fqsen('\\' . (string)$node->type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($node->default !== null) {
|
||||||
|
$defaultType = $this->resolveExpressionNodeToType($node->default);
|
||||||
|
if (isset($type) && !is_a($type, get_class($defaultType))) {
|
||||||
|
$type = new Types\Compound([$type, $defaultType]);
|
||||||
|
} else {
|
||||||
|
$type = $defaultType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $type ?? new Types\Mixed;
|
||||||
|
}
|
||||||
|
|
||||||
if ($node instanceof Node\FunctionLike) {
|
if ($node instanceof Node\FunctionLike) {
|
||||||
// Functions/methods
|
// Functions/methods
|
||||||
$docBlock = $node->getAttribute('docBlock');
|
$docBlock = $node->getAttribute('docBlock');
|
||||||
|
@ -882,6 +919,11 @@ class DefinitionResolver
|
||||||
}
|
}
|
||||||
return (string)$class->namespacedName . '::' . $node->name;
|
return (string)$class->namespacedName . '::' . $node->name;
|
||||||
}
|
}
|
||||||
|
} else if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && strtolower((string)$node->name) === 'define') {
|
||||||
|
if (!isset($node->args[0]) || !($node->args[0]->value instanceof Node\Scalar\String_)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (string)$node->args[0]->value->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ class Index implements ReadableIndex, \Serializable
|
||||||
* Registers a definition
|
* Registers a definition
|
||||||
*
|
*
|
||||||
* @param string $fqn The fully qualified name of the symbol
|
* @param string $fqn The fully qualified name of the symbol
|
||||||
* @param string $definition The Definition object
|
* @param Definition $definition The Definition object
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setDefinition(string $fqn, Definition $definition)
|
public function setDefinition(string $fqn, Definition $definition)
|
||||||
|
|
|
@ -50,9 +50,18 @@ class SymbolInformation
|
||||||
{
|
{
|
||||||
$parent = $node->getAttribute('parentNode');
|
$parent = $node->getAttribute('parentNode');
|
||||||
$symbol = new self;
|
$symbol = new self;
|
||||||
if ($node instanceof Node\Stmt\Class_) {
|
if (
|
||||||
$symbol->kind = SymbolKind::CLASS_;
|
$node instanceof Node\Expr\FuncCall
|
||||||
} else if ($node instanceof Node\Stmt\Trait_) {
|
&& $node->name instanceof Node\Name
|
||||||
|
&& strtolower((string)$node->name) === 'define'
|
||||||
|
&& isset($node->args[0])
|
||||||
|
&& $node->args[0]->value instanceof Node\Scalar\String_
|
||||||
|
) {
|
||||||
|
// constants with define() like
|
||||||
|
// define('TEST_PROPERTY', true);
|
||||||
|
$symbol->kind = SymbolKind::CONSTANT;
|
||||||
|
$symbol->name = (string)$node->args[0]->value->value;
|
||||||
|
} else if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) {
|
||||||
$symbol->kind = SymbolKind::CLASS_;
|
$symbol->kind = SymbolKind::CLASS_;
|
||||||
} else if ($node instanceof Node\Stmt\Interface_) {
|
} else if ($node instanceof Node\Stmt\Interface_) {
|
||||||
$symbol->kind = SymbolKind::INTERFACE;
|
$symbol->kind = SymbolKind::INTERFACE;
|
||||||
|
|
|
@ -57,7 +57,7 @@ class LanguageServerTest extends TestCase
|
||||||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
if ($msg->body->params->type === MessageType::ERROR) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$promise->reject(new Exception($msg->body->params->message));
|
||||||
} else if (strpos($msg->body->params->message, 'All 26 PHP files parsed') !== false) {
|
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
|
||||||
$promise->fulfill();
|
$promise->fulfill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ class LanguageServerTest extends TestCase
|
||||||
if ($promise->state === Promise::PENDING) {
|
if ($promise->state === Promise::PENDING) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$promise->reject(new Exception($msg->body->params->message));
|
||||||
}
|
}
|
||||||
} else if (strpos($msg->body->params->message, 'All 26 PHP files parsed') !== false) {
|
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
|
||||||
$promise->fulfill();
|
$promise->fulfill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ abstract class ServerTestCase extends TestCase
|
||||||
$this->definitionLocations = [
|
$this->definitionLocations = [
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
|
'TEST_PROPERTY' => new Location($globalSymbolsUri, new Range(new Position(104, 0), new Position(104, 30))),
|
||||||
'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 9, 6), new Position( 9, 22))),
|
'TEST_CONST' => new Location($globalSymbolsUri, new Range(new Position( 9, 6), new Position( 9, 22))),
|
||||||
'TestClass' => new Location($globalSymbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
|
'TestClass' => new Location($globalSymbolsUri, new Range(new Position(20, 0), new Position(61, 1))),
|
||||||
'ChildClass' => new Location($globalSymbolsUri, new Range(new Position(99, 0), new Position(99, 37))),
|
'ChildClass' => new Location($globalSymbolsUri, new Range(new Position(99, 0), new Position(99, 37))),
|
||||||
|
@ -163,6 +164,9 @@ abstract class ServerTestCase extends TestCase
|
||||||
],
|
],
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
|
'TEST_PROPERTY' => [
|
||||||
|
0 => new Location($globalSymbolsUri, new Range(new Position(106, 6), new Position(106, 19)))
|
||||||
|
],
|
||||||
'TEST_CONST' => [
|
'TEST_CONST' => [
|
||||||
0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15))),
|
0 => new Location($referencesUri, new Range(new Position(29, 5), new Position(29, 15))),
|
||||||
1 => new Location($globalReferencesUri, new Range(new Position(29, 5), new Position(29, 15)))
|
1 => new Location($globalReferencesUri, new Range(new Position(29, 5), new Position(29, 15)))
|
||||||
|
|
|
@ -156,6 +156,21 @@ class HoverTest extends ServerTestCase
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHoverForGlobalConstant()
|
||||||
|
{
|
||||||
|
// print TEST_PROPERTY ? 'true' : 'false';
|
||||||
|
// Get hover for TEST_PROPERTY
|
||||||
|
$reference = $this->getReferenceLocations('TEST_PROPERTY')[0];
|
||||||
|
$result = $this->textDocument->hover(
|
||||||
|
new TextDocumentIdentifier($reference->uri),
|
||||||
|
$reference->range->end
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals(new Hover([
|
||||||
|
new MarkedString('php', "<?php\n\\define('TEST_PROPERTY', \\false);"),
|
||||||
|
'Lorem ipsum dolor sit amet, consectetur.'
|
||||||
|
], $reference->range), $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testHoverForVariable()
|
public function testHoverForVariable()
|
||||||
{
|
{
|
||||||
// echo $var;
|
// echo $var;
|
||||||
|
|
|
@ -58,6 +58,7 @@ class SymbolTest extends ServerTestCase
|
||||||
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
|
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
|
||||||
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
|
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
|
||||||
new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''),
|
new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''),
|
||||||
|
new SymbolInformation('define', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_PROPERTY'), ''),
|
||||||
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''),
|
new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), ''),
|
||||||
|
|
||||||
new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), '')
|
new SymbolInformation('SecondTestNamespace', SymbolKind::NAMESPACE, $this->getDefinitionLocation('SecondTestNamespace'), '')
|
||||||
|
|
Loading…
Reference in New Issue