feat: Fix linter

This commit is contained in:
Jed 2026-07-06 22:09:33 +02:00
parent b1d0f10cec
commit 529ecbe6a6
10 changed files with 65 additions and 105 deletions

View file

@ -13,9 +13,7 @@ pub(super) struct Preview {
impl Deref for Preview { impl Deref for Preview {
type Target = yazi_core::tab::Preview; type Target = yazi_core::tab::Preview;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { &self.tab.preview }
&self.tab.preview
}
} }
impl Preview { impl Preview {

View file

@ -1,26 +1,12 @@
use std::{io::{BufRead, BufReader, Cursor, Seek}, path::PathBuf, sync::OnceLock};
use anyhow::{Result, anyhow, bail}; use anyhow::{Result, anyhow, bail};
use ratatui_core::{ use ratatui_core::{layout::Size, text::{Line, Span, Text}};
layout::Size, use syntect::{LoadingError, dumps, easy::HighlightLines, highlighting::{self, Theme, ThemeSet}, parsing::{SyntaxReference, SyntaxSet}};
text::{Line, Span, Text},
};
use std::{
io::{BufRead, BufReader, Cursor, Seek},
path::PathBuf,
sync::OnceLock,
};
use syntect::{
LoadingError, dumps,
easy::HighlightLines,
highlighting::{self, Theme, ThemeSet},
parsing::{SyntaxReference, SyntaxSet},
};
use yazi_binding::elements::HighlightPosition; use yazi_binding::elements::HighlightPosition;
use yazi_config::{THEME, YAZI}; use yazi_config::{THEME, YAZI};
use yazi_runner::previewer::PeekError; use yazi_runner::previewer::PeekError;
use yazi_shared::{ use yazi_shared::{id::{Id, Ids}, replace_to_printable};
id::{Id, Ids},
replace_to_printable,
};
use yazi_shim::ratatui::LineIter; use yazi_shim::ratatui::LineIter;
static INCR: Ids = Ids::new(); static INCR: Ids = Ids::new();
@ -77,9 +63,7 @@ impl Highlighter {
}) })
} }
pub fn abort() { pub fn abort() { INCR.next(); }
INCR.next();
}
fn highlight(mut self, position: Option<HighlightPosition>) -> Result<Text<'static>, PeekError> { fn highlight(mut self, position: Option<HighlightPosition>) -> Result<Text<'static>, PeekError> {
self.load_syntax()?; self.load_syntax()?;

View file

@ -6,14 +6,8 @@ use yazi_adapter::ADAPTOR;
use yazi_config::{LAYOUT, YAZI}; use yazi_config::{LAYOUT, YAZI};
use yazi_fs::{Entries, FilesOp, cha::Cha, file::File}; use yazi_fs::{Entries, FilesOp, cha::Cha, file::File};
use yazi_macro::render; use yazi_macro::render;
use yazi_runner::{ use yazi_runner::{RUNNER, previewer::{PeekError, PeekJob}};
RUNNER, use yazi_shared::{pool::Symbol, url::{UrlBuf, UrlLike}};
previewer::{PeekError, PeekJob},
};
use yazi_shared::{
pool::Symbol,
url::{UrlBuf, UrlLike},
};
use yazi_vfs::{VfsEntries, VfsFilesOp}; use yazi_vfs::{VfsEntries, VfsFilesOp};
use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock}; use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock};
@ -104,9 +98,7 @@ impl Preview {
ADAPTOR.image_hide().ok(); ADAPTOR.image_hide().ok();
} }
pub fn same_url(&self, url: &UrlBuf) -> bool { pub fn same_url(&self, url: &UrlBuf) -> bool { matches!(&self.lock, Some(l) if l.url == *url) }
matches!(&self.lock, Some(l) if l.url == *url)
}
pub fn same_file(&self, file: &File, mime: &str) -> bool { pub fn same_file(&self, file: &File, mime: &str) -> bool {
self.same_url(&file.url) self.same_url(&file.url)
@ -118,7 +110,5 @@ impl Preview {
&& matches!(&self.lock, Some(l) if l.skip == self.skip && l.search_idx == self.search_idx) && matches!(&self.lock, Some(l) if l.skip == self.skip && l.search_idx == self.search_idx)
} }
pub fn same_folder(&self, url: &UrlBuf) -> bool { pub fn same_folder(&self, url: &UrlBuf) -> bool { self.folder_lock.as_ref() == Some(url) }
self.folder_lock.as_ref() == Some(url)
}
} }

View file

@ -23,19 +23,13 @@ impl From<ActionCow> for PeekForm {
} }
impl From<bool> for PeekForm { impl From<bool> for PeekForm {
fn from(force: bool) -> Self { fn from(force: bool) -> Self { Self { force, ..Default::default() } }
Self { force, ..Default::default() }
}
} }
impl FromLua for PeekForm { impl FromLua for PeekForm {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
Err("unsupported".into_lua_err())
}
} }
impl IntoLua for PeekForm { impl IntoLua for PeekForm {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
Err("unsupported".into_lua_err())
}
} }

View file

@ -1,11 +1,7 @@
use std::{fmt::format, process::Stdio}; use std::process::Stdio;
use anyhow::Result; use anyhow::Result;
use tokio::{ use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
io::{AsyncBufReadExt, BufReader},
process::Command,
sync::mpsc::{self, UnboundedReceiver},
};
use yazi_fs::{FsUrl, file::File}; use yazi_fs::{FsUrl, file::File};
use yazi_shared::url::{AsUrl, UrlBuf, UrlLike}; use yazi_shared::url::{AsUrl, UrlBuf, UrlLike};
use yazi_vfs::VfsFile; use yazi_vfs::VfsFile;

View file

@ -1,8 +1,5 @@
use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value}; use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value};
use yazi_binding::{ use yazi_binding::{Error, elements::{Area, HighlightPosition}};
Error,
elements::{Area, HighlightPosition},
};
use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock}; use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock};
use yazi_fs::FsUrl; use yazi_fs::FsUrl;
use yazi_runner::previewer::PeekError; use yazi_runner::previewer::PeekError;
@ -38,7 +35,8 @@ impl Utils {
}) })
} }
// Note: You need to implement or update Highlighter::oneshot_with_highlight to accept line/column and highlight accordingly. // Note: You need to implement or update Highlighter::oneshot_with_highlight to
// accept line/column and highlight accordingly.
pub(super) fn preview_widget(lua: &Lua) -> mlua::Result<Function> { pub(super) fn preview_widget(lua: &Lua) -> mlua::Result<Function> {
lua.create_async_function(|_, (t, value): (Table, Value)| async move { lua.create_async_function(|_, (t, value): (Table, Value)| async move {