Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Fix diagnostics messages (correct filename and output is cleared when compilation is successful) #56

Merged
merged 2 commits into from
Mar 30, 2023

Conversation

Bramas
Copy link
Contributor

@Bramas Bramas commented Mar 29, 2023

fixes #44

src/main.rs Outdated
Comment on lines 299 to 325
for (uri, message, range) in messages.into_iter() {
self.client
.publish_diagnostics(
uri,
vec![Diagnostic {
range,
severity: Some(DiagnosticSeverity::ERROR),
message,
..Default::default()
})
.collect(),
None,
)
.await;
}],
None,
)
.await;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Can we use something like join_all so we don't have to wait for each promise individually?

for (uri, message, range) in messages.into_iter() {
self.client
.publish_diagnostics(
uri,
Copy link
Owner

Choose a reason for hiding this comment

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

Can we merge diagnostics per URI so everything for each file is published at once? Otherwise, we may send diagnostics many times to the same file, which is both slow and will cause the last sent diagnostic to be overwritten each time.

Ideally, this would also handle the above added block to clear diagnostics by sending an empty set to files which we have checked but found no errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I was thinking about it. First I thought that there was a single diagnostic per file but I did not realized that previous diagnostics were just overwritten.

I am fixing it now.

@nvarner
Copy link
Owner

nvarner commented Mar 29, 2023

Would also close #57

@Bramas
Copy link
Contributor Author

Bramas commented Mar 29, 2023

I pushed a new version where diagnostics are grouped per file, and are sent together with join_all as suggested.

However I am unable to find a document where typst reports several errors, to try if it works as expected. Can typst return several error per file? it seems like it stops after the first error (hence always on a single file).

@beeb
Copy link
Contributor

beeb commented Mar 29, 2023

The function prototype certainly suggests it could return multiple errors. Even if that's not a common occurence right now, we have to assume it can be a possibility in the future. LGTM!

Copy link
Owner

@nvarner nvarner left a comment

Choose a reason for hiding this comment

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

A few things could be made more idiomatic. In general, it's better to avoid mut and instead build our collections from iterators. However, this looks pretty good, and I need to do some general refactoring anyway. If it turns out to be possible to make it nicer, that can be done then.

@nvarner nvarner merged commit 78ae5b4 into nvarner:master Mar 30, 2023
@nvarner
Copy link
Owner

nvarner commented Mar 30, 2023

Thank you!

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.

Error in file (not main) shows in unrelated file
3 participants