feat: preview image and text on path completion or hover#2371
feat: preview image and text on path completion or hover#2371QuadnucYard wants to merge 4 commits into
Conversation
Summary of ChangesHello @QuadnucYard, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the developer experience by integrating file content previews directly into the path completion and hover features. Users can now quickly inspect the contents of image and text files referenced by paths, streamlining workflows and reducing the need to navigate away from the current context to view file details. This enhancement provides immediate visual and textual feedback, making path resolution more intuitive and efficient. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a file preview feature for completions and hovers, which is a great enhancement for user experience. The implementation is well-structured, with a new file_preview module containing the core logic.
I've found a couple of areas for improvement:
- A potential panic in the text preview generation due to unsafe string slicing, which I've marked as high severity.
- An opportunity to use a more idiomatic and efficient way to get file extensions in one of the new functions.
Overall, this is a solid contribution. Addressing these points will make the new feature more robust.
| let text_content = String::from_utf8_lossy(content); | ||
|
|
||
| // Limit preview length (first LENGTH_LIMIT characters or LINE_LIMIT lines) | ||
| let lines: Vec<&str> = text_content.lines().take(LINE_LIMIT).collect(); |
There was a problem hiding this comment.
This text_content.lines, reading full content, could bring performance issue. The correct implementation should add an optional method to world world.file_by_id_with_range_to_read(id, 0..LENGTH_LIMIT) to prevent fully reading and previewing large files.
| )); | ||
| } | ||
|
|
||
| if IMAGE_EXTENSIONS.contains(&extension) { |
There was a problem hiding this comment.
refactor to use and enhance PathKind:
- use
ext_matcherto detect known file types quickly.
| let base64_content = base64::engine::general_purpose::STANDARD.encode(content); | ||
|
|
||
| // Determine MIME type | ||
| let mime_type = match extension { |
There was a problem hiding this comment.
refactor to use and enhance PathKind:
- add
PathKind::mime_type
| /// Generate image preview with base64 encoding | ||
| fn generate_image_preview( | ||
| content: &[u8], | ||
| extension: &str, |
| ) | ||
| } else { | ||
| format!( | ||
| "\n\n**Size**: {:.1} KB", |
There was a problem hiding this comment.
remove this long image preview, we could add todos or achieve them intermediately:
// todo: add command to view file using system software (viewer).
// todo: it is not intutive to disallow image preview if `supports_html` is false, so we may add additional flag to determine whether to enable image preview (may be `enable_image_preview`).
| }; | ||
|
|
||
| // Determine syntax highlighting language | ||
| let language = match extension { |
There was a problem hiding this comment.
refactor to use and enhance PathKind:
- add
PathKind::markdown_language
|
|
||
| /// A human-readable string that represents a doc-comment. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub documentation: Option<Documentation>, |
There was a problem hiding this comment.
remove this added field, which is not widely supported by clients, and fill the existing field CompletionItem::detail instead.
Preview file contents at path like markdown.
Supported formats:
Limitations