mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add ability to Go to Definition on Use statements (#3805)
This adds the ability to use the LSP's "Go to Definition" on `use MyClass` statements. Co-authored-by: Matthew Brown <github@muglug.com>
This commit is contained in:
parent
0b6d682964
commit
b8c4abf08b
@ -63,6 +63,12 @@ trait CanAlias
|
||||
break;
|
||||
|
||||
case PhpParser\Node\Stmt\Use_::TYPE_NORMAL:
|
||||
$codebase->analyzer->addOffsetReference(
|
||||
$this->getFilePath(),
|
||||
(int) $use->getAttribute('startFilePos'),
|
||||
(int) $use->getAttribute('endFilePos'),
|
||||
$use_path
|
||||
);
|
||||
if ($codebase->collect_locations) {
|
||||
// register the path
|
||||
$codebase->use_referencing_locations[strtolower($use_path)][] =
|
||||
|
@ -337,6 +337,33 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase
|
||||
$this->assertSame('B\AClass', $symbol_at_position[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSymbolPositionUseStatement()
|
||||
{
|
||||
$codebase = $this->project_analyzer->getCodebase();
|
||||
$config = $codebase->config;
|
||||
$config->throw_exception = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
namespace B;
|
||||
use StreamWrapper;
|
||||
'
|
||||
);
|
||||
|
||||
$codebase->file_provider->openFile('somefile.php');
|
||||
$codebase->scanFiles();
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
|
||||
$symbol_at_position = $codebase->getReferenceAtPosition('somefile.php', new Position(2, 25));
|
||||
$this->assertNotNull($symbol_at_position);
|
||||
|
||||
$this->assertSame('StreamWrapper', $symbol_at_position[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user