Skip to content

Conversation

Jack251970
Copy link
Member

@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.

Clear results when there are no update tasks

In this function, we need to reset all things because there are no update tasks.

if (ShouldClearExistingResultsForNonQuery(plugins))
{
    // No update tasks and just return
    ClearResults();
    return;
}

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

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds an untrimmed input field Query.Input, changes QueryBuilder.Build to accept both raw and trimmed text, updates callers and tests to pass both values, and refactors MainViewModel to track Query instances for cancellation, progress, and result-clearing.

Changes

Cohort / File(s) Change Summary
Query model & builder
Flow.Launcher.Plugin/Query.cs, Flow.Launcher.Core/Plugin/QueryBuilder.cs
Added public string Input { get; internal init; } to Query. Changed QueryBuilder.Build signature to Build(string input, string text, Dictionary<...>) and set Query.Input (explicit empty string when input is null/empty).
View and VM callsites
Flow.Launcher/MainWindow.xaml.cs, Flow.Launcher/ViewModel/MainViewModel.cs
Call sites updated to pass raw and trimmed texts to QueryBuilder.Build. Replaced _isQueryRunning with _progressQuery and _updateQuery; reworked cancellation, progress timing, results-updating/clearing, and gating of results-updated events by Query.Input.
Helpers
Flow.Launcher/Helper/ResultHelper.cs
Updated QueryBuilder.Build invocations to pass the raw query as the first argument and trimmed/raw as second where applicable.
Tests
Flow.Launcher.Test/QueryBuilderTest.cs
Updated QueryBuilder.Build calls to the new three-argument form; test assertions unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant MainWindow
    participant MainViewModel
    participant QueryBuilder
    participant Plugins

    User->>MainWindow: type rawInput
    MainWindow->>MainViewModel: Submit QueryText (rawInput)
    MainViewModel->>QueryBuilder: Build(rawInput, trimmedText, plugins)
    Note right of QueryBuilder #eef6ff: Sets Query.Input = rawInput\nand other Query fields
    QueryBuilder-->>MainViewModel: Query { Input, Search, RawQuery, ... }
    MainViewModel->>MainViewModel: set _progressQuery / _updateQuery
    MainViewModel->>Plugins: run plugin queries (async, cancellable)
    alt query still current
        MainViewModel->>MainWindow: show progress, update results
    else cancelled or replaced
        MainViewModel->>MainWindow: clear/hide results
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • taooceros
  • jjw24

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning Beyond adding the Input property to satisfy issue #2605, this pull request also overhauls the main view model’s update and cancellation logic, result clearing, progress tracking, and history event gating, which are not related to the untrimmed query support requested in the linked issue. Consider isolating the untrimmed input support into its own pull request and handling the broader view model update logic enhancements and result clearing in a separate change to keep each PR focused on a single concern.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly references the three core changes made in this pull request—improving update logic, fixing a logic issue, and adding the Input property—so it accurately summarizes the main modifications in a related way.
Linked Issues Check ✅ Passed This pull request implements the raw untrimmed input support required by issue #2605 by adding the Input property to Query, updating the Build method to accept and set Input, and revising the update logic to use Input instead of comparing RawQuery to QueryText.
Description Check ✅ Passed The description outlines the changes to update logic, the fix for raw query comparisons, the addition of the Input property, and the new result clearing behavior, all of which directly align with the code modifications in this pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch improve_update

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3ad0b8 and ae76b53.

📒 Files selected for processing (1)
  • Flow.Launcher/Helper/ResultHelper.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher/Helper/ResultHelper.cs (1)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (1)
  • QueryBuilder (7-63)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher/Helper/ResultHelper.cs (1)

23-23: Verify history reconstruction with identical input and text parameters.

Since rawQuery is passed as both the input and text arguments, Query.Input and Query.RawQuery will contain the same value when reconstructing queries from history. This loses the semantic distinction between untrimmed input and processed query that the PR introduces elsewhere.

Confirm that:

  1. Plugins handle queries from history correctly when Input equals RawQuery (both contain the stored, likely already-processed query)
  2. This approach doesn't break history-based result population or plugin behavior
  3. Consider whether storing the original untrimmed input in LastOpenedHistoryItem would better preserve the intent of the Input property (optional future enhancement)

The change is technically correct given the new API signature and the constraint that we don't have access to the original untrimmed input when reconstructing from history. However, verification ensures no edge cases are missed.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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
Member Author

Jack251970 commented May 4, 2025

@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.

@Jack251970
Copy link
Member Author

Jack251970 commented Sep 23, 2025

@jjw24 I failed to reproduce this issue during today's usage and fast typing. But since the first issue you pointed out is related to IResultUpdate, I reverted some of changes, and could you please test if it resolves that issue?

https://ci.appveyor.com/project/JohnTheGr8/flow-launcher/builds/52791393/artifacts

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f49a86a and e01109d.

📒 Files selected for processing (2)
  • 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 (1)
  • Flow.Launcher/MainWindow.xaml.cs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
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.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/PluginManager.cs (5)
  • PluginManager (23-821)
  • PluginManager (161-167)
  • ICollection (305-328)
  • ICollection (330-333)
  • PluginPair (459-462)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

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

🧹 Nitpick comments (6)
Flow.Launcher/ViewModel/MainViewModel.cs (6)

39-40: Naming and intent are clear; keep.

The split between progress tracking and update gating reads well. Consider brief XML docs to cement intent for future maintainers.


286-293: Harden ResultsUpdated gating and avoid mixed-token checks.

Use the resolved token for both the cancellation check and keep comparisons ordinal for perf/correctness on raw text.

-                    if (_updateQuery == null || e.Query.Input != _updateQuery.Input || e.Token.IsCancellationRequested)
+                    var token = e.Token == default ? _updateToken : e.Token;
+                    if (token.IsCancellationRequested
+                        || _updateQuery == null
+                        || !string.Equals(e.Query.Input, _updateQuery.Input, StringComparison.Ordinal))
                     {
                         return;
                     }
-
-                    var token = e.Token == default ? _updateToken : e.Token;

1417-1436: Progress-bar trigger: compare with ordinal and consider snapshot.

Use ordinal comparison for raw text; if you adopt the input snapshot above, compare against it for extra safety.

-                    if (_progressQuery != null && _progressQuery.Input == query.Input)
+                    if (_progressQuery != null &&
+                        string.Equals(_progressQuery.Input, query.Input, StringComparison.Ordinal))
                     {
                         ProgressBarVisibility = Visibility.Visible;
                     }

1687-1702: Minor: _lastQuery is never null in ctor; simplify null-propagation.

You can drop the null-conditional on _lastQuery for a tiny clarity bump. Not a blocker.

Based on learnings

-            if (_lastQuery?.ActionKeyword != query?.ActionKeyword)
+            if (_lastQuery.ActionKeyword != query?.ActionKeyword)

1350-1415: Potential cross-thread property updates (minor).

Property assignments (e.g., PluginIconPath, SearchIconVisibility) happen after the thread hop in the current code. With the compile fix above (use Task.Yield), you’ll continue on the UI context and avoid cross-thread UI-binding surprises.


286-323: Use ordinal comparisons consistently for raw text.

