Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to Go to Definition on Use statements #3805

Merged
merged 2 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Psalm/Internal/Analyzer/CanAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public function visitUse(PhpParser\Node\Stmt\Use_ $stmt)
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)][] =
Expand Down
27 changes: 27 additions & 0 deletions tests/LanguageServer/SymbolLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,33 @@ protected function get_command() : AClass {

$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
Expand Down