Skip to content

Conversation

Jack251970
Copy link
Member

Follow on with #3203.

Add OriginQuery for topmost results & plugin info results so that we can remove result.OriginQuery null check.

@Jack251970 Jack251970 requested a review from Copilot May 11, 2025 09:10
@Jack251970 Jack251970 added the Dev branch only An issue or fix for the Dev branch build label May 11, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 11, 2025
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 addresses the OriginQuery null issue by updating the handling of OriginQuery in topmost results and plugin info context menus so that the previous null checks can be removed.

  • Removed conditional null-checks around result.OriginQuery in history recording and record management.
  • Updated ContextMenuPluginInfo signature to accept a Result instead of a plugin ID.
  • Propagated OriginQuery values in context menu result objects.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Flow.Launcher/ViewModel/MainViewModel.cs Removed null-check on result.OriginQuery and added its propagation to context menus
Flow.Launcher/Storage/TopMostRecord.cs Removed null-checks for result.OriginQuery in record lookup, removal and update logic
Comments suppressed due to low confidence (2)

Flow.Launcher/ViewModel/MainViewModel.cs:447

  • Removing the null-check for result.OriginQuery may lead to a NullReferenceException if result.OriginQuery is unexpectedly null. Ensure that result.OriginQuery is always non-null at this point or add alternative error handling.
_history.Add(result.OriginQuery.RawQuery);

Flow.Launcher/Storage/TopMostRecord.cs:15

  • The removal of the null-check for result.OriginQuery could cause a null dereference when accessing RawQuery. Confirm that result.OriginQuery is guaranteed to be non-null or implement a safeguard.
if (records.IsEmpty || !records.TryGetValue(result.OriginQuery.RawQuery, out var value))

@Jack251970 Jack251970 requested review from jjw24 and taooceros May 11, 2025 09:11
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 22
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

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.

Copy link

gitstream-cm bot commented May 11, 2025

🥷 Code experts: no user but you matched threshold 10

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

See details

Flow.Launcher/Storage/TopMostRecord.cs

Activity based on git-commit:

Jack251970
MAY
APR
MAR
FEB
JAN 30 additions & 9 deletions
DEC 3 additions & 2 deletions

Knowledge based on git-blame:
Jack251970: 47%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
MAY 486 additions & 294 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: 40%

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

Copy link

gitstream-cm bot commented May 11, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@Jack251970 Jack251970 enabled auto-merge May 11, 2025 09:11
Copy link

gitstream-cm bot commented May 11, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented May 11, 2025

📝 Walkthrough

Walkthrough

This change removes explicit null checks for result.OriginQuery in several methods within TopMostRecord and MainViewModel, allowing direct access to RawQuery and always adding it to history. Additionally, it updates the method signature of ContextMenuPluginInfo to accept a Result object instead of a plugin ID string, adjusting related calls and logic accordingly.

Changes

File(s) Change Summary
Flow.Launcher/Storage/TopMostRecord.cs Removed null checks for result.OriginQuery in IsTopMost, Remove, and AddOrUpdate, now always accessing RawQuery.
Flow.Launcher/ViewModel/MainViewModel.cs Removed null check on result.OriginQuery before adding to history; updated ContextMenuPluginInfo to accept Result instead of plugin ID; set OriginQuery property on returned Result objects; minor formatting adjustments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainViewModel
    participant TopMostRecord

    User->>MainViewModel: Selects a result (possibly with context menu)
    MainViewModel->>TopMostRecord: AddOrUpdate(result)
    Note right of TopMostRecord: No null check on result.OriginQuery<br/>Directly uses result.OriginQuery.RawQuery
    MainViewModel->>MainViewModel: Add result.OriginQuery.RawQuery to history (no null check)
Loading

Possibly related PRs

  • Flow-Launcher/Flow.Launcher#3203: Makes the opposite change by adding null checks for OriginQuery in TopMostRecord methods, directly related as it touches the same logic.
  • Flow-Launcher/Flow.Launcher#3099: Modifies TopMostRecord methods and retains null checks, focusing on thread safety with ConcurrentDictionary, indicating a related approach to the same area.

Suggested labels

bug

Suggested reviewers

  • taooceros

Poem

A bunny hopped through code so neat,
Null checks vanished in a single leap!
Now queries flow, unchecked, unbound,
History grows with every round.
With paws on keys, the rabbit grins—
For tidier logic, let the coding begin! 🐇✨

✨ 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: 0

🔭 Outside diff range comments (2)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

1616-1643: 💡 Verification agent

🧩 Analysis chain

Robustness concerns in ContextMenuPluginInfo

  1. PluginManager.GetPluginForId(id) may return null if the plugin is disabled/uninstalled between query & click.
  2. metadata.Website can be nullAPI.OpenUrl(null) might throw or open an empty tab.
  3. No glyph/icon is set; consider adding one for UI consistency.
- var metadata = PluginManager.GetPluginForId(id).Metadata;
+ var pluginPair = PluginManager.GetPluginForId(id);
+ if (pluginPair is null)
+     return new Result { Title = App.API.GetTranslation("pluginNotFound"), OriginQuery = result.OriginQuery };
+ var metadata = pluginPair.Metadata;
...
- Action = _ =>
- {
-     App.API.OpenUrl(metadata.Website);
-     return true;
- },
+ Action = _ =>
+ {
+     if (!string.IsNullOrWhiteSpace(metadata.Website))
+         App.API.OpenUrl(metadata.Website);
+     else
+         App.API.ShowMsg(metadata.Name, App.API.GetTranslation("websiteNotProvided"));
+     return true;
+ },

I’ll verify the nullability and property definitions before updating the comment.


🏁 Script executed:

#!/bin/bash
set -e

echo "1) Signature and nullability of GetPluginForId:"
rg -n "GetPluginForId" -C 2

echo
echo "2) Definition of PluginMetadata and its Website, IcoPath, PluginDirectory properties:"
rg -n "class PluginMetadata" -C 3
rg -n "Website" -C 2
rg -n "IcoPath" -C 2
rg -n "PluginDirectory" -C 2

Length of output: 71390


Digging into PluginMetadata to confirm nullability of Website and IcoPath:

#!/bin/bash
# Show PluginMetadata definition
sed -n '1,200p' Flow.Launcher.Plugin/PluginMetadata.cs

Handle missing plugin and website in ContextMenuPluginInfo

Ensure you don’t dereference a null plugin or open a null/empty URL:

• Add a null‐check for GetPluginForId(id) and return a “plugin not found” result.
• Guard metadata.Website against null/whitespace before calling OpenUrl.

File: Flow.Launcher/ViewModel/MainViewModel.cs (around lines 1616–1643)

-            var metadata = PluginManager.GetPluginForId(id).Metadata;
+            var pluginPair = PluginManager.GetPluginForId(id);
+            if (pluginPair is null)
+                return new Result
+                {
+                    Title       = App.API.GetTranslation("pluginNotFound"),
+                    OriginQuery = result.OriginQuery
+                };
+            var metadata = pluginPair.Metadata;-            Action = _ =>
-            {
-                App.API.OpenUrl(metadata.Website);
-                return true;
-            },
+            Action = _ =>
+            {
+                if (!string.IsNullOrWhiteSpace(metadata.Website))
+                    App.API.OpenUrl(metadata.Website);
+                return true;
+            },
Flow.Launcher/Storage/TopMostRecord.cs (1)

14-39: ⚠️ Potential issue

Eliminated null-checks can crash when OriginQuery is absent

result.OriginQuery.RawQuery is now dereferenced in three places without guarding against null.
While the PR’s intent is to guarantee this property, the guarantee relies on every code path (including 3rd-party plugins) honouring it. A single oversight will take down the app.

Suggested defensive code (minimal overhead):

- if (records.IsEmpty || !records.TryGetValue(result.OriginQuery.RawQuery, out var value))
+ var raw = result.OriginQuery?.RawQuery;
+ if (string.IsNullOrEmpty(raw) || records.IsEmpty || !records.TryGetValue(raw, out var value))

Replicate the same pattern in Remove and AddOrUpdate.

Alternatively, mark Result.OriginQuery as non-nullable in the model and enforce it via constructor or factory methods.

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

1154-1157: ContextMenuPluginInfo insertion looks good, but mind the ordering

Adding the plugin-info entry after the Top-Most item changes the order that users see items. If UI order matters (e.g., consistency with previous releases), consider inserting it before results.Add(ContextMenuTopMost(selected)) or document the new order in release notes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b2b49a and 0e6741c.

📒 Files selected for processing (2)
  • Flow.Launcher/Storage/TopMostRecord.cs (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (3)
Flow.Launcher/ViewModel/MainViewModel.cs (3)

445-449: Potential NullReferenceException when adding to history

result.OriginQuery is now assumed to be non-null (_history.Add(result.OriginQuery.RawQuery)), but 3rd-party plugins (or future internal code paths) can still create a Result without populating OriginQuery.
If that happens Flow crashes as soon as a user executes such a result.

- _history.Add(result.OriginQuery.RawQuery);
+ if (result.OriginQuery is not null)
+     _history.Add(result.OriginQuery.RawQuery);

Alternatively, add a contract/assertion earlier in the pipeline (e.g., when building Result) to guarantee non-nullness and fail fast during development rather than at runtime.

Please grep for new Result( patterns that omit OriginQuery to confirm whether any remain.


1590-1592: 👍 OriginQuery now propagated to Top-Most “remove” menu

Propagating OriginQuery ensures downstream consumers (TopMostRecord, history, etc.) can rely on its presence. No issues spotted.


1608-1610: 👍 OriginQuery now propagated to Top-Most “add” menu

Same remark as above – this removes the need for null guards elsewhere.

@Jack251970 Jack251970 changed the title Origin query null issue Fix origin query null issue May 11, 2025
@prlabeler prlabeler bot added the bug Something isn't working label May 11, 2025
@Jack251970 Jack251970 changed the title Fix origin query null issue Fix null origin query issue May 11, 2025
@Jack251970 Jack251970 merged commit 31c18b8 into dev May 11, 2025
16 checks passed
@Jack251970 Jack251970 deleted the origin_query_null_issue branch May 11, 2025 09:59
@jjw24 jjw24 removed the bug Something isn't working label May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev branch only An issue or fix for the Dev branch build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants