Skip to content
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

Process parse errors (including error nodes) in TextDocumentState #492

Conversation

sungshik
Copy link
Contributor

@sungshik sungshik commented Oct 25, 2024

Before this PR, parse trees were processed twice to find error nodes (i.e., the exact same computation was repeated a second time): first in TextDocumentState (to figure out if lastTreeWithoutErrors should be updated), and next in RascalTextDocumentService (to translate error nodes to LSP diagnostics).

After this PR, all processing of parse errors (including error nodes) is moved out of RascalTextDocumentService into TextDocumentState. There is a new API call getCurrentDiagnosticsAsync (optionally with a debounce delay) for consumers to get diagnostics, similar to the existing getCurrentTreeAsync.

Copy link
Contributor Author

@sungshik sungshik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments

@PieterOlivier
Copy link

PieterOlivier commented Oct 28, 2024

Looking good! Maybe you can move the Debouncer class to its own file?

.whenComplete((t, e) -> {

// Prepare result values for futures
var tree = new Versioned<>(version, t);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a <tree,diagnostics> pair seem to belong together (not suprisingly), would ik make sense to have one Versioned object with a version and a pair of <tree,diagnostics>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, yes, it would. However, in many places in the project (including the Parametric... classes), a Versioned<ITree> is currently expected, so it seems quite an invasive change to supply a Versioned<Pair<ITree,List<Diagnostic>> instead. I'm not worried about the complicated type parameter btw (i.e., we could hide the structure with an auxiliary class). But it's just a lot of changes to places that we don't really need/hope to touch right now 😉.

At the same time, I imagine the reporting of diagnostics can be streamlined a bit more if the diagnostics become accessible in some places where currently there's only a parse tree. Tt requires a bit more thought, though. I think I'd prefer to do that in a separate PR.

@sungshik sungshik marked this pull request as ready for review October 28, 2024 15:09
@sungshik sungshik merged commit b095617 into error-recovery/rascal Oct 30, 2024
5 of 12 checks passed
@sungshik sungshik deleted the error-recovery/rascal-diagnostics-in-document-state branch October 30, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants