-
I am exploring the langium 0.2.0 project and I try to implement a custom scope provider. I extracted the problem on a small example (https://github.com/goto40/langium-scoping-example-modeling-method_calls): The grammar is as follows:
An example model is used to evaluate the behavior:
In the basic configuration I used the hello-world example with the modified grammar.
I tried export class MyScopeProvider extends DefaultScopeProvider {
getScope(node: AstNode, referenceId: string): Scope {
if (referenceId=="Call:methodref" && node.$type=='Call') {
const scopes: AstNodeDescription[] = [];
let definitions: Def[]|undefined = [];
definitions = (node as Call).instance?.ref?.type?.ref?.defs;
if (definitions) {
definitions.forEach(element => {
scopes.push( { node: element, type: element.$type, name: element.name, documentUri:node.$document!.uri, path: ''} )
});
return new SimpleScope(stream(scopes));
}
else {
const result = super.getScope(node, referenceId);
return result;
}
}
else {
const result = super.getScope(node, referenceId);
return result;
}
}
} It does not work. Obviously it is the wrong solution. I also observed, that accessing |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Your solution approach looks correct. One problem might be const descriptions = stream(definitions).map(element =>
this.descriptionProvider.createDescription(element, element.name, getDocument(element)));
return new SimpleScope(descriptions); Where |
Beta Was this translation helpful? Give feedback.
-
I updated to 0.3.0: Now, it seems to work (it resolves the references). Thank you. Notes: grammar and major changes:
... and in the scope provider
|
Beta Was this translation helpful? Give feedback.
I updated to 0.3.0: Now, it seems to work (it resolves the references).
However, I do not get auto-completion for the custom scope provider (I did not investigate).
Thank you.
Notes: grammar and major changes: