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

add CopyText and AutoCompleteText to some results in the sys plugin #3114

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

cibere
Copy link
Contributor

@cibere cibere commented Dec 7, 2024

Adds the CopyText and AutoCompleteText keys to the Open recycle bin, Open Flow Launcher's log location, and Open the location where Flow Launcher's settings are stored results.

Disclaimer

This code is untested (idk how to test it)
Elven helped me figure out how to test it through AppVeyor

This comment has been minimized.

Copy link

gitstream-cm bot commented Dec 7, 2024

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 Dec 7, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the Main class within the Flow.Launcher.Plugin.Sys namespace. The Commands method has been updated to enhance several Result objects by adding CopyText and AutoCompleteText properties. New variables for logPath, userDataPath, and recycleBinFolder were introduced to streamline result construction. Additionally, the Action delegate for the Open Recycle Bin result now references the recycleBinFolder variable, improving code maintainability by centralizing path definitions.

Changes

File Path Change Summary
Plugins/Flow.Launcher.Plugin.Sys/Main.cs Enhanced Commands method by adding CopyText and AutoCompleteText properties to results. Introduced logPath, userDataPath, and recycleBinFolder variables for better maintainability. Updated Action delegate for Open Recycle Bin to use recycleBinFolder.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FlowLauncher
    participant Commands

    User->>FlowLauncher: Request action (e.g., Open Recycle Bin)
    FlowLauncher->>Commands: Execute Commands method
    Commands->>Commands: Define logPath, userDataPath, recycleBinFolder
    Commands->>FlowLauncher: Return Result with CopyText and AutoCompleteText
    FlowLauncher->>User: Display results
Loading

🐇 "In the code where bunnies hop,
New paths and texts, we’ll never stop.
With logs and folders, neat and bright,
Our plugin's future is a delight!
So here’s to changes, big and small,
A joyful leap, we celebrate all!" 🐇

Possibly related PRs

  • [WebSearch] Add copy URL to menu #3082: The changes in this PR involve modifications to the Main class in the Flow.Launcher.Plugin.WebSearch namespace, specifically enhancing context menu functionality and adding a ContextData property to Result objects, which is similar to the enhancements made to the Commands method in the Main class of the Flow.Launcher.Plugin.Sys namespace. Both PRs focus on improving the functionality and maintainability of context-related features.

Suggested labels

enhancement, Explorer Plugin

Suggested reviewers

  • jjw24

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 29c9fd6 and fe4fcf6.

📒 Files selected for processing (1)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (5 hunks)
🔇 Additional comments (5)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (5)

136-138: LGTM! Good refactoring to improve maintainability.

Extracting these paths into variables reduces duplication and makes the code more maintainable.


300-300: LGTM! Changes align with PR discussion.

The implementation correctly uses the shell command for both copying and opening the recycle bin, which aligns with the discussed requirements in the PR.

Also applies to: 304-304


406-407: LGTM! Good addition for documentation URL access.

Adding copy and autocomplete functionality for the documentation URL improves user experience by providing quick access to the documentation.


419-420: LGTM! Consider verifying userdata path existence.

The implementation correctly allows copying and autocompleting the userdata path. However, it would be good to verify that the path exists before showing this result.

Also applies to: 423-423


393-394: LGTM! Consider verifying log path existence.

The implementation correctly allows copying and autocompleting the log path. However, it would be good to verify that the path exists before showing this result.

✅ Verification successful

Let me gather more information about how the log path is used in the codebase.


Let me check one more thing about the log directory creation and validation.


LGTM! The log directory is properly managed by the system.

The log path used in the Sys plugin is safe to use as it's the same path that's automatically created and managed by Flow.Launcher's logging system (Log.cs). The Log class ensures the directory exists by creating it during initialization, so there's no need for additional existence checks in the plugin.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the log path pattern exists in the codebase
# and if there are any error handling patterns around it

# Check for path existence checks
rg -A 3 "DataLocation\.DataDirectory\(\).+Logs.+Constant\.Version" 

# Check for any error handling patterns
ast-grep --pattern 'if (!File.Exists($_)) { $$$ }'

Length of output: 538


Script:

#!/bin/bash
# Check the broader context of how logPath is used
rg -B 5 -A 10 "var logPath = Path\.Combine\(DataLocation\.DataDirectory\(\), \"Logs\", Constant\.Version\)"

# Check if Directory.Exists is used instead of File.Exists
ast-grep --pattern 'if (!Directory.Exists($_)) { $$$ }'

# Check if there's any directory creation logic
ast-grep --pattern 'Directory.CreateDirectory($_)'

Length of output: 2477


Script:

#!/bin/bash
# Check how the log directory is initialized and validated
rg -B 5 -A 10 "CurrentLogDirectory"

# Check if there's any log directory validation in the Sys plugin
rg -B 3 -A 3 "Directory\.(Exists|CreateDirectory)" Plugins/Flow.Launcher.Plugin.Sys/

Length of output: 4059


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. (Experiment)
  • @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 and nitpick comments (2)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (2)

300-305: Consider adding error handling for the Process.Start call

The changes look good, but the Process.Start call should include error handling to gracefully handle cases where the recycle bin cannot be opened.

 Action = c =>
 {
-    {
-        System.Diagnostics.Process.Start("explorer", recycleBinFolder);
-    }
+    try
+    {
+        System.Diagnostics.Process.Start("explorer", recycleBinFolder);
+    }
+    catch (Exception ex)
+    {
+        context.API.ShowMsg("Error", $"Failed to open recycle bin: {ex.Message}");
+    }
     return true;
 }

420-424: LGTM! Consider adding tests for the new functionality

The changes look good, but since this code is untested, consider adding unit tests to verify:

  1. The CopyText and AutoCompleteText properties are correctly set
  2. The directory paths are correctly resolved

Would you like me to help create unit tests for these changes?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f46ee7 and 29c9fd6.

📒 Files selected for processing (1)
  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs (5 hunks)
🔇 Additional comments (4)
Plugins/Flow.Launcher.Plugin.Sys/Main.cs (4)

136-138: LGTM! Good refactoring to reduce duplication

The introduction of these variables improves code maintainability by centralizing path definitions that are used multiple times throughout the method.


394-395: LGTM! Good use of version-specific log path

The properties are correctly set to the version-specific log path, which helps users easily copy or auto-complete the correct log directory path.


407-408: LGTM! Documentation URL properly exposed

The properties are correctly set to the documentation URL constant, enabling easy access to Flow Launcher's documentation.


Line range hint 136-424: Consider implementing a comprehensive testing strategy

While the changes look good and follow a consistent pattern, a testing strategy should be implemented to ensure reliability. Consider:

  1. Unit tests for path resolution
  2. Integration tests for the new CopyText and AutoCompleteText functionality
  3. End-to-end tests for the complete user workflow

This will help ensure the new features work as expected across different environments and versions.

This comment has been minimized.

@cibere
Copy link
Contributor Author

cibere commented Dec 7, 2024

Ok, I managed to test it through appveyor, and it seems like everything works except copying the log location and userdata folder. Though I'm not sure why it isn't working This appears to be happening due to Flow Launcher copying the folders instead of the path, though as of now, I'm not sure how to fix this

@Yusyuriv
Copy link
Member

Yusyuriv commented Dec 8, 2024

I think we should add a way to opt out of this behavior. Right now it always tries to copy files. Maybe add another property to Result? Something like bool CopyTextAsPlainText?

@jjw24
Copy link
Member

jjw24 commented Dec 8, 2024

I think we should add a way to opt out of this behavior. Right now it always tries to copy files. Maybe add another property to Result? Something like bool CopyTextAsPlainText?

What do you mean? It copies query text if it's highlighted, or else the text passed from plugin. Which behaviour are you referring to?

@cibere
Copy link
Contributor Author

cibere commented Dec 8, 2024

I think we should add a way to opt out of this behavior. Right now it always tries to copy files. Maybe add another property to Result? Something like bool CopyTextAsPlainText?

What do you mean? It copies query text if it's highlighted, or else the text passed from plugin. Which behaviour are you referring to?

The part of the code where if the text from the plugin is a valid path, flow will copy the file/dir it points to instead of the path

@jjw24
Copy link
Member

jjw24 commented Dec 8, 2024

Ctrl+Shift+C hotkey does that already doesn't it? It copies text only from path.

@cibere
Copy link
Contributor Author

cibere commented Dec 8, 2024

Ctrl+Shift+C hotkey does that already doesn't it? It copies text only from path.

Oh, that does seem to work. I guess that means this PR works as it should

@jjw24
Copy link
Member

jjw24 commented Dec 8, 2024

Have you tested the copy and autocomplete works for Recycle bin command?

@Yusyuriv
Copy link
Member

Yusyuriv commented Dec 8, 2024

Ctrl+Shift+C hotkey does that already doesn't it? It copies text only from path.

Oh, I completely forgot about that one. Yes, it does work.

Have you tested the copy and autocomplete works for Recycle bin command?

It does autocomplete and copy the text shell:RecycleBinFolder, but since it's not a file path, the only thing Flow suggests after autocompleting it is searching about it online.

@cibere
Copy link
Contributor Author

cibere commented Dec 8, 2024

shell:RecycleBinFolder seems to open a virtual folder that includes the recycle bins of all of the user's current drives, and that virtual folder doesn't seem to have a filepath besides the shell shortcut and a guid.

I see 3 main options:

  1. Keep the changes I made to the open recycle bin result
  2. Revert the changes I made to the open recycle bin result
  3. Keep the CopyText key, but remove the AutoCompleteText key

I personally like 3 the most since CopyText works just fine, and as Yusyuriv mentioned, the auto complete just prompts you to search shell:recyclebinfolder online.

I'm just not sure which change I should make

@Yusyuriv
Copy link
Member

Yusyuriv commented Dec 9, 2024

I also think option 3 is the best, but I'd like to hear others' opinion.

@cibere
Copy link
Contributor Author

cibere commented Dec 11, 2024

I applied the third option for now, I can change it if needed though.

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.

@jjw24
Copy link
Member

jjw24 commented Dec 12, 2024

Option 3 sounds good too.

@jjw24 jjw24 enabled auto-merge December 12, 2024 10:19
@jjw24 jjw24 merged commit 86fc68b into Flow-Launcher:dev Dec 12, 2024
7 checks passed
@jjw24 jjw24 added enhancement New feature or request and removed 1 min review labels Dec 12, 2024
@jjw24 jjw24 added this to the 1.20.0 milestone Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants