-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: port
require()
and ya.sync()
to Rust to avoid plugin inform…
…ation initialization process (#853)
- Loading branch information
Showing
23 changed files
with
310 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub"]} | ||
{"version":"0.2","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers"],"language":"en","flagWords":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
package.path = BOOT.plugin_dir .. "/?.yazi/init.lua;" .. package.path | ||
|
||
local _require = require | ||
require = function(name) | ||
YAZI_PLUGIN_NAME, YAZI_SYNC_CALLS = name, 0 | ||
local mod = _require(name) | ||
mod._name = name | ||
return mod | ||
end | ||
|
||
YAZI_SYNC_BLOCKS = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(clippy::module_inception)] | ||
|
||
mod loader; | ||
mod require; | ||
|
||
pub use loader::*; | ||
use require::*; | ||
|
||
pub(super) fn init() { LOADER.with(Default::default); } | ||
|
||
pub(super) fn install(lua: &'static mlua::Lua) -> mlua::Result<()> { | ||
Require::install(lua)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use mlua::{ExternalResult, Function, IntoLua, Lua, MetaMethod, Table, TableExt, UserData, Value, Variadic}; | ||
|
||
use crate::RtRef; | ||
|
||
pub(super) struct Require; | ||
|
||
impl Require { | ||
pub(super) fn install(lua: &'static Lua) -> mlua::Result<()> { | ||
let globals = lua.globals(); | ||
|
||
let require = globals.raw_get::<_, Function>("require")?; | ||
globals.raw_set( | ||
"require", | ||
lua.create_function(move |lua, name: mlua::String| { | ||
lua.named_registry_value::<RtRef>("rt")?.swap(name.to_str()?); | ||
let module: Table = require.call(&name)?; | ||
lua.named_registry_value::<RtRef>("rt")?.reset(); | ||
|
||
module.raw_set("_name", &name)?; | ||
Self::create_mt(lua, name, module) | ||
})?, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn create_mt( | ||
lua: &'static Lua, | ||
name: mlua::String<'static>, | ||
module: Table<'static>, | ||
) -> mlua::Result<Table<'static>> { | ||
let ts = | ||
lua.create_table_from([("name", name.into_lua(lua)?), ("module", module.into_lua(lua)?)])?; | ||
|
||
let mt = lua.create_table()?; | ||
mt.raw_set( | ||
"__index", | ||
lua.create_function(|_, (ts, key): (Table, mlua::String)| { | ||
if key.to_str()? == "setup" { | ||
Ok(RequireSetup { name: ts.raw_get("name")?, module: ts.raw_get("module")? }) | ||
} else { | ||
Err("Only `require():setup()` is supported").into_lua_err() | ||
} | ||
})?, | ||
)?; | ||
|
||
ts.set_metatable(Some(mt)); | ||
Ok(ts) | ||
} | ||
} | ||
|
||
pub(super) struct RequireSetup { | ||
name: mlua::String<'static>, | ||
module: Table<'static>, | ||
} | ||
|
||
impl UserData for RequireSetup { | ||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { | ||
methods.add_meta_method(MetaMethod::Call, |lua, me, args: Variadic<Value>| { | ||
lua.named_registry_value::<RtRef>("rt")?.swap(me.name.to_str()?); | ||
let result = me.module.call_method::<_, Variadic<Value>>("setup", args); | ||
lua.named_registry_value::<RtRef>("rt")?.reset(); | ||
result | ||
}); | ||
} | ||
} |
Oops, something went wrong.