Skip to content
Permalink
Browse files

Fix #1888 - add go-to-variable

  • Loading branch information...
muglug committed Jul 1, 2019
1 parent 2e1493b commit 5c76b3c82d9ddc07f2cc0f1f5d7720f5dd54bfa7
@@ -943,8 +943,8 @@ public function invalidateInformationForFile(string $file_path)
*/
public function getSymbolInformation(string $file_path, string $symbol)
{
if (substr($symbol, 0, 6) === 'type: ') {
return substr($symbol, 6);
if (\is_numeric($symbol[0])) {
return \preg_replace('/[^:]*:/', '', $symbol);
}
try {
@@ -1013,6 +1013,15 @@ public function getSymbolInformation(string $file_path, string $symbol)
*/
public function getSymbolLocation(string $file_path, string $symbol)
{
if (\is_numeric($symbol[0])) {
$symbol = \preg_replace('/:.*/', '', $symbol);
$symbol_parts = explode('-', $symbol);
$file_contents = $this->getFileContents($file_path);
return new CodeLocation\Raw($file_contents, $file_path, (int) $symbol_parts[0], (int) $symbol_parts[1]);
}
try {
if (strpos($symbol, '::')) {
if (strpos($symbol, '()')) {
@@ -1115,23 +1124,7 @@ public function getReferenceAtPosition(string $file_path, Position $position)
}
if ($reference === null || $start_pos === null || $end_pos === null) {
ksort($type_map);
foreach ($type_map as $start_pos => list($end_pos, $possible_type)) {
if ($offset < $start_pos) {
break;
}
if ($offset > $end_pos) {
continue;
}
$reference = 'type: ' . $possible_type;
}
if ($reference === null || $start_pos === null || $end_pos === null) {
return null;
}
return null;
}
$range = new Range(
@@ -256,6 +256,17 @@ public static function analyze(
}
}
if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
) {
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt,
$first_appearance->raw_file_start . '-' . $first_appearance->raw_file_end . ':mixed'
);
}
$statements_analyzer->registerVariableUses([$first_appearance->getHash() => $first_appearance]);
}
} else {
@@ -264,14 +275,30 @@ public static function analyze(
if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
&& isset($stmt->inferredType)
) {
$codebase->analyzer->addNodeType(
$statements_analyzer->getFilePath(),
$stmt,
(string) $stmt->inferredType
);
}
if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
) {
$first_appearance = $statements_analyzer->getFirstAppearance($var_name);
if ($first_appearance) {
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt,
$first_appearance->raw_file_start
. '-' . $first_appearance->raw_file_end
. ':' . $stmt->inferredType->getId()
);
}
}
}
return null;
@@ -242,7 +242,7 @@ function () use ($capabilities, $rootPath, $processId) {
// Support "Completion"
if ($this->project_analyzer->provide_completion) {
$serverCapabilities->completionProvider = new CompletionOptions;
$serverCapabilities->completionProvider = new CompletionOptions();
$serverCapabilities->completionProvider->resolveProvider = false;
$serverCapabilities->completionProvider->triggerCharacters = ['$', '>', ':'];
}
@@ -104,9 +104,12 @@ class A {
/** @var int|null */
protected $a;
const BANANA = "🍌";
const BANANA = "nana";
public function foo() : void {}
public function foo() : void {
$a = 1;
echo $a;
}
}
function bar() : int {
@@ -141,8 +144,14 @@ function bar() : int {
$function_symbol_location = $codebase->getSymbolLocation('somefile.php', 'B\bar()');
$this->assertNotNull($function_symbol_location);
$this->assertSame(13, $function_symbol_location->getLineNumber());
$this->assertSame(16, $function_symbol_location->getLineNumber());
$this->assertSame(26, $function_symbol_location->getColumn());
$function_symbol_location = $codebase->getSymbolLocation('somefile.php', '257-259');
$this->assertNotNull($function_symbol_location);
$this->assertSame(11, $function_symbol_location->getLineNumber());
$this->assertSame(25, $function_symbol_location->getColumn());
}
/**
@@ -214,19 +223,19 @@ public function bar() : void {
$this->assertNotNull($symbol_at_position);
$this->assertSame('type: int|null', $symbol_at_position[0]);
$this->assertSame('245-246:int|null', $symbol_at_position[0]);
$symbol_at_position = $codebase->getReferenceAtPosition('somefile.php', new Position(12, 30));
$this->assertNotNull($symbol_at_position);
$this->assertSame('type: int', $symbol_at_position[0]);
$this->assertSame('213-214:int(1)', $symbol_at_position[0]);
$symbol_at_position = $codebase->getReferenceAtPosition('somefile.php', new Position(17, 30));
$this->assertNotNull($symbol_at_position);
$this->assertSame('type: int', $symbol_at_position[0]);
$this->assertSame('425-426:int(2)', $symbol_at_position[0]);
}
/**
@@ -362,7 +371,7 @@ public function bar(string $a) {}
public static function staticFoo(string $a) {}
public function __construct() {}
public function __construct() {}
}
function foo(string $a) {

0 comments on commit 5c76b3c

Please sign in to comment.
You can’t perform that action at this time.