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

feat: Implement textDocument/xevaluatableExpression #58

Merged
merged 4 commits into from
Jul 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath =
$serverCapabilities->xworkspaceReferencesProvider = true;
$serverCapabilities->xdefinitionProvider = true;
$serverCapabilities->xdependenciesProvider = true;
$serverCapabilities->experimental = [
'xevaluatableExpressionProvider' => true,
];

return new InitializeResult($serverCapabilities);
});
Expand Down
30 changes: 30 additions & 0 deletions src/Server/TextDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,34 @@ public function xdefinition(TextDocumentIdentifier $textDocument, Position $posi
return [new SymbolLocationInformation($descriptor, $def->symbolInformation->location)];
});
}

/**
* Return an evaluatable exrpession under the cursor for the debugger.
*
* @param TextDocumentIdentifier $textDocument The text document
* @param Position $position The position inside the text document
* @return Promise <EE>
*/
public function xevaluatableExpression(TextDocumentIdentifier $textDocument, Position $position): Promise
{
return coroutine(function () use ($textDocument, $position) {
$document = yield $this->documentLoader->getOrLoad($textDocument->uri);
// Find the node under the cursor
$node = $document->getNodeAtPosition($position);
if ($node === null) {
return null;
}
if (
$node instanceof Node\Expression\Variable ||
$node instanceof Node\Parameter ||
$node instanceof Node\Expression\SubscriptExpression ||
$node instanceof Node\Expression\MemberAccessExpression ||
(($node2 = $node->getFirstAncestor(Node\Expression\SubscriptExpression::class)) && ($node = $node2))
) {
$range = RangeFactory::fromNode($node);
return [ 'expression' => $node->getText(), 'range' => $range ];
}
return null;
});
}
}
3 changes: 3 additions & 0 deletions tests/LanguageServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function testInitialize()
$serverCapabilities->xworkspaceReferencesProvider = true;
$serverCapabilities->xdefinitionProvider = true;
$serverCapabilities->xdependenciesProvider = true;
$serverCapabilities->experimental = [
'xevaluatableExpressionProvider' => true,
];

$this->assertEquals(new InitializeResult($serverCapabilities), $result);
}
Expand Down