Skip to content

Commit 2959b05

Browse files
committed
Fixup references adder
1 parent 9f2d3a4 commit 2959b05

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/NodeVisitors/ReferencesFinder.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace LanguageServer;
5+
6+
use PhpParser\{NodeVisitorAbstract, Node};
7+
use LanguageServer\Protocol\{SymbolInformation, SymbolKind, Range, Position, Location};
8+
9+
class ReferencesFinder extends NodeVisitorAbstract
10+
{
11+
/**
12+
* @var LanguageServer\Protocol\SymbolInformation[]
13+
*/
14+
private $symbols = [];
15+
16+
/**
17+
* Map from Nodes to array of references
18+
* @var Map
19+
*/
20+
private $references = [];
21+
22+
public function __construct(SymbolInformation $symbols)
23+
{
24+
$this->symbols = $symbols;
25+
}
26+
27+
public function enterNode(Node $node)
28+
{
29+
if ($node instanceof Node\Name) {
30+
foreach ($this->symbols as $symbol) {
31+
if ($symbol->name === (string)$node) {
32+
// The name matches
33+
// For classes/interfaces/traits, we now found a reference
34+
if ($node instanceof Node\Stmt\ClassLike) {
35+
36+
}
37+
// For methods, we need to check if the object is of the right class
38+
// For variables, we need to check if the variable is in the scope
39+
}
40+
}
41+
}
42+
$this->parent = $parent;
43+
}
44+
}

src/Project.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function __construct(LanguageClient $client)
5555
*/
5656
public function getDocument(string $uri)
5757
{
58-
$uri = urldecode($uri);
5958
if (!isset($this->documents[$uri])) {
6059
$this->documents[$uri] = new PhpDocument($uri, $this, $this->client, $this->parser);
6160
}

src/Server/TextDocument.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Position,
1515
FormattingOptions,
1616
TextEdit,
17+
ReferenceContext,
1718
Location
1819
};
1920

@@ -90,6 +91,18 @@ public function formatting(TextDocumentIdentifier $textDocument, FormattingOptio
9091
return $this->project->getDocument($textDocument->uri)->getFormattedText();
9192
}
9293

94+
/**
95+
* The references request is sent from the client to the server to resolve project-wide references for the symbol
96+
* denoted by the given text document position.
97+
*
98+
* @param ReferenceContext $context
99+
* @return Location[]
100+
*/
101+
public function references(ReferenceContext $context, TextDocumentIdentifier $textDocument, Position $position): array
102+
{
103+
// $this->project->getDocument($textDocument->uri)->
104+
}
105+
93106
/**
94107
* The goto definition request is sent from the client to the server to resolve the definition location of a symbol
95108
* at a given text document position.

0 commit comments

Comments
 (0)