-
-
Notifications
You must be signed in to change notification settings - Fork 378
Improve update logic & Fix update logic issue & Input for Query #3502
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: dev
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR improves the update logic in the main view model by refactoring how running and current queries are tracked and by updating the QueryBuilder.Build method signature to accept separate input and trimmed text parameters.
- Refactored MainViewModel to replace _isQueryRunning with two distinct query state variables.
- Updated QueryBuilder.Build calls in view model, tests, and main window to pass both raw and trimmed query text.
- Added documentation for the new Query.Input property and corresponding changes in QueryBuilder.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
Flow.Launcher/ViewModel/MainViewModel.cs | Refactored query state tracking and updated QueryBuilder.Build invocations. |
Flow.Launcher/MainWindow.xaml.cs | Updated QueryBuilder.Build call for consistency in query text handling. |
Flow.Launcher.Test/QueryBuilderTest.cs | Adjusted tests to accommodate the updated QueryBuilder.Build signature. |
Flow.Launcher.Plugin/Query.cs | Added Input property documentation. |
Flow.Launcher.Core/Plugin/QueryBuilder.cs | Changed Build method signature to accept both raw input and trimmed text. |
Comments suppressed due to low confidence (1)
Flow.Launcher/ViewModel/MainViewModel.cs:372
- [nitpick] Ensure that passing the untrimmed QueryText as the first parameter while the second parameter is trimmed is the intended behavior, and document this design choice for clarity.
var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins);
This comment has been minimized.
This comment has been minimized.
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
This comment has been minimized.
This comment has been minimized.
📝 WalkthroughWalkthroughThis change updates the query construction and management logic across the codebase. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MainWindow
participant MainViewModel
participant QueryBuilder
participant Query
User->>MainWindow: Types or edits query
MainWindow->>MainViewModel: Passes QueryText (raw input)
MainViewModel->>QueryBuilder: Build(raw input, processed text, plugins)
QueryBuilder->>Query: Constructs Query (with Input property)
Query-->>MainViewModel: Returns Query object
MainViewModel->>MainViewModel: Tracks _progressQuery and _updateQuery
MainViewModel->>MainWindow: Updates UI/results
Assessment against linked issues
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)
239-265
: Redundant guards – can be collapsed for clarityThe same three-part condition (
_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || …
) is evaluated twice, once before cloning the results and once after.
Keeping a single guard at the top of the handler avoids duplication and a tiny amount of wasted work.- if (_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || e.Token.IsCancellationRequested) - { - return; - } - - var token = e.Token == default ? _updateSource.Token : e.Token; - … - if (_currentQuery == null || e.Query.RawQuery != _currentQuery.RawQuery || token.IsCancellationRequested) - { - return; - } + var token = e.Token == default ? _updateSource.Token : e.Token; + if (_currentQuery == null || + e.Query.RawQuery != _currentQuery.RawQuery || + token.IsCancellationRequested) + { + return; + }
372-373
: Minor readability nit – avoid double-trim
QueryText
is already passed as the raw input. CallingQueryText.Trim()
for the second parameter means the string is trimmed twice insideBuild
. You can save an allocation by trimming once:-var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins); +var trimmed = QueryText.Trim(); +var query = QueryBuilder.Build(QueryText, trimmed, PluginManager.NonGlobalPlugins);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Flow.Launcher.Core/Plugin/QueryBuilder.cs
(3 hunks)Flow.Launcher.Plugin/Query.cs
(1 hunks)Flow.Launcher.Test/QueryBuilderTest.cs
(3 hunks)Flow.Launcher/MainWindow.xaml.cs
(1 hunks)Flow.Launcher/ViewModel/MainViewModel.cs
(9 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: gitStream.cm
- GitHub Check: gitStream.cm
- GitHub Check: build
🔇 Additional comments (11)
Flow.Launcher.Plugin/Query.cs (1)
10-14
: Good addition of theInput
property with clear documentationThe new
Input
property with appropriate XML documentation clearly explains its purpose and usage guidance. The warning about usingSearch
property instead is consistent with the documentation forRawQuery
.Flow.Launcher/MainWindow.xaml.cs (1)
411-411
: UpdatedQueryBuilder.Build
call with proper parametersThe call has been correctly updated to pass both the raw query text and the trimmed text as separate parameters, aligning with the updated method signature in
QueryBuilder.cs
.Flow.Launcher.Test/QueryBuilderTest.cs (3)
19-19
: Test adjusted to use updatedQueryBuilder.Build
signatureThe test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.
42-42
: Test adjusted to use updatedQueryBuilder.Build
signatureThe test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.
54-54
: Test adjusted to use updatedQueryBuilder.Build
signatureThe test call has been properly updated to include the raw input parameter, maintaining test integrity while accommodating the API change.
Flow.Launcher.Core/Plugin/QueryBuilder.cs (4)
9-9
: Method signature updated to include the raw input parameterThe
Build
method signature has been enhanced to accept the raw input as a separate parameter, which will be used to populate the newInput
property on theQuery
class.
14-15
: Minor formatting changeSmall formatting adjustment with no functional impact.
25-26
: Additional whitespace added for readabilitySmall formatting improvement to enhance code readability.
Also applies to: 32-33
42-42
: Correctly setting the newInput
propertyThe new
Input
property is properly populated with the raw input parameter, completing the implementation of this feature.Flow.Launcher/ViewModel/MainViewModel.cs (2)
1274-1281
: Potential visibility race on_runningQuery
_runningQuery
is written on the UI thread and later read from aTask.Delay
continuation running on a ThreadPool thread.
Although reference assignments are atomic, withoutvolatile
/Interlocked
there is no publish-happens-before relation; the ThreadPool may observe a stale value.If correctness depends on the most recent write, consider:
private volatile Query _runningQuery;or guarding access with a lock/
Interlocked.Exchange
.Would you verify if stale reads could surface in practice? If so, I can help prepare a patch.
1396-1397
: Verify parameter order matchesQueryBuilder.Build
signatureJust a sanity check:
Build(rawInput, processedText, nonGlobalPlugins)
is expected.
Confirm thatQueryText
(raw) andqueryBuilder.ToString().Trim()
(processed) are in the correct order to ensureQuery.Input
holds the unmodified user text.
This comment has been minimized.
This comment has been minimized.
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.
Actionable comments posted: 0
♻️ Duplicate comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)
35-36
: Improved state tracking with dedicated Query objectsThis is a good improvement over using a boolean flag. Tracking queries as objects allows for more precise state management and validation.
The existing suggestion to rename these variables to
_progressQuery
and_updateQuery
to more clearly indicate their purposes is still valid.
1254-1255
:⚠️ Potential issueCompile-time error:
TaskScheduler
is not awaitable
await TaskScheduler.Default;
will not compile becauseTaskScheduler
does not implementGetAwaiter()
.-// Switch to ThreadPool thread -await TaskScheduler.Default; +// Switch to ThreadPool thread +await Task.Yield(); // or `await Task.Run(() => {}, _updateSource.Token);`
🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
260-263
: Redundant validation checkThis is a duplicate of the check on line 240. While it's valid to verify conditions haven't changed, consider extracting this validation to a helper method to avoid duplication.
-if (_updateQuery == null || e.Query.RawQuery != _updateQuery.RawQuery || token.IsCancellationRequested) -{ - return; -} +if (IsQueryMismatchOrCancelled(_updateQuery, e.Query, token)) +{ + return; +} // Add this helper method to the class +private bool IsQueryMismatchOrCancelled(Query currentQuery, Query eventQuery, CancellationToken token) +{ + return currentQuery == null || eventQuery.RawQuery != currentQuery.RawQuery || token.IsCancellationRequested; +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Flow.Launcher/ViewModel/MainViewModel.cs
(9 hunks)
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: gitStream workflow automation
- GitHub Check: gitStream.cm
- GitHub Check: build
🔇 Additional comments (9)
Flow.Launcher/ViewModel/MainViewModel.cs (9)
240-240
: Fixed update logic comparisonThis fixes the core issue where the update logic incorrectly compared
e.Query.RawQuery
withQueryText
instead of comparing equivalent objects.
373-373
: Updated QueryBuilder.Build call with Input parameterCorrectly updated to pass both raw input and trimmed text to match the updated signature.
1221-1221
: Reset query state before processingGood practice to initialize the query state before starting a new query process.
1241-1246
: Early return optimization for changed queriesThis is a good optimization to prevent processing outdated queries when user input changes rapidly.
1251-1252
: Improved query state trackingSetting both the progress and update query objects provides better tracking of the query lifecycle.
1291-1302
: Progress bar visibility linked to query stateGood implementation of delayed progress bar visibility that also checks if the query is still active before showing it.
1325-1332
: Reset progress query after completionProperly manages the progress state and progress bar visibility after query execution completes.
1334-1338
: Added safety with try-finally blockThe finally block ensures the query state is cleaned up even if an exception occurs, preventing state leakage.
1414-1414
: Updated call to match new QueryBuilder.Build signatureCorrectly updated to provide both the original input and the processed query string.
Until we can actually figure out what's causing it. |
This comment has been minimized.
This comment has been minimized.
🥷 Code experts: theClueless Jack251970 has most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame: To learn more about /:\ gitStream - Visit our Docs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (2)
36-37
: LGTM! Improved query state tracking.The replacement of a boolean flag with two distinct
Query
objects provides more precise state management. The descriptive field names clearly indicate their purposes, addressing the confusion noted in previous reviews about similar state tracking variables.
1299-1300
:⚠️ Potential issueCritical: TaskScheduler.Default is not awaitable.
This line will cause a compilation error as
TaskScheduler.Default
does not implementGetAwaiter()
. Based on past review comments, this issue was supposedly addressed in previous commits, but the problematic code still remains.Replace with an awaitable construct:
-// Switch to ThreadPool thread -await TaskScheduler.Default; +// Switch to ThreadPool thread +await Task.Yield();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Flow.Launcher.Core/Plugin/QueryBuilder.cs
(2 hunks)Flow.Launcher.Plugin/Query.cs
(1 hunks)Flow.Launcher/MainWindow.xaml.cs
(1 hunks)Flow.Launcher/ViewModel/MainViewModel.cs
(7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- Flow.Launcher.Plugin/Query.cs
- Flow.Launcher.Core/Plugin/QueryBuilder.cs
- Flow.Launcher/MainWindow.xaml.cs
🧰 Additional context used
🧠 Learnings (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Learnt from: Yusyuriv
PR: Flow-Launcher/Flow.Launcher#3118
File: Flow.Launcher/ViewModel/MainViewModel.cs:1404-1413
Timestamp: 2024-12-08T21:12:12.060Z
Learning: In the `MainViewModel` class, the `_lastQuery` field is initialized in the constructor and is never null.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (9)
Flow.Launcher/ViewModel/MainViewModel.cs (9)
269-269
: LGTM! Fixes the core comparison issue.This correctly addresses the problem described in the PR objectives where
e.Query.RawQuery
was incorrectly compared withQueryText
. Using_updateQuery.RawQuery
ensures we're comparing the right query properties.
265-265
: LGTM! Proper initialization of progress tracking.Resetting
_progressQuery
to null at the start ensures clean state for the new query execution.
348-358
: LGTM! Well-designed progress bar timing logic.The 200ms delay before showing the progress bar prevents flickering for fast queries while ensuring longer operations provide user feedback. The condition checks ensure the progress bar is only shown for the current active query.
415-419
: LGTM! Proper cleanup in finally block.The finally block ensures
_progressQuery
is always cleared even if exceptions occur, preventing stale state that could affect subsequent queries.
404-404
: LGTM! Correct implementation of new QueryBuilder API.The call now properly passes both the raw input (
QueryText
) and the trimmed query text, supporting the newInput
property functionality described in the PR objectives.
516-516
: LGTM! Handles empty query case correctly.Consistently passes empty strings for both input and query parameters when the query text is empty or whitespace.
536-536
: LGTM! Preserves original input while using expanded query.Correctly passes the original
QueryText
as input while using the expandedqueryBuilder.ToString().Trim()
as the processed query text, ensuring shortcut expansions work while preserving the raw input.
1421-1437
: LGTM! Excellent refactoring with proper encapsulation.The
ClearResults
local function effectively encapsulates all the clearing logic, improving code organization and reducing duplication. It handles all necessary state resets: results visibility, plugin icons, and progress bar, with helpful debug logging.
279-283
:❓ Verification inconclusive
Verify the early return condition for query staleness.
The check
if (query.Input != QueryText) return;
may be too aggressive and could incorrectly skip valid queries. Consider if this comparison should account for timing or processing delays where the input might temporarily differ from the current QueryText.
🏁 Script executed:
#!/bin/bash # Search for similar input vs QueryText comparisons in the codebase rg -A 3 -B 3 "\.Input.*QueryText|QueryText.*\.Input"Length of output: 722
Verify staleness check on query input vs current QueryText
The guard
// Check if the query has changed because query can be changed so fast that // token of the query between two queries has not been created yet if (query.Input != QueryText) return;prevents stale results from overwriting fresh ones, but comparing raw strings can still miss edge cases (e.g. same text re-entered quickly, trivial edits, casing differences). You may want to ensure this check is robust by:
- Using a cancellation token or timestamp/request ID on each query to cancel or ignore outdated tasks rather than relying solely on string equality.
- Normalizing inputs (trim, case) if minor differences shouldn’t invalidate a query.
- Confirming that no valid results are dropped when
QueryText
toggles back to a previous value.Location:
- File: Flow.Launcher/ViewModel/MainViewModel.cs
- Around line:
if (query.Input != QueryText) return;
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. Forbidden patterns 🙅 (1)In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves. These forbidden patterns matched content: s.b. workaround(s)
If the flagged items are 🤯 false positivesIf items relate to a ...
|
From #3314. Resolve #2605.
Improve update logic
Improve main view model update logic.
Fix update logic issue
We should not use
e.Query.RawQuery != QueryText
becauseQueryText
(Input) is different fromRawQuery
(Query).Add new property Input for Query
Input
is the property without trimming whitespace and it can help developer get the raw input.Clear results when there are no update tasks
In this function, we need to reset all things because there are no update tasks.
Test