-
Notifications
You must be signed in to change notification settings - Fork 94
add QSyntaxHighlighter to Span inspector #1368
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
base: main
Are you sure you want to change the base?
add QSyntaxHighlighter to Span inspector #1368
Conversation
This highlights all output tokens that share the same span as the text cursor is hovering over.
Expansion erros are now shown directly in the output textfield.
- Fix incorrect calculation of target span - Fix false highlighting caused by Pretty Please code manipulation
- Prevents issues with special characters like '<' and '>' breaking the output HTML
These tokens are now ignored during parsing because prettyplease inserts them automatically in certain situations.
…fresh bug - Make output text area scrollable - Adjust text color to match the theme - Fix edge case where text change did not trigger refresh if cursor position stayed the same
- Before tests were failing due to an outdated Cargo.lock
- Tests were failing due to an outdated Cargo.lock
- renamed finalFormats to PendingHighlights - improve comment for PendingHighlights - added PendingHighlights to field of SyntaxHighlighter
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1368 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 13108 13108
=========================================
Hits 13108 13108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hm, I managed to get the span inspector to panic: |
LeonMatthesKDAB
left a comment
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.
Overall, this looks surprisingly clean 🥳
I had expected a custom QSyntaxHighlighter to be much more annoying to implement.
The background coloring for spans is also really easy to parse visually.
Good job, thank you 👍
Just some smaller nitpicks remaining.
| impl cxx_qt::Constructor<(*mut QTextDocument,)> for qobject::SyntaxHighlighter { | ||
| type BaseArguments = (*mut QTextDocument,); | ||
| type InitializeArguments = (); | ||
| type NewArguments = (); | ||
|
|
||
| fn route_arguments( | ||
| args: (*mut QTextDocument,), | ||
| ) -> ( | ||
| Self::NewArguments, | ||
| Self::BaseArguments, | ||
| Self::InitializeArguments, | ||
| ) { | ||
| ((), args, ()) | ||
| } | ||
|
|
||
| fn new(_: ()) -> SyntaxHighlighterRust { | ||
| SyntaxHighlighterRust::default() | ||
| } | ||
| } | ||
|
|
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.
Yay, all the work to implement the Constructor stuff is paying off 🥳
| ); | ||
| let expand_result = Self::expand(&text.to_string()); | ||
|
|
||
| let (formated_rust, char_flags) = match expand_result.clone() { |
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.
| let (formated_rust, char_flags) = match expand_result.clone() { | |
| let (formatted_rust, char_flags) = match expand_result.clone() { |
nit-pick: typo
| .map_err(|err| eprintln!("Parsing error: {err}")) | ||
| .unwrap(); | ||
|
|
||
| let formated_rust = prettyplease::unparse(&file); |
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.
| let formated_rust = prettyplease::unparse(&file); | |
| let formatted_rust = prettyplease::unparse(&file); |
typo
| self.as_mut() | ||
| .rust_mut() | ||
| .output_highlighter | ||
| .pin_mut() |
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.
This is duplicated boilerplate from the statement above.
Please extract this into an output_highlighter local variable.
| unsafe extern "C++Qt" { | ||
| include!(<QSyntaxHighlighter>); | ||
| #[qobject] | ||
| type QSyntaxHighlighter; |
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.
Please split the CXX-Qt bridge into two, where all of this goes into the syntax_highlighter.rs .
That would clean this module up quite a bit.
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.
It does not seem possible for me to split this up, because both parts need to use the same types, but they are defined in different namespaces.
For example:
error[E0308]: mismatched types
--> examples/span-inspector/src/inspector.rs:161:43
|
161 | make_q_syntax_highlighter(output.text_document());
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `syntax_highlighter_ffi::QTextDocument`, found `qobject::QTextDocument`
| |
| arguments to this function are incorrect
|
= note: `qobject::QTextDocument` and `syntax_highlighter_ffi::QTextDocument` have similar names, but are actually distinct types
| (None, State::Literal) | ||
| } | ||
|
|
||
| (State::Default, "#[") => { |
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.
#![ can also mark the start of a macro (which then applies to module scope)
examples/span-inspector/build.rs
Outdated
| .qt_module("Network") | ||
| .qt_module("Quick") | ||
| .file("src/inspector.rs") | ||
| .qobject_header("include/helper.h") |
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.
This will need to use ccp_file now that 0.8 is out :) (needs rebasing/merging of main)
examples/span-inspector/build.rs
Outdated
| .file("src/inspector.rs") | ||
| .qobject_header("include/helper.h") | ||
| .build(); | ||
| println!("cargo:rerun-if-changed=include/helper.h"); |
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.
This is not needed, cpp_file will do this automatically :)
| proc-macro2.workspace = true | ||
| prettyplease = { version = "0.2", features = ["verbatim"] } | ||
| syn.workspace = true | ||
| fancy-regex = "0.16.2" |
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.
Any reason you used fancy-regex and not regex?
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.
It seems that the regex crate does not support lookahead or lookbehind.
| for i in 0..block_length { | ||
| let color = match flags[(block_position + i) as usize] { | ||
| TokenFlag::Original => QColor::from_rgba(0, 100, 155, 170), | ||
| TokenFlag::Generated => QColor::from_rgba(0, 255, 0, 15), |
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 think this green has a little bit too much blue in it, which visually makes it appeary related to the "Original" coloring.
I guess you can also try adding an equal amount of red to balance it and just make it brighter.
But overall, I really like the approach of using the background color to indicate this.
This PR introduces a major rewrite of the Span inspector: