Fix 'find references' for unused symbols (#392)
* Add tests for unused symbols * Fix tests for unused symbolspull/396/head^2
parent
f10680e441
commit
cc3f0da21a
|
@ -105,3 +105,15 @@ class ChildClass extends TestClass {}
|
||||||
define('TEST_DEFINE_CONSTANT', false);
|
define('TEST_DEFINE_CONSTANT', false);
|
||||||
|
|
||||||
print TEST_DEFINE_CONSTANT ? 'true' : 'false';
|
print TEST_DEFINE_CONSTANT ? 'true' : 'false';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neither this class nor its members are referenced anywhere
|
||||||
|
*/
|
||||||
|
class UnusedClass
|
||||||
|
{
|
||||||
|
public $unusedProperty;
|
||||||
|
|
||||||
|
public function unusedMethod()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -85,6 +85,9 @@ abstract class ServerTestCase extends TestCase
|
||||||
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
|
'TestClass::staticTestMethod()' => new Location($globalSymbolsUri, new Range(new Position(46, 4), new Position(49, 5))),
|
||||||
'TestClass::testMethod()' => new Location($globalSymbolsUri, new Range(new Position(57, 4), new Position(60, 5))),
|
'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))),
|
'test_function()' => new Location($globalSymbolsUri, new Range(new Position(78, 0), new Position(81, 1))),
|
||||||
|
'UnusedClass' => new Location($globalSymbolsUri, new Range(new Position(111, 0), new Position(118, 1))),
|
||||||
|
'UnusedClass::unusedProperty' => new Location($globalSymbolsUri, new Range(new Position(113,11), new Position(113, 26))),
|
||||||
|
'UnusedClass::unusedMethod' => new Location($globalSymbolsUri, new Range(new Position(115, 4), new Position(117, 5))),
|
||||||
'whatever()' => new Location($globalReferencesUri, new Range(new Position(21, 0), new Position(23, 1))),
|
'whatever()' => new Location($globalReferencesUri, new Range(new Position(21, 0), new Position(23, 1))),
|
||||||
|
|
||||||
// Namespaced
|
// Namespaced
|
||||||
|
|
|
@ -159,4 +159,43 @@ class GlobalTest extends ServerTestCase
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
$this->assertEquals($this->getReferenceLocations('TestClass'), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReferencesForUnusedClass()
|
||||||
|
{
|
||||||
|
// class UnusedClass
|
||||||
|
// Get references for UnusedClass
|
||||||
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
|
$result = $this->textDocument->references(
|
||||||
|
new ReferenceContext,
|
||||||
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
|
new Position(111, 10)
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReferencesForUnusedProperty()
|
||||||
|
{
|
||||||
|
// public $unusedProperty
|
||||||
|
// Get references for unusedProperty
|
||||||
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
|
$result = $this->textDocument->references(
|
||||||
|
new ReferenceContext,
|
||||||
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
|
new Position(113, 18)
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReferencesForUnusedMethod()
|
||||||
|
{
|
||||||
|
// public function unusedMethod()
|
||||||
|
// Get references for unusedMethod
|
||||||
|
$symbolsUri = pathToUri(realpath(__DIR__ . '/../../../../fixtures/global_symbols.php'));
|
||||||
|
$result = $this->textDocument->references(
|
||||||
|
new ReferenceContext,
|
||||||
|
new TextDocumentIdentifier($symbolsUri),
|
||||||
|
new Position(115, 26)
|
||||||
|
)->wait();
|
||||||
|
$this->assertEquals([], $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class SymbolTest extends ServerTestCase
|
||||||
// Request symbols
|
// Request symbols
|
||||||
$result = $this->workspace->symbol('')->wait();
|
$result = $this->workspace->symbol('')->wait();
|
||||||
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
$referencesUri = pathToUri(realpath(__DIR__ . '/../../../fixtures/references.php'));
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''),
|
new SymbolInformation('TestNamespace', SymbolKind::NAMESPACE, new Location($referencesUri, new Range(new Position(2, 0), new Position(2, 24))), ''),
|
||||||
|
@ -59,9 +60,12 @@ class SymbolTest extends ServerTestCase
|
||||||
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('TEST_DEFINE_CONSTANT', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'), ''),
|
new SymbolInformation('TEST_DEFINE_CONSTANT', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_DEFINE_CONSTANT'), ''),
|
||||||
|
new SymbolInformation('UnusedClass', SymbolKind::CLASS_, $this->getDefinitionLocation('UnusedClass'), ''),
|
||||||
|
new SymbolInformation('unusedProperty', SymbolKind::PROPERTY, $this->getDefinitionLocation('UnusedClass::unusedProperty'), 'UnusedClass'),
|
||||||
|
new SymbolInformation('unusedMethod', SymbolKind::METHOD, $this->getDefinitionLocation('UnusedClass::unusedMethod'), 'UnusedClass'),
|
||||||
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'), ''),
|
||||||
], $result);
|
], $result);
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue