From 529ecbe6a66882382c7eda9b1ca0ac44e24c8729 Mon Sep 17 00:00:00 2001 From: Jed Date: Mon, 6 Jul 2026 22:09:33 +0200 Subject: [PATCH] feat: Fix linter --- yazi-actor/src/lives/preview.rs | 4 +-- yazi-binding/src/elements/highlight.rs | 8 ++--- yazi-core/src/highlighter.rs | 42 ++++++++------------------ yazi-core/src/proxy.rs | 10 +++--- yazi-core/src/tab/preview.rs | 26 +++++----------- yazi-core/src/tab/preview_lock.rs | 20 ++++++------ yazi-parser/src/mgr/peek.rs | 28 +++++++---------- yazi-plugin/src/external/rg.rs | 14 +++------ yazi-plugin/src/utils/preview.rs | 8 ++--- yazi-runner/src/previewer/job.rs | 10 +++--- 10 files changed, 65 insertions(+), 105 deletions(-) diff --git a/yazi-actor/src/lives/preview.rs b/yazi-actor/src/lives/preview.rs index 61db852a..bee57a44 100644 --- a/yazi-actor/src/lives/preview.rs +++ b/yazi-actor/src/lives/preview.rs @@ -13,9 +13,7 @@ pub(super) struct Preview { impl Deref for Preview { type Target = yazi_core::tab::Preview; - fn deref(&self) -> &Self::Target { - &self.tab.preview - } + fn deref(&self) -> &Self::Target { &self.tab.preview } } impl Preview { diff --git a/yazi-binding/src/elements/highlight.rs b/yazi-binding/src/elements/highlight.rs index 57d454d1..a4bb205b 100644 --- a/yazi-binding/src/elements/highlight.rs +++ b/yazi-binding/src/elements/highlight.rs @@ -4,8 +4,8 @@ const EXPECTED: &str = "expected a table containing a line and a length"; #[derive(Clone, Debug)] pub struct HighlightPosition { - pub line: usize, - pub col: usize, + pub line: usize, + pub col: usize, pub length: usize, } @@ -24,8 +24,8 @@ impl FromLua for HighlightPosition { fn from_lua(value: Value, _: &Lua) -> mlua::Result { match value { Value::Table(tbl) => Ok(Self { - line: tbl.raw_get("line")?, - col: tbl.raw_get("col")?, + line: tbl.raw_get("line")?, + col: tbl.raw_get("col")?, length: tbl.raw_get("length")?, }), _ => Err(EXPECTED.into_lua_err()), diff --git a/yazi-core/src/highlighter.rs b/yazi-core/src/highlighter.rs index f7883d38..ad507970 100644 --- a/yazi-core/src/highlighter.rs +++ b/yazi-core/src/highlighter.rs @@ -1,42 +1,28 @@ +use std::{io::{BufRead, BufReader, Cursor, Seek}, path::PathBuf, sync::OnceLock}; + use anyhow::{Result, anyhow, bail}; -use ratatui_core::{ - layout::Size, - 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 ratatui_core::{layout::Size, text::{Line, Span, Text}}; +use syntect::{LoadingError, dumps, easy::HighlightLines, highlighting::{self, Theme, ThemeSet}, parsing::{SyntaxReference, SyntaxSet}}; use yazi_binding::elements::HighlightPosition; use yazi_config::{THEME, YAZI}; use yazi_runner::previewer::PeekError; -use yazi_shared::{ - id::{Id, Ids}, - replace_to_printable, -}; +use yazi_shared::{id::{Id, Ids}, replace_to_printable}; use yazi_shim::ratatui::LineIter; static INCR: Ids = Ids::new(); pub struct Highlighter { - path: PathBuf, + path: PathBuf, reader: BufReader, - skip: usize, - size: Size, + skip: usize, + size: Size, ticket: Id, - theme: &'static Theme, + theme: &'static Theme, syntaxes: &'static SyntaxSet, - inner: Option>, - syntax: Option<&'static SyntaxReference>, + inner: Option>, + syntax: Option<&'static SyntaxReference>, } impl Highlighter { @@ -77,9 +63,7 @@ impl Highlighter { }) } - pub fn abort() { - INCR.next(); - } + pub fn abort() { INCR.next(); } fn highlight(mut self, position: Option) -> Result, PeekError> { self.load_syntax()?; @@ -265,7 +249,7 @@ impl Highlighter { Span { content: s.into(), - style: ratatui_core::style::Style { + style: ratatui_core::style::Style { fg: Self::to_ansi_color(style.foreground), // bg: Self::to_ansi_color(style.background), add_modifier: modifier, diff --git a/yazi-core/src/proxy.rs b/yazi-core/src/proxy.rs index 387c9e5c..88b069ce 100644 --- a/yazi-core/src/proxy.rs +++ b/yazi-core/src/proxy.rs @@ -44,14 +44,14 @@ impl MgrProxy { pub fn update_peeked_error(job: PeekJob, error: String) { let area = LAYOUT.get().preview; Self::update_peeked(PreviewLock { - url: job.file.url, - cha: job.file.cha, + url: job.file.url, + cha: job.file.cha, mime: job.mime, - skip: job.skip, + skip: job.skip, search_idx: job.search_idx, - area: area.into(), - data: vec![ + area: area.into(), + data: vec![ Renderable::Clear(Default::default()).with_area(area), Renderable::from(Error::custom(error)).with_area(area), ], diff --git a/yazi-core/src/tab/preview.rs b/yazi-core/src/tab/preview.rs index b2b1816e..79a16860 100644 --- a/yazi-core/src/tab/preview.rs +++ b/yazi-core/src/tab/preview.rs @@ -6,27 +6,21 @@ use yazi_adapter::ADAPTOR; use yazi_config::{LAYOUT, YAZI}; use yazi_fs::{Entries, FilesOp, cha::Cha, file::File}; use yazi_macro::render; -use yazi_runner::{ - RUNNER, - previewer::{PeekError, PeekJob}, -}; -use yazi_shared::{ - pool::Symbol, - url::{UrlBuf, UrlLike}, -}; +use yazi_runner::{RUNNER, previewer::{PeekError, PeekJob}}; +use yazi_shared::{pool::Symbol, url::{UrlBuf, UrlLike}}; use yazi_vfs::{VfsEntries, VfsFilesOp}; use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock}; #[derive(Default, Debug)] pub struct Preview { - pub lock: Option, - pub skip: usize, + pub lock: Option, + pub skip: usize, pub search_idx: Option, - handle: Option>, + handle: Option>, pub folder_lock: Option, - folder_loader: Option>, + folder_loader: Option>, } impl Preview { @@ -104,9 +98,7 @@ impl Preview { ADAPTOR.image_hide().ok(); } - pub fn same_url(&self, url: &UrlBuf) -> bool { - matches!(&self.lock, Some(l) if l.url == *url) - } + pub fn same_url(&self, url: &UrlBuf) -> bool { matches!(&self.lock, Some(l) if l.url == *url) } pub fn same_file(&self, file: &File, mime: &str) -> bool { 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) } - pub fn same_folder(&self, url: &UrlBuf) -> bool { - self.folder_lock.as_ref() == Some(url) - } + pub fn same_folder(&self, url: &UrlBuf) -> bool { self.folder_lock.as_ref() == Some(url) } } diff --git a/yazi-core/src/tab/preview_lock.rs b/yazi-core/src/tab/preview_lock.rs index f78904b4..0b9c82c2 100644 --- a/yazi-core/src/tab/preview_lock.rs +++ b/yazi-core/src/tab/preview_lock.rs @@ -7,14 +7,14 @@ use yazi_widgets::Renderable; #[derive(Clone, Debug, Default)] pub struct PreviewLock { - pub url: yazi_shared::url::UrlBuf, - pub cha: yazi_fs::cha::Cha, + pub url: yazi_shared::url::UrlBuf, + pub cha: yazi_fs::cha::Cha, pub mime: Symbol, - pub skip: usize, + pub skip: usize, pub search_idx: Option, - pub area: Rect, - pub data: Vec, + pub area: Rect, + pub data: Vec, } impl_data_any!(PreviewLock); @@ -26,14 +26,14 @@ impl TryFrom for PreviewLock { let file: FileRef = t.raw_get("file")?; file.borrow(|f| { Ok(Self { - url: f.url_owned(), - cha: f.cha, + url: f.url_owned(), + cha: f.cha, mime: t.raw_get::("mime")?.to_str()?.intern(), - skip: t.raw_get("skip")?, + skip: t.raw_get("skip")?, search_idx: t.raw_get("search_idx")?, - area: t.raw_get("area")?, - data: Default::default(), + area: t.raw_get("area")?, + data: Default::default(), }) }) } diff --git a/yazi-parser/src/mgr/peek.rs b/yazi-parser/src/mgr/peek.rs index bccdaf20..432952a8 100644 --- a/yazi-parser/src/mgr/peek.rs +++ b/yazi-parser/src/mgr/peek.rs @@ -3,39 +3,33 @@ use yazi_shared::{event::ActionCow, url::UrlBuf}; #[derive(Debug, Default)] pub struct PeekForm { - pub skip: Option, - pub force: bool, - pub only_if: Option, + pub skip: Option, + pub force: bool, + pub only_if: Option, pub upper_bound: bool, - pub search_idx: Option, + pub search_idx: Option, } impl From for PeekForm { fn from(mut a: ActionCow) -> Self { Self { - skip: a.first().ok(), - force: a.bool("force"), - only_if: a.take("only-if").ok(), + skip: a.first().ok(), + force: a.bool("force"), + only_if: a.take("only-if").ok(), upper_bound: a.bool("upper-bound"), - search_idx: a.take("search-idx").ok(), + search_idx: a.take("search-idx").ok(), } } } impl From for PeekForm { - fn from(force: bool) -> Self { - Self { force, ..Default::default() } - } + fn from(force: bool) -> Self { Self { force, ..Default::default() } } } impl FromLua for PeekForm { - fn from_lua(_: Value, _: &Lua) -> mlua::Result { - Err("unsupported".into_lua_err()) - } + fn from_lua(_: Value, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } } impl IntoLua for PeekForm { - fn into_lua(self, _: &Lua) -> mlua::Result { - Err("unsupported".into_lua_err()) - } + fn into_lua(self, _: &Lua) -> mlua::Result { Err("unsupported".into_lua_err()) } } diff --git a/yazi-plugin/src/external/rg.rs b/yazi-plugin/src/external/rg.rs index 5bc3465f..7a83c490 100644 --- a/yazi-plugin/src/external/rg.rs +++ b/yazi-plugin/src/external/rg.rs @@ -1,20 +1,16 @@ -use std::{fmt::format, process::Stdio}; +use std::process::Stdio; use anyhow::Result; -use tokio::{ - io::{AsyncBufReadExt, BufReader}, - process::Command, - sync::mpsc::{self, UnboundedReceiver}, -}; +use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}}; use yazi_fs::{FsUrl, file::File}; use yazi_shared::url::{AsUrl, UrlBuf, UrlLike}; use yazi_vfs::VfsFile; pub struct RgOpt { - pub cwd: UrlBuf, - pub hidden: bool, + pub cwd: UrlBuf, + pub hidden: bool, pub subject: String, - pub args: Vec, + pub args: Vec, } pub fn rg(opt: RgOpt) -> Result> { diff --git a/yazi-plugin/src/utils/preview.rs b/yazi-plugin/src/utils/preview.rs index 619ce5d2..d869d906 100644 --- a/yazi-plugin/src/utils/preview.rs +++ b/yazi-plugin/src/utils/preview.rs @@ -1,8 +1,5 @@ use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value}; -use yazi_binding::{ - Error, - elements::{Area, HighlightPosition}, -}; +use yazi_binding::{Error, elements::{Area, HighlightPosition}}; use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock}; use yazi_fs::FsUrl; 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 { lua.create_async_function(|_, (t, value): (Table, Value)| async move { diff --git a/yazi-runner/src/previewer/job.rs b/yazi-runner/src/previewer/job.rs index e8430654..5db06144 100644 --- a/yazi-runner/src/previewer/job.rs +++ b/yazi-runner/src/previewer/job.rs @@ -6,10 +6,10 @@ use yazi_shared::{data::Sendable, pool::Symbol}; #[derive(Clone, Debug)] pub struct PeekJob { - pub previewer: PreviewerArc, - pub file: File, - pub mime: Symbol, - pub skip: usize, + pub previewer: PreviewerArc, + pub file: File, + pub mime: Symbol, + pub skip: usize, pub search_idx: Option, } @@ -31,7 +31,7 @@ impl IntoLua for PeekJob { // --- Seek #[derive(Clone, Debug)] pub struct SeekJob { - pub file: File, + pub file: File, pub units: i16, }