Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented Sep 21, 2025

Fixes #3185

@sxyazi sxyazi requested a review from Copilot September 21, 2025 15:28
Copy link

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

Fix compatibility handling when reusing previewer bytecode cache by validating cache and surfacing a user-visible error when incompatible.

  • Add compatibility check before invoking previewer; short-circuit to an error render if incompatible
  • Introduce peek_error to clear preview area and render a formatted error via MgrProxy
  • Add Area conversion from ratatui::layout::Rect to streamline passing layout rects into rendering APIs

Reviewed Changes

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

File Description
yazi-plugin/src/isolate/peek.rs Adds compatibility check and UI error rendering path; updates imports for Error/Renderable and MgrProxy usage
yazi-binding/src/elements/area.rs Adds Fromratatui::layout::Rect for Area to enable passing ratatui Rects directly into APIs expecting Area

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 23 to 31
let ct = CancellationToken::new();
if let Some(c) = LOADER.read().get(id) {
if c.sync_peek {
if let Err(e) = Loader::compatible_or_error(id, c) {
peek_error(file, mime, skip, e);
return None;
} else if c.sync_peek {
peek_sync(cmd, file, mime, skip);
} else {
peek_async(cmd, file, mime, skip, ct.clone());
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

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

The CancellationToken is created even when we immediately return on incompatibility or take the sync path. Initialize it only in the async branch to avoid unnecessary allocation and cloning. Example: move let ct = CancellationToken::new(); into the else { ... } branch before calling peek_async (and return it from there if applicable).

Copilot uses AI. Check for mistakes.
Comment on lines +119 to +134
fn peek_error(file: yazi_fs::File, mime: Symbol<str>, skip: usize, error: anyhow::Error) {
let area = LAYOUT.get().preview;
MgrProxy::update_peeked(UpdatePeekedOpt {
lock: PreviewLock {
url: file.url,
cha: file.cha,
mime: mime.to_string(),
skip,
area: area.into(),
data: vec![
Renderable::Clear(yazi_binding::elements::Clear { area: area.into() }),
Renderable::from(Error::custom(error.to_string())).with_area(area),
],
},
});
}
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider logging the compatibility error before updating the UI to match the error logging done in the async path and aid diagnostics in headless logs. For example: tracing::error!(error = %error, \"Previewer cache incompatible; rendering error\").

Copilot uses AI. Check for mistakes.
impl From<Rect> for Area {
fn from(rect: Rect) -> Self { Self::Rect(rect) }
}

Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

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

[nitpick] Add a brief doc comment explaining why this conversion exists (e.g., to allow passing ratatui::layout::Rect directly to APIs expecting Area). This helps future readers understand the intent and usage contexts.

Suggested change
/// Allows passing `ratatui::layout::Rect` directly to APIs expecting `Area`.

Copilot uses AI. Check for mistakes.
@sxyazi sxyazi merged commit e9742cb into main Sep 21, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-1d6814d7 branch September 21, 2025 15:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"@since" annotation behaves strangely

2 participants