Skip to content

Conversation

@aibaars
Copy link
Contributor

@aibaars aibaars commented Sep 23, 2024

Depends on #17543

This pull request add extraction of parse error messages, and adds some diagnostic queries.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Sep 23, 2024
@aibaars aibaars changed the title Aibaars/diagnostics Rust: extract parse errors as diagnostics Sep 23, 2024
@aibaars aibaars requested a review from a team as a code owner September 23, 2024 15:43
@github-actions github-actions bot added the Ruby label Sep 23, 2024
@aibaars aibaars added the no-change-note-required This PR does not need a change note label Sep 23, 2024
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

This looks great (first commit, from #17543 , not reviewed).

Thank you for implementing and testing the error queries alongside the extractor changes!

| does_not_compile.rs:2:13:2:12 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 |
| does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 |
| does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 |
| does_not_compile.rs:2:32:2:31 | expected field name or number | Extraction failed in does_not_compile.rs with error expected field name or number | 2 |
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised we don't get any results from error.rs (which contains compile_error!("An error!");).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line in error.rs isn't a syntax error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose. I feel like it should show up somewhere (and is a cleaner test than does_not_compile.rs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The extractor currently only parses the code, and error.rs does not contain a syntax error.
I would expect an error to be reported once we implement macro expansion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me. 👍

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Additional commits LGTM as well. We're just waiting for #17543 I think.

(valid, invalid)
} else {
return (Cow::Borrowed(""), None);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the special handling of the first chunk essentially an optimisation for the common case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is a way to get the location of the first UTF8 decoding error, if any. If a file is complete garbage we don't want to generate a ton of useless decoding errors, one is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the Cow (copy-on-write) stuff is an optimisation for the common case that the input is entirely valid utf8 and no replacements are needed.

@aibaars aibaars force-pushed the aibaars/diagnostics branch 2 times, most recently from 60677e5 to ca7b9e1 Compare September 24, 2024 15:37
@aibaars aibaars force-pushed the aibaars/diagnostics branch from ca7b9e1 to 5714811 Compare September 24, 2024 17:26
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

LGTM.

@aibaars aibaars merged commit f57dd0a into main Sep 25, 2024
@aibaars aibaars deleted the aibaars/diagnostics branch September 25, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants