-
Tag: @msujew This is most likely due to my lack of understanding regarding parser rule fragments, but I have an error that is somewhat confusing to me. I'm not sure I can easily create a minimal example, but the working repo is here. Questions:
Maybe I'm just missing something ... The validator works and the tests pass, but this error appears when I'm actually debugging the extension (runtime error). Error:
Grammar snippet: ...
SJMember infers SJMember:
SJField | SJMethod
;
SJField:
SJTypedDeclaration ';'
;
SJMethod:
SJTypedDeclaration
'(' (params+=SJParameter (',' params+=SJParameter)*)? ')'
body=SJBlock
;
fragment SJTypedDeclaration *:
type=[SJClass] name=ID
;
...
SJSelectionExpression infers SJExpression:
SJTerminalExpression
(
{infer SJMemberSelection.receiver=current} '.'
member=[SJMember]
(methodInvocation?='('
(args+=SJExpression (',' args+=SJExpression)*)? ')'
)?
)*
;
... Validator: checkMemberSelection(sel: SJMemberSelection, accept: ValidationAcceptor): void {
const member = sel.member;
if ( isSJField(member) && sel.methodInvocation) {
accept(
'error',
'Method invocation on a field',
{
node: sel,
property: 'methodInvocation',
code: IssueCodes.MemberSelection
}
)
} else if ( isSJMethod(member) && !sel.methodInvocation) {
accept(
'error',
'Field selection on a method',
{
node: sel,
property: 'member',
code: IssueCodes.MemberSelection
}
)
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @snarkipus, we're currently in the process of refactoring how references are resolved (see #641, which has already started with this process). We know (internally) of this issue, and are currently experimenting with ways to resolve it. The main issue here is that we incorrectly determine the reference ID based on reference that are declared within fragments. This affects mostly the completion, but other features of Langium as well.
Actually, it doesn't do anything. It did something in Xtext (but I don't remember what) and was rarely used. We just have it in there for backwards compatibility.
It's unrelated to the validator (since that exclusively operates on existing AST types), but it's very important for the completion provider (see above). We're still not sure how to deal with fragment rules, and whether we should actually try to generate AST types based on them. It would greatly help with cases such as your validator. |
Beta Was this translation helpful? Give feedback.
Hey @snarkipus,
we're currently in the process of refactoring how references are resolved (see #641, which has already started with this process). We know (internally) of this issue, and are currently experimenting with ways to resolve it. The main issue here is that we incorrectly determine the reference ID based on reference that are declared within fragments. This affects mostly the completion, but other features of Langium as well.
Actually, it doesn't do anything. It did something in Xtext (but I don't remember what) and was rarely used. We just have it in there for backwards compatibility.