-
Notifications
You must be signed in to change notification settings - Fork 8
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
Rename Language
to CompiledQuery
#151
Rename Language
to CompiledQuery
#151
Conversation
@alexpovel I reduced the amount of code in the See: 0b21418 I'll fix the clippies tommorrow. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #151 +/- ##
==========================================
+ Coverage 86.69% 86.77% +0.08%
==========================================
Files 32 32
Lines 1969 1883 -86
==========================================
- Hits 1707 1634 -73
+ Misses 262 249 -13 ☔ View full report in Codecov by Sentry. |
@alexpovel All clippies are fixed and the tests pass locally. |
Language
to CompiledQuery
Thank you! I'll give it a read soon. In CI, the feature power set test is failing, so seems like some parts of the refactor need to be gated behind feature attributes again |
212ca28
to
ff232f5
Compare
Ah yea the |
@alexpovel Do you want to |
let cli::Args { | ||
scope, | ||
shell, | ||
composable_actions, | ||
standalone_actions, | ||
mut options, | ||
languages_scopes, | ||
#[cfg(feature = "german")] | ||
german_options, | ||
} = args; |
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.
Nice!
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.
Destructuring for the win!
tests/langs/mod.rs
Outdated
) { | ||
let lang = lang.expect("Building a Language for a test should not fail"); |
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.
So there's no longer a way to statically (type level) say: custom, user-provided queries are expected to fail and if so, fail gracefully, while prepared queries are expected to be valid and would panic (but don't, as is validated through testing)?
Because under that model, try_from
on a prepared query wouldn't exist.
Just asking. Not a blocker.
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.
Good point, we can definitely do more with typing given that we know the prepared queries are syntactically valid and tested to be so.
I'll give this a look and if you like the solution I'll squash the commits.
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.
Alright, but no worries. Such a refactor might lead down the path we came from in the first place (PhantomData
, ...) 😉
And I'm not sure it was previously possible either, as the code query was an enum and not separate types.
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.
See what you think of something like this: 766ca78.
Maybe a trait is strong enough.
We could seal the trait so that prepared queries are only definable internally.
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.
And I clearly need to fix the macro if we continue on with this solution.
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.
A new trait can work, but I'm wondering if the solution couldn't be quite simple:
impl From<PreparedQuery> for CompiledQuery {
// ...
}
would that not be enough? This skips the intermediate, fallible RawQuery
state, and skips to the known-good state (and panics if necessary, but tests will show it won't). It can live in parallel with impl From<PreparedQuery> for RawQuery
if that's also needed.
Just skimmed over the proposal quickly so might be off base.
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.
And if it cannot be made simpler, I slightly prefer the previous approach, where we simply unwrap
on RawQuery
. A slight blip in the type system but a simpler implementation.
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.
Using Into
is indeed the simplest implementation you just end up needing to disambiguate the conversion to impl LanguageScoper
in the tests.
I'll make an Into
so we can compare.
@bheylin let's |
Once that lint is silenced I'm happy to merge. Again, feel free to squash, else I'll do it for you |
@alexpovel check out proposal 2 c0ddb6c |
Looks great! It's much simpler than the previous proposal, so a win in my books. This reads nice and fluent for example: c0ddb6c#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR1306-R1313 I'm happy to move forward with this 🙂 |
Oh CI is green, didn't expect that (thought you were still experimenting). So it this good to go from your perspective, save for some cleanup? |
16e00fd
to
e0b0382
Compare
…ete types - Merged the `Language` and `CodeQuery` aliases into a single `CompiledQuery` type per language mod `c::CompiledQuery`. - Rename the `Preparred[lang]Query` to `[lang]::ProparredQuery`. Leave the namespace disambiguate the type name. - Add a direct conversion between the `[lang]::PreparedQuery` and `[lang::CompiledQuery]`. - Rename `cli::Cli` to 'cli::Args'. - Use destructuring and object moving to avoid needless cloning and reference passing of the large `cli::Args` object. Destructuring allows us to pass the destuctured subobjects of `cli::Args` into the various processing functions so the reader can see clearly the dependencies of each function. - Add `enum StandaloneAction` to replace the difficult to read literal bool in pattern matching. - Replace the `macro_rules! handle_language_scope` with a `macro_rules impl_lang_scopes!` that links the `struct cli::LanguageScopes` and the list of `dyn LanguageScopes` used to perform tree-sitter matches. This results in less code in the `macro_rules!` and more invariants enforced by the type system.
e0b0382
to
0de07c9
Compare
@alexpovel I've squashed the commits and written a detailed commit message. |
Sounds good, merged. Thank you for all your work so far! |
Great! Thanks for your time and feedback. I'm going to make another smaller cleanup PR around renaming the |
@alexpovel I've performed the refactorings we talked about in PR #144 and moved the
handle_language_scope
macro into themod cli
so that the fields are andlang::CompiledQuery
's are strongly associated.One of the CLI tests is failing so I'll mark this as WIP.