Skip to content

feat: preview image and text on path completion or hover#2371

Open
QuadnucYard wants to merge 4 commits into
Myriad-Dreamin:mainfrom
QuadnucYard:file-preview
Open

feat: preview image and text on path completion or hover#2371
QuadnucYard wants to merge 4 commits into
Myriad-Dreamin:mainfrom
QuadnucYard:file-preview

Conversation

@QuadnucYard
Copy link
Copy Markdown
Contributor

Preview file contents at path like markdown.

Supported formats:

  • image: png, jpg, jpeg, gif, svg, webp
  • text: xml, yml/yaml, toml, json, csv, txt, md, bib, csl, typ

Limitations

  • It will not display images exceeding the size limit (1MB).
image image image image

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 File Preview Module: Introduced a new file_preview module in crates/tinymist-query/src/analysis to centralize logic for generating file content previews.
  • Path Completion Previews: Path completion suggestions now include rich documentation with previews for supported image and text file types. This enhances the user experience by providing immediate context for file paths.
  • Hover Previews: The hover functionality has been extended to display file content previews when hovering over file paths, offering quick insights without needing to open the file.
  • Supported File Formats: The feature supports previews for various image formats (png, jpg, jpeg, gif, svg, webp) and text formats (xml, yml/yaml, toml, json, csv, txt, md, bib, csl, typ).
  • Preview Limitations: Previews are limited to files under 1MB in size. Images are encoded in base64, and text files are truncated and syntax-highlighted for readability.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. A potential panic in the text preview generation due to unsafe string slicing, which I've marked as high severity.
  2. 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.

Comment thread crates/tinymist-query/src/analysis/file_preview.rs Outdated
Comment thread crates/tinymist-query/src/analysis/completion/path.rs Outdated
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();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to use and enhance PathKind:

  • use ext_matcher to detect known file types quickly.

let base64_content = base64::engine::general_purpose::STANDARD.encode(content);

// Determine MIME type
let mime_type = match extension {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to use and enhance PathKind:

  • add PathKind::mime_type

/// Generate image preview with base64 encoding
fn generate_image_preview(
content: &[u8],
extension: &str,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to use PathKind

)
} else {
format!(
"![Image Preview](data:{};base64,{})\n\n**Size**: {:.1} KB",
Copy link
Copy Markdown
Owner

@Myriad-Dreamin Myriad-Dreamin Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this added field, which is not widely supported by clients, and fill the existing field CompletionItem::detail instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants