Skip to content

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

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented May 2, 2025

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 because QueryText (Input) is different from RawQuery (Query).

Add new property Input for Query

Input is the property without trimming whitespace and it can help developer get the raw input.

Test

  • Input long string fast and interface will update instantly.

@Jack251970 Jack251970 requested review from Copilot and taooceros May 2, 2025 04:44
@Jack251970 Jack251970 requested a review from jjw24 May 2, 2025 04:44
Copy link
Contributor

@Copilot Copilot AI left a 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.

Copy link

gitstream-cm bot commented May 2, 2025

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.

Copy link
Contributor

coderabbitai bot commented May 2, 2025

Warning

Rate limit exceeded

@Jack251970 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5b5fb and bde7463.

📒 Files selected for processing (3)
  • Flow.Launcher.Core/Plugin/QueryBuilder.cs (2 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (2 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (10 hunks)
📝 Walkthrough

Walkthrough

This change updates the query construction and management logic across the codebase. The QueryBuilder.Build method now accepts both the original user input and a processed version of the query text, and the Query class adds a new Input property to store the raw input. The MainViewModel replaces its boolean query-running flag with two Query objects to more precisely track active and current queries, improving cancellation and progress bar handling. All relevant method calls and tests are updated to accommodate the new method signature and logic.

Changes

File(s) Change Summary
Flow.Launcher.Core/Plugin/QueryBuilder.cs Updated Build method to accept an additional input parameter and set the new Input property on the returned Query object.
Flow.Launcher.Plugin/Query.cs Added new public Input property with internal init accessor and documentation.
Flow.Launcher.Test/QueryBuilderTest.cs Updated test calls to QueryBuilder.Build to include the additional input parameter.
Flow.Launcher/MainWindow.xaml.cs Modified call to QueryBuilder.Build in the Backspace key handler to pass both the full and trimmed query text.
Flow.Launcher/ViewModel/MainViewModel.cs Replaced _isQueryRunning with _progressQuery and _updateQuery fields; updated query construction and result handling logic; updated all QueryBuilder.Build calls to supply both input and processed text.

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
Loading

Suggested reviewers

  • taooceros
  • jjw24

Poem

A bunny hopped through fields of code,
With queries new, their logic showed.
Now input’s saved, both raw and neat,
The search is swift, the flow complete!
Two queries tracked, no flag in sight—
A rabbit’s joy, the code feels right!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 clarity

The 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. Calling QueryText.Trim() for the second parameter means the string is trimmed twice inside Build. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8bb96d7 and 34c3cda.

📒 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 the Input property with clear documentation

The new Input property with appropriate XML documentation clearly explains its purpose and usage guidance. The warning about using Search property instead is consistent with the documentation for RawQuery.

Flow.Launcher/MainWindow.xaml.cs (1)

411-411: Updated QueryBuilder.Build call with proper parameters

The 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 updated QueryBuilder.Build signature

The 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 updated QueryBuilder.Build signature

The 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 updated QueryBuilder.Build signature

The 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 parameter

The Build method signature has been enhanced to accept the raw input as a separate parameter, which will be used to populate the new Input property on the Query class.


14-15: Minor formatting change

Small formatting adjustment with no functional impact.


25-26: Additional whitespace added for readability

Small formatting improvement to enhance code readability.

Also applies to: 32-33


42-42: Correctly setting the new Input property

The 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 a Task.Delay continuation running on a ThreadPool thread.
Although reference assignments are atomic, without volatile/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 matches QueryBuilder.Build signature

Just a sanity check: Build(rawInput, processedText, nonGlobalPlugins) is expected.
Confirm that QueryText (raw) and queryBuilder.ToString().Trim() (processed) are in the correct order to ensure Query.Input holds the unmodified user text.

@Jack251970 Jack251970 changed the title Improve update logic Improve update logic & Fix update logic issue May 2, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 2, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 2, 2025

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 objects

This 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 issue

Compile-time error: TaskScheduler is not awaitable

await TaskScheduler.Default; will not compile because TaskScheduler does not implement GetAwaiter().

-// 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 check

This 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

📥 Commits

Reviewing files that changed from the base of the PR and between 381334f and 1381748.

📒 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 comparison

This fixes the core issue where the update logic incorrectly compared e.Query.RawQuery with QueryText instead of comparing equivalent objects.


373-373: Updated QueryBuilder.Build call with Input parameter

Correctly updated to pass both raw input and trimmed text to match the updated signature.


1221-1221: Reset query state before processing

Good practice to initialize the query state before starting a new query process.


1241-1246: Early return optimization for changed queries

This is a good optimization to prevent processing outdated queries when user input changes rapidly.


1251-1252: Improved query state tracking

Setting both the progress and update query objects provides better tracking of the query lifecycle.


1291-1302: Progress bar visibility linked to query state

Good implementation of delayed progress bar visibility that also checks if the query is still active before showing it.


1325-1332: Reset progress query after completion

Properly manages the progress state and progress bar visibility after query execution completes.


1334-1338: Added safety with try-finally block

The 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 signature

Correctly updated to provide both the original input and the processed query string.

@Jack251970 Jack251970 removed this from the 1.20.0 milestone May 4, 2025
@Jack251970
Copy link
Contributor Author

@jjw24 I am not sure if this PR can resolve #3508.

@jjw24
Copy link
Member

jjw24 commented May 4, 2025

Until we can actually figure out what's causing it.

@jjw24 jjw24 added this to the Future milestone May 4, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented May 5, 2025

🥷 Code experts: theClueless

Jack251970 has most 👩‍💻 activity in the files.
Jack251970, theClueless have most 🧠 knowledge in the files.

See details

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Activity based on git-commit:

Jack251970
MAY 3 additions & 3 deletions
APR
MAR
FEB
JAN
DEC

Knowledge based on git-blame:
theClueless: 53%
Jack251970: 7%

Flow.Launcher.Plugin/Query.cs

Activity based on git-commit:

Jack251970
MAY 4 additions & 3 deletions
APR
MAR
FEB 6 additions & 6 deletions
JAN 1 additions & 13 deletions
DEC

Knowledge based on git-blame:
Jack251970: 11%

Flow.Launcher.Test/QueryBuilderTest.cs

Activity based on git-commit:

Jack251970
MAY
APR
MAR
FEB 20 additions & 19 deletions
JAN
DEC

Knowledge based on git-blame:
theClueless: 57%
Jack251970: 31%

Flow.Launcher/MainWindow.xaml.cs

Activity based on git-commit:

Jack251970
MAY 0 additions & 4 deletions
APR 69 additions & 45 deletions
MAR 1141 additions & 1076 deletions
FEB 1 additions & 1 deletions
JAN
DEC 5 additions & 10 deletions

Knowledge based on git-blame:
Jack251970: 65%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
MAY 171 additions & 75 deletions
APR 35 additions & 28 deletions
MAR 695 additions & 628 deletions
FEB 63 additions & 21 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions

Knowledge based on git-blame:
Jack251970: 36%

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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)

36-37: Consider more descriptive names for query tracking variables.

While _progressQuery and _updateQuery are good names with helpful comments, consider renaming them to even more descriptive names to make their purposes clearer.

-private Query _progressQuery; // Used for QueryResultAsync
-private Query _updateQuery; // Used for ResultsUpdated
+private Query _progressQuery; // Tracks active query for progress bar visibility
+private Query _updateQuery; // Used to validate incoming ResultsUpdated events

1286-1286: ⚠️ Potential issue

Fix the TaskScheduler usage - it's not awaitable.

TaskScheduler.Default is not awaitable and this will cause a compilation error. You need to use a construct that actually returns a Task.

-// Switch to ThreadPool thread
-await TaskScheduler.Default;
+// Switch to ThreadPool thread
+await Task.Yield();
🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

247-270: Consider extracting duplicate validation logic.

The validation check at line 247 is repeated at line 267. Consider extracting this into a helper method to avoid duplication and make future maintenance easier.

+private bool IsQueryStillValid(Query eventQuery, CancellationToken token) 
+{
+    return _updateQuery != null && eventQuery.RawQuery == _updateQuery.RawQuery && !token.IsCancellationRequested;
+}

 plugin.ResultsUpdated += (s, e) =>
 {
-    if (_updateQuery == null || e.Query.RawQuery != _updateQuery.RawQuery || e.Token.IsCancellationRequested)
+    if (!IsQueryStillValid(e.Query, e.Token))
     {
         return;
     }

     // processing logic...

-    if (_updateQuery == null || e.Query.RawQuery != _updateQuery.RawQuery || token.IsCancellationRequested)
+    if (!IsQueryStillValid(e.Query, token))
     {
         return;
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1381748 and 07bcd5d.

📒 Files selected for processing (3)
  • Flow.Launcher.Core/Plugin/QueryBuilder.cs (2 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher/MainWindow.xaml.cs
  • Flow.Launcher.Core/Plugin/QueryBuilder.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 (10)
Flow.Launcher/ViewModel/MainViewModel.cs (10)

36-37: Good replacement of boolean flag with more descriptive Query objects.

Replacing the single boolean _isQueryRunning flag with two separate Query objects (_progressQuery and _updateQuery) provides better state tracking and clarity about which query is being used for which purpose.


247-250: Improved update logic validation with proper Query comparison.

The updated condition now correctly compares e.Query.RawQuery with _updateQuery.RawQuery instead of comparing with QueryText, addressing the core issue mentioned in the PR objective. This ensures that the comparison is between the same types of data.


267-270: Good addition of secondary validation check after processing.

Adding a second check after processing the results ensures that the query is still valid before writing the results to the channel, providing an extra layer of protection against race conditions.


380-380: Updated Build method call to include both raw and processed query.

This change correctly passes both the original QueryText and its trimmed version to align with the updated signature of QueryBuilder.Build.


1244-1244: Good defensive programming to initialize _progressQuery.

Explicitly setting _progressQuery to null at the start of the method ensures a clean query state before processing begins.


1272-1273: Effective early return to prevent processing outdated queries.

Adding this check prevents running queries that no longer match the current user input, which should improve performance and responsiveness when typing quickly.


1282-1283: Clear assignment of tracking queries to improve state management.

Setting both _progressQuery and _updateQuery at the same point in the code flow makes it easier to understand and maintain the query state.


1343-1351: Improved progress bar handling based on _progressQuery state.

The progress bar visibility is now controlled by checking if _progressQuery is not null and matches the current query, which provides a more accurate representation of the current processing state than the previous boolean flag.


1268-1405: Added try-finally block for robust cleanup of _progressQuery.

Wrapping the query execution in a try-finally block ensures that _progressQuery is always cleared even if exceptions occur, preventing the progress bar from getting stuck in a visible state.


1505-1505: Updated ConstructQueryAsync return to include original input.

The method now correctly returns the result of QueryBuilder.Build with both the original QueryText and the expanded query string, which aligns with the updated method signature.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

1285-1286: ⚠️ Potential issue

TaskScheduler.Default is not awaitable

await TaskScheduler.Default; will not compile because TaskScheduler doesn't implement GetAwaiter().

-// Switch to ThreadPool thread
-await TaskScheduler.Default;
+// Switch to ThreadPool thread
+await Task.Yield();                   // or `await Task.Run(() => {}, token);`
🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

36-1506: Consider renaming variables for better clarity

While the code logic has improved significantly, the variable names _progressQuery and _updateQuery could be more descriptive to better indicate their specific purposes.

-private Query _progressQuery; // Used for QueryResultAsync
-private Query _updateQuery; // Used for ResultsUpdated
+private Query _executingQuery; // Query currently being executed in QueryResultAsync
+private Query _activeQuery; // Query currently being used to validate result updates
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07bcd5d and cf3fc6a.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (10 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 (1)
  • GitHub Check: build
🔇 Additional comments (12)
Flow.Launcher/ViewModel/MainViewModel.cs (12)

36-37: Improved query state tracking with dedicated objects

This change replaces the boolean flag _isQueryRunning with two explicit Query objects that provide better state tracking for different scenarios. This is a good design improvement as it allows for more precise query state management.


247-250: Fixed update logic to properly compare query objects

This fixes the core issue mentioned in the PR where the update logic was incorrectly comparing e.Query.RawQuery with QueryText. Now it properly compares e.Query.RawQuery with _updateQuery.RawQuery, ensuring that only relevant updates are processed.


267-270: Added additional validation check to prevent stale updates

This second validation check ensures that by the time results are processed, the query is still valid. This prevents potential race conditions where the query changed between the initial check and when the results are about to be added to the update channel.


380-380: Updated Backspace command to pass both raw and trimmed query

The change aligns with the updated QueryBuilder.Build signature that now requires both the raw input and the processed query text. This ensures consistency with the rest of the codebase.


1244-1244: Explicitly reset query state at the beginning of query execution

This ensures that the progress query state starts clean before each query execution, preventing potential state leakage from previous queries.


1268-1273: Added early return to prevent processing outdated queries

This important check prevents processing queries that no longer match the current user input, which helps with responsiveness when typing quickly. This directly addresses the PR objective of improving interface updates for rapid input.


1282-1283: Set both query tracking objects after token creation

Setting both _progressQuery and _updateQuery at this point ensures they're properly initialized with the current query before any async operations, which is crucial for proper state tracking.


1341-1348: Improved progress bar visibility logic

The progress bar visibility is now based on checking if the current query matches the _progressQuery reference instead of a boolean flag. This is more robust as it prevents showing the progress bar for outdated queries.


1401-1405: Added try-finally block to ensure cleanup

The try-finally block ensures that _progressQuery is always reset, even if an exception occurs during query execution. This prevents the UI from getting stuck in a loading state.


1408-1409: Updated QueryTaskAsync with isHomeQuery parameter

This parameter addition clarifies whether the query is a home query, which allows for different handling logic. The method now makes the distinction explicit rather than relying on other contextual clues.


1485-1486: Updated QueryBuilder.Build call to use consistent parameters

This change aligns with the updated method signature to accept both raw input and processed text, maintaining consistency across the codebase.


1505-1506: Passing both raw and processed query to QueryBuilder.Build

Similarly to the previous comment, this ensures the Build method receives the complete context it needs - both the original user input (QueryText) and the expanded/processed query text.

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.

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 24
⚠️ non-alpha-in-dictionary 19

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)

\bwork[- ]arounds?\b
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970 Jack251970 changed the title Improve update logic & Fix update logic issue Improve update logic & Fix update logic issue & Input for Query May 12, 2025
@Jack251970 Jack251970 linked an issue May 12, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10 min review bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Support Untrimmed query for Flow Launcher's Query
2 participants