1
0
Fork 0

rename test constant and fix name gets renamed bug

pull/347/head
jens1o 2017-04-17 12:15:46 +02:00
parent 503cc6bcff
commit 76e7170f15
5 changed files with 48 additions and 41 deletions

View File

@ -102,6 +102,6 @@ class ChildClass extends TestClass {}
/** /**
* Lorem ipsum dolor sit amet, consectetur. * Lorem ipsum dolor sit amet, consectetur.
*/ */
define('TEST_PROPERTY', false); define('TEST_DEFINE_CONSTANT', false);
print TEST_PROPERTY ? 'true' : 'false'; print TEST_DEFINE_CONSTANT ? 'true' : 'false';

View File

@ -58,9 +58,8 @@ class SymbolInformation
&& $node->args[0]->value instanceof Node\Scalar\String_ && $node->args[0]->value instanceof Node\Scalar\String_
) { ) {
// constants with define() like // constants with define() like
// define('TEST_PROPERTY', true); // define('TEST_DEFINE_CONSTANT', false);
$symbol->kind = SymbolKind::CONSTANT; $symbol->kind = SymbolKind::CONSTANT;
$symbol->name = (string)$node->args[0]->value->value;
} else if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) { } 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_) {
@ -91,6 +90,14 @@ class SymbolInformation
} }
if ($node instanceof Node\Name) { if ($node instanceof Node\Name) {
$symbol->name = (string)$node; $symbol->name = (string)$node;
} else if(
$node instanceof Node\Expr\FuncCall
&& $node->name instanceof Node\Name
&& strtolower((string)$node->name) === 'define'
&& isset($node->args[0])
&& $node->args[0]->value instanceof Node\Scalar\String_
) {
$symbol->name = (string)$node->args[0]->value->value;
} else if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignOp) { } else if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignOp) {
$symbol->name = $node->var->name; $symbol->name = $node->var->name;
} else if ($node instanceof Node\Expr\ClosureUse) { } else if ($node instanceof Node\Expr\ClosureUse) {

View File

@ -72,7 +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_DEFINE_CONSTANT' => new Location($globalSymbolsUri, new Range(new Position(104, 0), new Position(104, 37))),
'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))),
@ -164,8 +164,8 @@ abstract class ServerTestCase extends TestCase
], ],
// Global // Global
'TEST_PROPERTY' => [ 'TEST_DEFINE_CONSTANT' => [
0 => new Location($globalSymbolsUri, new Range(new Position(106, 6), new Position(106, 19))) 0 => new Location($globalSymbolsUri, new Range(new Position(106, 6), new Position(106, 26)))
], ],
'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))),

View File

@ -158,15 +158,15 @@ class HoverTest extends ServerTestCase
public function testHoverForGlobalConstant() public function testHoverForGlobalConstant()
{ {
// print TEST_PROPERTY ? 'true' : 'false'; // print TEST_DEFINE_CONSTANT ? 'true' : 'false';
// Get hover for TEST_PROPERTY // Get hover for TEST_DEFINE_CONSTANT
$reference = $this->getReferenceLocations('TEST_PROPERTY')[0]; $reference = $this->getReferenceLocations('TEST_DEFINE_CONSTANT')[0];
$result = $this->textDocument->hover( $result = $this->textDocument->hover(
new TextDocumentIdentifier($reference->uri), new TextDocumentIdentifier($reference->uri),
$reference->range->end $reference->range->end
)->wait(); )->wait();
$this->assertEquals(new Hover([ $this->assertEquals(new Hover([
new MarkedString('php', "<?php\n\\define('TEST_PROPERTY', \\false);"), new MarkedString('php', "<?php\n\\define('TEST_DEFINE_CONSTANT', \\false);"),
'Lorem ipsum dolor sit amet, consectetur.' 'Lorem ipsum dolor sit amet, consectetur.'
], $reference->range), $result); ], $reference->range), $result);
} }

View File

@ -58,7 +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('TEST_DEFINE_CONSTANT', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'), ''),
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'), '')