From 6a8668fab5bba176f19c40776aaab5b393b11263 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 23 Feb 2026 17:25:57 -0500 Subject: [PATCH] fix(ci): luacats support --- doc/nonicons.nvim.txt | 10 +++++ lua/nonicons/hi-test.lua | 85 +++++++++++++++++++++++++++++++++++++++ lua/nonicons/init.lua | 8 ++++ lua/nonicons/override.lua | 6 +++ lua/nonicons/resolve.lua | 8 ++++ plugin/nonicons.lua | 4 ++ 6 files changed, 121 insertions(+) create mode 100644 lua/nonicons/hi-test.lua diff --git a/doc/nonicons.nvim.txt b/doc/nonicons.nvim.txt index 0fd5043..8b43865 100644 --- a/doc/nonicons.nvim.txt +++ b/doc/nonicons.nvim.txt @@ -232,6 +232,16 @@ iTerm2 ~ Preferences > Profiles > Text > Non-ASCII Font > select Nonicons +============================================================================== +COMMANDS *nonicons-commands* + + *:NoniconsHiTest* +`:NoniconsHiTest` + Open a scratch buffer listing every icon in the nonicons font alongside + its name, Unicode codepoint, and which extensions / filenames / filetypes + map to it. Use this to visually verify that glyphs render correctly and + that resolution tables point to the intended icons. + ============================================================================== HEALTH CHECK *nonicons-health* diff --git a/lua/nonicons/hi-test.lua b/lua/nonicons/hi-test.lua new file mode 100644 index 0000000..ed22827 --- /dev/null +++ b/lua/nonicons/hi-test.lua @@ -0,0 +1,85 @@ +local mapping = require('nonicons.mapping') +local resolve = require('nonicons.resolve') + +---@param name string +---@return string +local function char(name) + local code = mapping[name] + if code then + return vim.fn.nr2char(code) + end + return '?' +end + +---@param t table +---@return string[] +local function sorted_keys(t) + local keys = {} + for k in pairs(t) do + keys[#keys + 1] = k + end + table.sort(keys) + return keys +end + +---@param t table +---@return table +local function invert(t) + local inv = {} + for k, v in pairs(t) do + inv[v] = inv[v] or {} + inv[v][#inv[v] + 1] = k + end + for _, list in pairs(inv) do + table.sort(list) + end + return inv +end + +return function() + local lines = {} ---@type string[] + + local ext_by_icon = invert(resolve.ext_map) + local fname_by_icon = invert(resolve.filename_map) + local ft_by_icon = invert(resolve.ft_map) + + local icon_names = sorted_keys(mapping) + + lines[#lines + 1] = 'nonicons.nvim — icon reference' + lines[#lines + 1] = string.rep('=', 72) + lines[#lines + 1] = '' + lines[#lines + 1] = string.format(' %-4s %-28s %-7s %s', 'ICON', 'NAME', 'CODE', 'MAPPED FROM') + lines[#lines + 1] = string.rep('-', 72) + + for _, name in ipairs(icon_names) do + local sources = {} ---@type string[] + if ext_by_icon[name] then + for _, ext in ipairs(ext_by_icon[name]) do + sources[#sources + 1] = 'ext:' .. ext + end + end + if fname_by_icon[name] then + for _, fname in ipairs(fname_by_icon[name]) do + sources[#sources + 1] = 'file:' .. fname + end + end + if ft_by_icon[name] then + for _, ft in ipairs(ft_by_icon[name]) do + sources[#sources + 1] = 'ft:' .. ft + end + end + + local src_str = #sources > 0 and table.concat(sources, ', ') or '' + lines[#lines + 1] = string.format(' %s %-28s U+%04X %s', char(name), name, mapping[name], src_str) + end + + lines[#lines + 1] = '' + lines[#lines + 1] = string.format('%d icons total', #icon_names) + + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + vim.bo[buf].modifiable = false + vim.bo[buf].buftype = 'nofile' + vim.bo[buf].bufhidden = 'wipe' + vim.api.nvim_set_current_buf(buf) +end diff --git a/lua/nonicons/init.lua b/lua/nonicons/init.lua index 42c1539..e80afae 100644 --- a/lua/nonicons/init.lua +++ b/lua/nonicons/init.lua @@ -24,8 +24,11 @@ local function ensure_initialized() initialized = true end +---@type table M.mapping = require('nonicons.mapping') +---@param name string Icon name +---@return string? glyph function M.get(name) local code = M.mapping[name] if code then @@ -40,6 +43,9 @@ function M.apply() end end +---@param name string? Filename (e.g. `'init.lua'`) +---@param ext string? File extension (e.g. `'lua'`) +---@return string? glyph function M.get_icon(name, ext) local key = require('nonicons.resolve').resolve_name(name, ext) if key then @@ -47,6 +53,8 @@ function M.get_icon(name, ext) end end +---@param ft string Vim filetype +---@return string? glyph function M.get_icon_by_filetype(ft) local key = require('nonicons.resolve').resolve_filetype(ft) if key then diff --git a/lua/nonicons/override.lua b/lua/nonicons/override.lua index 64cccc1..bd44c8b 100644 --- a/lua/nonicons/override.lua +++ b/lua/nonicons/override.lua @@ -1,6 +1,8 @@ local mapping = require('nonicons.mapping') local resolve_mod = require('nonicons.resolve') +---@param name string +---@return string? local function char(name) local code = mapping[name] if code then @@ -8,8 +10,12 @@ local function char(name) end end +---@type string local fallback_icon +---@param name string? +---@param ext string? +---@return string local function resolve(name, ext) local key = resolve_mod.resolve_name(name, ext) if key then diff --git a/lua/nonicons/resolve.lua b/lua/nonicons/resolve.lua index 42a881a..c7906ef 100644 --- a/lua/nonicons/resolve.lua +++ b/lua/nonicons/resolve.lua @@ -1,5 +1,6 @@ local M = {} +---@type table M.ext_map = { lua = 'lua', luac = 'lua', @@ -287,6 +288,7 @@ M.ext_map = { mojo = 'code', } +---@type table M.filename_map = { ['dockerfile'] = 'docker', ['containerfile'] = 'docker', @@ -421,6 +423,7 @@ M.filename_map = { ['code_of_conduct.md'] = 'book', } +---@type table M.ft_map = { typescriptreact = 'react', javascriptreact = 'react', @@ -434,6 +437,9 @@ M.ft_map = { latex = 'book', } +---@param name string? Filename (e.g. `'init.lua'`) +---@param ext string? File extension (e.g. `'lua'`) +---@return string? icon_name function M.resolve_name(name, ext) if ext and M.ext_map[ext] then return M.ext_map[ext] @@ -459,6 +465,8 @@ function M.resolve_name(name, ext) end end +---@param ft string? Vim filetype +---@return string? icon_name function M.resolve_filetype(ft) if not ft then return diff --git a/plugin/nonicons.lua b/plugin/nonicons.lua index 7219658..e381004 100644 --- a/plugin/nonicons.lua +++ b/plugin/nonicons.lua @@ -4,3 +4,7 @@ end vim.g.loaded_nonicons = 1 require('nonicons').apply() + +vim.api.nvim_create_user_command('NoniconsHiTest', function() + require('nonicons.hi-test')() +end, { desc = 'nonicons: display all icons' })