Skip to content

yazi: wire lua_ls type checking for font-dark previewer#9

Merged
kriswill merged 3 commits into
mainfrom
yazi-lua-lsp-types
May 25, 2026
Merged

yazi: wire lua_ls type checking for font-dark previewer#9
kriswill merged 3 commits into
mainfrom
yazi-lua-lsp-types

Conversation

@kriswill
Copy link
Copy Markdown
Owner

What

Makes lua_ls resolve yazi's Lua runtime API when editing
modules/home-manager/yazi/font-dark.yazi/main.lua, then clears every
diagnostic the now-working LSP surfaces.

Previously, opening the previewer override flagged ya, rt, fs, Command,
Err as undefined globals — the file lives outside config/nvim/, so it
inherited no Lua type info.

Changes

  • flake.nix — add yazi-plugins input (github:yazi-rs/plugins, flake = false); the official types.yazi LuaCATS stubs aren't in nixpkgs.
  • modules/home-manager/yazi/default.nix — deploy types.yazi to ~/.config/yazi/plugins/types.yazi (annotations-only; never referenced by a previewer/preloader/fetcher, so yazi never executes it).
  • .luarc.json (new) — runtime.version: Lua 5.4, types.yazi on workspace.library, and Err as a declared global. lua_ls picks this dir up as its root via the existing .luarc.json root-marker.
  • main.lua — resolve the real diagnostics: "64" pointsize (Command:arg takes strings), rename the shadowed err local, and one documented ---@diagnostic disable-next-line for an upstream stub false-positive.

On the one suppression

ya.preview_widget accepts a Renderable, an Error, or nil at runtime
(yazi-plugin/src/utils/preview.rs), but types.yazi annotates the parameter
as only Renderable|Renderable[]. The code is correct; the stub is incomplete.
yazi's own shipped preset triggers the same warning against yazi's own stubs.

Verification

  • nix build .#darwinConfigurations.k.system — passes.
  • lua-language-server --check on the file — no problems found.
  • stylua --check (as efm runs it) — clean.

kriswill added 2 commits May 25, 2026 10:31
Add the official yazi LuaCATS stubs (types.yazi plugin) and a .luarc.json
so lua_ls resolves the yazi runtime globals (ya, rt, fs, Command, Err) when
editing modules/home-manager/yazi/font-dark.yazi/main.lua.

- flake.nix: add yazi-plugins input (github:yazi-rs/plugins, flake=false)
- yazi module: deploy types.yazi to ~/.config/yazi/plugins/types.yazi
- .luarc.json: Lua 5.4 runtime, types.yazi on workspace.library, Err global
- main.lua: fix the diagnostics surfaced by the now-working LSP —
  "64" pointsize (Command:arg takes strings), rename the shadowed `err`
  local, and suppress the one upstream stub false-positive on
  ya.preview_widget (runtime accepts Error/nil; stub annotates Renderable
  only — see yazi-plugin/src/utils/preview.rs)
Replace the hardcoded `#dcd7ba` fill (which was kanagawa-wave's fg, not
this dragon flavor's `#c5c9c5`) with a value chosen at runtime from
`rt.term.light`: near-black on light terminals, fujiWhite on dark ones.

yazi exposes no flat palette or general "foreground" field — `th` is only
per-widget style tables — so light/dark mode is the cleanest theme-aware
signal available without hardcoding a flavor color.
Replace the binary `rt.term.light` heuristic with the flavor's actual
foreground, read at runtime via `th.mgr.border_style:raw().fg` (yazi has
no flat palette; `:raw()` serializes a Style to a table whose fg/bg are
"#RRGGBB" strings). Falls back to fujiWhite if unset.
@kriswill kriswill merged commit ca83901 into main May 25, 2026
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.

1 participant