parent
b8b038d0b0
commit
57604e61f1
|
@ -6,3 +6,5 @@
|
|||
[](https://github.com/felixfbecker/php-language-server/blob/master/LICENSE.txt)
|
||||
|
||||
A pure PHP implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol).
|
||||
|
||||

|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 206 KiB |
|
@ -4,6 +4,7 @@ declare(strict_types = 1);
|
|||
namespace LanguageServer;
|
||||
|
||||
use PhpParser\{NodeVisitorAbstract, Node};
|
||||
use LanguageServer\Protocol\{SymbolInformation, SymbolKind, Range, Position, Location};
|
||||
|
||||
class SymbolFinder extends NodeVisitorAbstract
|
||||
{
|
||||
|
@ -41,17 +42,17 @@ class SymbolFinder extends NodeVisitorAbstract
|
|||
public function enterNode(Node $node)
|
||||
{
|
||||
$class = get_class($node);
|
||||
if (!isset(self::NODE_SYMBOL_MAP[$class])) {
|
||||
if (!isset(self::NODE_SYMBOL_KIND_MAP[$class])) {
|
||||
return;
|
||||
}
|
||||
$symbol = new SymbolInformation();
|
||||
$symbol->kind = self::NODE_SYMBOL_MAP[$class];
|
||||
$symbol->kind = self::NODE_SYMBOL_KIND_MAP[$class];
|
||||
$symbol->name = (string)$node->name;
|
||||
$symbol->location = new Location(
|
||||
$this->uri,
|
||||
new Range(
|
||||
new Position($node->getAttribute('startLine'), $node->getAttribute('startColumn')),
|
||||
new Position($node->getAttribute('endLine'), $node->getAttribute('endColumn'))
|
||||
new Position($node->getAttribute('startLine') - 1, $node->getAttribute('startColumn') - 1),
|
||||
new Position($node->getAttribute('endLine') - 1, $node->getAttribute('endColumn') - 1)
|
||||
)
|
||||
);
|
||||
$symbol->containerName = $this->containerName;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace LanguageServer;
|
|||
|
||||
use PhpParser\{Error, Comment, Node, ParserFactory, NodeTraverser, Lexer};
|
||||
use PhpParser\NodeVisitor\NameResolver;
|
||||
use LanguageServer\Protocol\TextDocumentItem;
|
||||
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier, VersionedTextDocumentIdentifier};
|
||||
|
||||
/**
|
||||
* Provides method handlers for all textDocument/* methods
|
||||
|
@ -65,18 +65,18 @@ class TextDocumentManager
|
|||
/**
|
||||
* The document change notification is sent from the client to the server to signal changes to a text document.
|
||||
*
|
||||
* @param LanguageServer\Protocol\VersionedTextDocumentIdentifier $textDocument
|
||||
* @param LanguageServer\Protocol\TextDocumentContentChangeEvent[] $contentChanges
|
||||
* @param Protocol\VersionedTextDocumentIdentifier $textDocument
|
||||
* @param Protocol\TextDocumentContentChangeEvent[] $contentChanges
|
||||
* @return void
|
||||
*/
|
||||
public function didChange(VersionedTextDocumentIdentifier $textDocument, array $contentChanges)
|
||||
{
|
||||
$this->updateAst($textDocument->uri, $contentChanges->text);
|
||||
$this->updateAst($textDocument->uri, $contentChanges[0]->text);
|
||||
}
|
||||
|
||||
private function updateAst(string $uri, string $content)
|
||||
{
|
||||
$stmts = $parser->parse($content);
|
||||
$stmts = $this->parser->parse($content);
|
||||
// TODO report errors as diagnostics
|
||||
// foreach ($parser->getErrors() as $error) {
|
||||
// error_log($error->getMessage());
|
||||
|
@ -85,7 +85,7 @@ class TextDocumentManager
|
|||
if ($stmts) {
|
||||
$traverser = new NodeTraverser;
|
||||
$traverser->addVisitor(new NameResolver);
|
||||
$traverser->addVisitor(new ColumnCalculator($textDocument->text));
|
||||
$traverser->addVisitor(new ColumnCalculator($content));
|
||||
$traverser->traverse($stmts);
|
||||
}
|
||||
$this->asts[$uri] = $stmts;
|
||||
|
|
Loading…
Reference in New Issue