1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +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:
Joe Hoyle 2020-07-11 23:16:44 +02:00 committed by GitHub
parent 0b6d682964
commit b8c4abf08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -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)][] =

View File

@ -336,6 +336,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