All string-equality checks on Input/RawQuery should be StringComparison.Ordinal.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e01109d and 61ee542.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs (8 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
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.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/PluginManager.cs (3)
  • PluginManager (23-821)
  • PluginManager (161-167)
  • PluginPair (459-462)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: gitStream.cm
🔇 Additional comments (14)
Flow.Launcher/ViewModel/MainViewModel.cs (14)

444-452: Correct: Build now receives both Input (untrimmed) and text (trimmed).

This aligns Backspace with the new QueryBuilder API and preserves user input semantics.


1337-1345: Don’t abort after shortcut expansion (stale guard).

ConstructQueryAsync can rewrite QueryText (builtin/custom shortcuts). Comparing query.Input with the live QueryText right after that will often differ and prematurely return, yielding an empty/stale result pane after expansions.

Apply this to snapshot the input before constructing the query and relax the guard to allow either the original input or the expanded RawQuery:

-            var query = await ConstructQueryAsync(QueryText, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
+            var inputSnapshot = QueryText;
+            var query = await ConstructQueryAsync(inputSnapshot, Settings.CustomShortcuts, Settings.BuiltinShortcuts);
@@
-                // Check if the input text matches the query text
-                if (query.Input != QueryText) return;
+                // Short-circuit only if user has typed something new unrelated to this query
+                var currentText = QueryText;
+                if (!string.Equals(currentText, inputSnapshot, StringComparison.Ordinal) &&
+                    !string.Equals(currentText, query.RawQuery, StringComparison.Ordinal))
+                {
+                    return;
+                }

1485-1499: Result-clearing logic looks correct; good early return when no update tasks.

This prevents stale results when home-page plugins are all disabled or absent.

If you want to be extra sure, test with:

  • ShowHistoryResultsForHomePage = false
  • All home plugins disabled
  • Enter/clear text to confirm the view clears.

1596-1599: Good: Build for whitespace path sets both Input and RawQuery empty.

This keeps IsHomeQuery true and avoids null queries.


1618-1619: Good: pass the method parameter as Input to avoid races.

Using queryText here ensures the built Query carries the exact input used for construction.


217-277: Channel consumer resiliency looks fine; continuation restarts on fault.

No action needed.


571-588: UI navigation helpers unchanged; LGTM.

Selection and preview update wiring remains consistent.

Also applies to: 607-622


1510-1517: ClearResults helper is cohesive and idempotent.

Approach to collapse/clear/reset states is sound.


1523-1572: Per-plugin query path is correct; good use of Task.Yield and cloning.

No issues spotted.


327-338: Clock/date timer ok.

PeriodicTimer loop is simple and cancellation-free as intended.


1951-1958: Dialog focus restore is guarded and logged; ok.

No changes requested.


2276-2303: Dispose pattern correct; writers completed and tasks disposed.

Looks good.


1379-1381: Compile-time error: TaskScheduler is not awaitable.

await TaskScheduler.Default; won’t compile and also risks property updates off the UI thread. Use an awaitable construct; you don’t need to hop threads here since plugin work is already offloaded per-plugin.

-                // Switch to ThreadPool thread
-                await TaskScheduler.Default;
+                // Yield once without changing context (plugin queries run on background tasks)
+                await Task.Yield();

1335-1499: No extra await TaskScheduler.Default or stale-query guards found
Only the await at MainViewModel.cs:1380 and the input guard at 1363 exist.

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.

@Jack251970 Jack251970 changed the title Improve update logic & Fix update logic issue & Input for Query Improve update logic & Fix update logic issue & Add Input for Query Sep 29, 2025
@Jack251970 Jack251970 modified the milestones: Future, 2.1.0 Sep 29, 2025

This comment has been minimized.

Updated comments across multiple files to standardize the phrasing from "work around" to "workaround" for consistency and clarity. Changes were made in `Directory.Build.props`, `Flow.Launcher.csproj`, and `MainWindow.xaml.cs`. These updates are non-functional and only affect documentation within the codebase.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Flow.Launcher/MainWindow.xaml.cs (1)

862-862: Fix forbidden pattern: "work around" → "workaround".

The phrase "work around" should be written as one word to comply with the project's style guidelines.

Apply this diff:

-            // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
+            // Initialize call twice to workaround multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

1483-1495: Remove duplicate assignment of _progressQuery = null.

The _progressQuery field is set to null at line 1483 within the try block and again at line 1494 in the finally block. The finally block assignment is sufficient to ensure cleanup in all cases.

Apply this diff:

         if (currentCancellationToken.IsCancellationRequested) return;
 
         // this should happen once after all queries are done so progress bar should continue
         // until the end of all querying
-        _progressQuery = null;
 
         if (!currentCancellationToken.IsCancellationRequested)
         {
             // update to hidden if this is still the current query
             ProgressBarVisibility = Visibility.Hidden;
         }
     }
     finally
     {
         // this make sures progress query is null when this query is canceled
         _progressQuery = null;
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61ee542 and 51be8d0.

📒 Files selected for processing (2)
  • Flow.Launcher/MainWindow.xaml.cs (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (7 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-08T21:12:12.060Z
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.

Applied to files:

  • Flow.Launcher/ViewModel/MainViewModel.cs
🧬 Code graph analysis (2)
Flow.Launcher/ViewModel/MainViewModel.cs (3)
Flow.Launcher.Plugin/Query.cs (2)
  • Query (8-113)
  • ToString (112-112)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (2)
  • Query (9-62)
  • QueryBuilder (7-63)
Flow.Launcher.Core/Plugin/PluginManager.cs (5)
  • PluginManager (23-821)
  • PluginManager (161-167)
  • ICollection (305-328)
  • ICollection (330-333)
  • PluginPair (459-462)
Flow.Launcher/MainWindow.xaml.cs (2)
Flow.Launcher.Core/Plugin/QueryBuilder.cs (1)
  • QueryBuilder (7-63)
Flow.Launcher.Core/Plugin/PluginManager.cs (2)
  • PluginManager (23-821)
  • PluginManager (161-167)
🪛 GitHub Actions: Check Spelling
Flow.Launcher/MainWindow.xaml.cs

[error] 862-862: Forbidden pattern: 'work around' matches a line_forbidden.patterns entry: '\bwork[- ]arounds?\b'

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (8)
Flow.Launcher/MainWindow.xaml.cs (1)

479-479: LGTM! Correct usage of the new QueryBuilder.Build signature.

The call correctly passes the untrimmed QueryTextBox.Text as the input parameter and the trimmed version as the text parameter, aligning with the new Input property feature.

Flow.Launcher/ViewModel/MainViewModel.cs (7)

39-40: LGTM! Query-based tracking improves state management.

Replacing the boolean _isQueryRunning with Query-based tracking fields provides more precise cancellation and state management by tracking which specific query is in progress.


286-286: LGTM! Correct use of Input property for stale query detection.

The guard now compares e.Query.Input with _updateQuery.Input, which correctly identifies stale queries by comparing the untrimmed original input rather than the trimmed/expanded RawQuery.

Based on PR objectives and author clarification to reviewer taooceros.


444-444: LGTM! Correct usage of the new QueryBuilder.Build signature.

The call correctly passes QueryText (untrimmed) as the input parameter and QueryText.Trim() as the text parameter.


1375-1376: Verify that await TaskScheduler.Default; compiles in your environment.

The code await TaskScheduler.Default; is not standard awaitable syntax. TaskScheduler does not implement GetAwaiter() in the standard .NET libraries.

If this compiles in your environment, you may be using a Visual Studio extension or custom awaiter. However, this will fail in most standard .NET environments.

Standard alternatives for switching to ThreadPool:

If the current syntax doesn't compile or you want more portable code, use:

-// Switch to ThreadPool thread
-await TaskScheduler.Default;
+// Switch to ThreadPool thread
+await Task.Run(() => { });

Or if you only need to yield execution without guaranteeing a thread switch:

-// Switch to ThreadPool thread
-await TaskScheduler.Default;
+// Yield execution
+await Task.Yield();

Note: Task.Yield() queues continuation but doesn't guarantee thread switch, while Task.Run(() => { }) ensures execution on ThreadPool.

Based on past review comments indicating this was discussed with reviewer taooceros.


1424-1434: LGTM! Correct progress bar timing with Input property comparison.

The progress bar logic correctly uses _progressQuery.Input == query.Input to verify that the current query is still active before showing the progress indicator.


1594-1594: LGTM! Correct handling of empty input.

For empty or whitespace input, both the input and text parameters are set to string.Empty, correctly indicating a home query with no user input.


1614-1614: LGTM! Correctly uses method parameter to avoid race condition.

The call correctly passes the immutable queryText parameter (not the mutable QueryText property) as the input argument, preventing race conditions where the property value could change between query construction and validation.

Based on past review comments indicating this race condition was previously flagged and fixed.

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 2
⚠️ non-alpha-in-dictionary 2

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.

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 review in progress Indicates that a review is in progress for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Support Untrimmed query for Flow Launcher's Query

3 participants