8000 Add support for logging diagnostics at runtime by felix-oq · Pull Request #92 · jvalue/jayvee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 5 commits into from
Jan 10, 2023
Merged

Conversation

felix-oq
Copy link
Contributor
@felix-oq felix-oq commented Jan 9, 2023

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 and hint) 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.

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.
@felix-oq felix-oq requested a review from georg-schwarz January 9, 2023 16:08
relatedInformation: diagnostic.info.relatedInformation,
data: diagnostic.info.data,
source: document.textDocument.languageId,
} as LspDiagnostic;
Copy link
Member

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 = {
 // ...
}

Copy link
Contributor Author

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.

Copy link
Member
@georg-schwarz georg-schwarz left a 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 ;-)

@felix-oq
Copy link
Contributor Author

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)

I actually planned to do this, but not in this PR to keep it small.

In VS Code, the line offset is practical, because it is clickable:

8000

@felix-oq felix-oq merged commit e238f6b into main Jan 10, 2023
@felix-oq felix-oq deleted the diagnostic-logging branch January 10, 2023 11:21
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0