Skip to content

[audit] image.lua — dead code, unused require, and unimplemented vim.ui.img API #289

Description

@stanfish06

What

lua/config/image.lua has two distinct problems:

1. Unused require("lib.ui") — line 1

local mod_ui = require("lib.ui")

mod_ui is assigned but never referenced anywhere in the file. lib/ui.lua is loaded at Neovim startup for no effect. The lib/ui.lua module itself only exports Window.create_tmp_float_window(), which is also never called from anywhere in the config.

2. preview_image() is dead code using an unimplemented API — lines 3–11

local function preview_image(path)
    local id = vim.ui.img.set(
     vim.fn.readblob(path),
     { row = 0, col = 0, width = 100, height = 50, zindex = 0 }
    )
    return id
end
  • preview_image is never called; there is no user command or keymap that invokes it.
  • vim.ui.img.set() references an API that is still an open proposal (image API neovim/neovim#30889) and is not available in current Neovim stable releases.
  • The -- image api does not associate with window at this point, check later comment (line 5 in the original) confirms this is intentional WIP.

Where

lua/config/image.lua:1–12 (the entire file)
lua/lib/ui.lua — loaded unnecessarily, also contains dead create_tmp_float_window()

Why it matters

  • A require("lib.ui") at startup wastes module load time (trivial but unnecessary).
  • If vim.ui.img ever ships as a stable API, the code needs to be wired up before it does anything useful.
  • If vim.ui.img never ships (or lands under a different name), the file is a permanent stub.

Recommended action

Two options:

Option A — activate the feature: When vim.ui.img is available in the running Neovim, expose preview_image via a :ImagePreview command with a pcall guard:

local ok, _ = pcall(function() return vim.ui.img end)
if ok then
    vim.api.nvim_create_user_command("ImagePreview", function(opts)
        preview_image(vim.fn.expand(opts.args))
    end, { nargs = 1, complete = "file" })
end

Option B — remove the stub: Drop image.lua from init.lua, remove require("lib.ui"), and leave a TODO comment in init.lua pointing to neovim/neovim#30889 for when the API lands.

Also consider removing or trimming lib/ui.lua — it exposes only Window.create_tmp_float_window() which duplicates what vim.api.nvim_open_win() does in 4 lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions