Skip to content
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

New API for Record Key of Results & Fix Result Clone Issue #3194

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Jack251970
Copy link
Contributor

Add RecordKey for Result class.

  • The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
  • This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
  • If the plugin does not specific this, FL just uses Title and SubTitle to identify this result.

E.g. The records of plugin Edge Workspace have subtitles which can change based on the tab number of the edge workspace, but FL should regard these records as the same. (Full issue in cspotcode/Flow.Launcher.Plugin.EdgeWorkspaces#3)

Advantages

  • Title and SubTitle of the Result should be the properties for display, and RecordKey can be the property for identification. That way one plugin can specify any unique key, and FL will use it, ignoring title and subtitle. Plugin can get full control and can modify title or subtitle without breaking TopmostRecord and UserSelectedRecord.

  • A nullable identification field / RecordKey is also easier for non-C# plugins because it avoids extra RPC calling between C# and the external process. And in the case of Edge Workspaces, the Edge browser already assigns each workspace a unique UUID, so we can use that value for RecordKey.

More details in #3178.

@prlabeler prlabeler bot added the bug Something isn't working label Jan 21, 2025
Copy link

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ 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 Jan 21, 2025

🥷 Code experts: no user matched threshold 10

See details

Flow.Launcher.Plugin/Result.cs

Knowledge based on git-blame:

Flow.Launcher/Storage/TopMostRecord.cs

Knowledge based on git-blame:

Flow.Launcher/Storage/UserSelectedRecord.cs

Knowledge based on git-blame:

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

Copy link

gitstream-cm bot commented Jan 21, 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 Jan 21, 2025

📝 Walkthrough

Walkthrough

The pull request introduces several enhancements to the Result class in Flow Launcher's plugin system. New properties have been added to provide more metadata and customization options for results, including ContextData, PluginID, TitleToolTip, SubTitleToolTip, and others. The changes also modify hash code generation and equality comparison logic in related storage classes to incorporate a new RecordKey property, which allows for more precise identification and tracking of result records.

Changes

File Change Summary
Flow.Launcher.Plugin/Result.cs Added multiple new properties: ContextData, PluginID, TitleToolTip, SubTitleToolTip, PreviewPanel, ProgressBar, ProgressBarColor, Preview, AddSelectedCount, and RecordKey
Flow.Launcher/Storage/TopMostRecord.cs Added RecordKey property to Record class, updated Equals method to use RecordKey for comparison
Flow.Launcher/Storage/UserSelectedRecord.cs Modified GenerateResultHashCode and GenerateQueryAndResultHashCode methods to use RecordKey for hash code generation

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • jjw24
  • taooceros

Poem

🐰 A rabbit's tale of code so bright,
New properties taking flight!
Results now rich with metadata's grace,
Plugins dancing at a faster pace.
Hop, hop, hooray for Flow Launcher's might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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

🧹 Nitpick comments (3)
Flow.Launcher/Storage/TopMostRecord.cs (2)

53-53: Consider adding validation for RecordKey.

While the property implementation is correct, consider adding validation to ensure RecordKey follows any required format or constraints (e.g., UUID format for Edge workspaces).


57-67: LGTM! Robust equality comparison implementation.

The implementation correctly:

  1. Falls back to Title/SubTitle comparison when RecordKey is empty
  2. Uses RecordKey for comparison when available
  3. Always verifies PluginID to ensure results from different plugins are distinct

Consider adding a comment explaining why PluginID is always checked, as it might not be immediately obvious to future maintainers.

Flow.Launcher.Plugin/Result.cs (1)

265-271: LGTM! Consider adding usage examples to documentation.

The documentation clearly explains the purpose of RecordKey. Consider adding code examples to demonstrate:

  1. When to use RecordKey vs. Title/SubTitle
  2. Common patterns for generating RecordKey values
  3. Edge workspace UUID example mentioned in PR description
 /// <summary>
 /// The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
 /// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
 /// If the plugin does not specific this, FL just uses Title and SubTitle to identify this result.
+/// <example>
+/// <code>
+/// // Example 1: Using workspace UUID as RecordKey
+/// var result = new Result
+/// {
+///     Title = $"Workspace: {workspaceName}",
+///     SubTitle = $"Contains {tabCount} tabs",
+///     RecordKey = workspaceUuid // Stable identifier even when name/tab count changes
+/// };
+/// </code>
+/// </example>
 /// </summary>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8db59 and 1984426.

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

36-37: LGTM! Proper propagation of RecordKey.

The implementation correctly copies the RecordKey from Result to Record during creation.

Flow.Launcher/Storage/UserSelectedRecord.cs (2)

47-55: LGTM! Consistent hash code generation logic.

The implementation correctly handles both cases:

  1. Uses RecordKey for hash generation when available
  2. Falls back to Title/SubTitle combination when RecordKey is empty

68-76: LGTM! Verify hash collision probability.

The implementation correctly maintains consistency with GenerateResultHashCode while incorporating query components. However, let's verify that the hash generation doesn't increase collision probability with RecordKey.

✅ Verification successful

Hash collision probability verified - implementation is sound

The hash implementation uses a proven algorithm with a prime multiplier (31) that ensures good distribution. The RecordKey path doesn't increase collision probability compared to the Title+SubTitle path as it uses the same robust hashing strategy.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential hash collisions in the codebase
# Look for instances where different RecordKeys might generate the same hash

# Search for RecordKey assignments to analyze their patterns
rg -g '*.cs' 'RecordKey\s*=\s*.+' -A 2

Length of output: 702


Script:

#!/bin/bash
# Find GenerateStaticHashCode implementation and RecordKey assignments
ast-grep --pattern 'GenerateStaticHashCode($_) { $$$ }'

# Find where RecordKey is populated with actual values
rg -g '*.cs' '\.RecordKey\s*=\s*[^;]+;' -B 2 -A 2

Length of output: 109


Script:

#!/bin/bash
# Check the implementation file directly
cat Flow.Launcher/Storage/UserSelectedRecord.cs

# Search for GenerateStaticHashCode with broader pattern
rg -g '*.cs' 'GenerateStaticHashCode' -B 2 -A 5

# Find RecordKey property definition
ast-grep --pattern 'public string RecordKey { get; set; }'

Length of output: 7419

Flow.Launcher.Plugin/Result.cs (1)

188-197: LGTM! Complete property cloning.

The Clone method correctly includes all new properties, including RecordKey, ensuring complete object copying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant