-
Notifications
You must be signed in to change notification settings - Fork 15
Add support for logging diagnostics at runtime #92
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
Conversation
Runtime diagnostics use an interface that is similar to validation diagnostics provided by Langium. Supports various severities and selecting affected text ranges via AST nodes.
relatedInformation: diagnostic.info.relatedInformation, | ||
data: diagnostic.info.data, | ||
source: document.textDocument.languageId, | ||
} as LspDiagnostic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the as
here? Otherwise I'd use
const lspDiagnostic: LspDiagnostic = {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it that way, but then I get the following error:
TS2375: Type '{ message: string; range: Range; severity: DiagnosticSeverity; code: string | number | undefined; codeDescription: CodeDescription | undefined; tags: DiagnosticTag[] | undefined; relatedInformation: DiagnosticRelatedInformation[] | undefined; data: unknown; source: string; }' is not assignable to type 'Diagnostic' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties. Types of property 'code' are incompatible. Type 'string | number | undefined' is not assignable to type 'string | number'. Type 'undefined' is not assignable to type 'string | number'.
I did the conversion in a similar way to how Langium does it, see here. It seems like they did not run into this error for some reason, even though they assign the same types as I do.
Unfortunately their conversion method is not publicly accessible, so I derived my custom implementation from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
I'm not a too big fan of the offset as number after a colon... I'd rather have a visual clue on where the issue is (e.g. a ^
in the line below pointing to the character) - but I think this would be another enhancement exceeding the scope of this MR. Rdy to merge from my side ;-)
# Conflicts: # package-lock.json
Part of #86
Adds support for logging diagnostics at runtime. Such runtime diagnostics are created similarly to validation diagnostics provided by Langium. This enables different severities (
error
,warning
,info
andhint
) and selecting affected text via AST nodes.The interpreter is now able to print validation diagnostics and runtime diagnostics consistently. See the following examples:


Additionally, the path to the affected source file (including line number and line offset) is printed to the console, e.g.
example/gas.jv:1:9
.