Skip to content

Getting access to AST-Infos via langium framewokr from right-click in IDE editor and emit command to other webview #1902

Answered by msujew
jhln asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @jhln,

as you correctly pointed out, all the positions are stored on the CST nodes of every AST element. You can simply use node.$cstNode?.range to get the range of any AST element. That's for example how our LSP services work. See as an example:

protected collectLocationLinks(sourceCstNode: CstNode, _params: DefinitionParams): MaybePromise<LocationLink[] | undefined> {
const goToLink = this.findLink(sourceCstNode);
if (goToLink) {
return [LocationLink.create(
goToLink.targetDocument.textDocument.uri,
(goToLink.target.astNode.$cstNode ?? goToLink.target).range,
g…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@cdietrich
Comment options

@msujew
Comment options

@cdietrich
Comment options

@jhln
Comment options

@jhln
Comment options

Answer selected by jhln
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants