* refactor: extract resolution tables into resolve module Problem: ext_map, filename_map, and resolve() are locked inside override.lua as locals, making them inaccessible to any code path that doesn't go through the devicons monkey-patch. Solution: extract all resolution tables and logic into a new nonicons.resolve module. Fix Gemfile/Jenkinsfile case bug (keys were uppercase but resolve() lowercases input before lookup). Add ft_map for vim filetypes that don't match extension or mapping keys. * refactor: wire override.lua to resolve module Problem: override.lua still has its own copies of ext_map, filename_map, and resolve(), duplicating the newly extracted resolve module. Solution: replace local tables and resolve() with imports from nonicons.resolve. Update all *_by_filetype overrides to use resolve_filetype() instead of raw ext_map[ft], gaining ft_map fallback and direct mapping key lookup. * feat: add get_icon and get_icon_by_filetype API Problem: plugins that don't use devicons have no way to get nonicons glyphs for files. The only integration path is the devicons monkey-patch via apply(). Solution: add get_icon(name, ext) and get_icon_by_filetype(ft) to the public API in init.lua. Both use lazy require of the resolve module and return nil on miss so callers decide fallback. Document both functions in vimdoc and update the oil.nvim recipe.
57 lines
1 KiB
Lua
57 lines
1 KiB
Lua
local M = {}
|
|
|
|
---@class nonicons.Config
|
|
---@field override boolean
|
|
|
|
---@type nonicons.Config
|
|
local default = {
|
|
override = true,
|
|
}
|
|
|
|
local initialized = false
|
|
|
|
---@type nonicons.Config
|
|
local config
|
|
|
|
local function ensure_initialized()
|
|
if initialized then
|
|
return
|
|
end
|
|
local user = vim.g.nonicons or {}
|
|
vim.validate('nonicons', user, 'table')
|
|
vim.validate('nonicons.override', user.override, 'boolean', true)
|
|
config = vim.tbl_deep_extend('force', default, user)
|
|
initialized = true
|
|
end
|
|
|
|
M.mapping = require('nonicons.mapping')
|
|
|
|
function M.get(name)
|
|
local code = M.mapping[name]
|
|
if code then
|
|
return vim.fn.nr2char(code)
|
|
end
|
|
end
|
|
|
|
function M.apply()
|
|
ensure_initialized()
|
|
if config.override then
|
|
require('nonicons.override').apply()
|
|
end
|
|
end
|
|
|
|
function M.get_icon(name, ext)
|
|
local key = require('nonicons.resolve').resolve_name(name, ext)
|
|
if key then
|
|
return M.get(key)
|
|
end
|
|
end
|
|
|
|
function M.get_icon_by_filetype(ft)
|
|
local key = require('nonicons.resolve').resolve_filetype(ft)
|
|
if key then
|
|
return M.get(key)
|
|
end
|
|
end
|
|
|
|
return M
|