feat: add public file-icon API (#10)

* 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.
This commit is contained in:
Barrett Ruth 2026-02-22 21:35:45 -05:00 committed by GitHub
parent 5426ec037f
commit d07145eeae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 527 additions and 445 deletions

View file

@ -53,6 +53,33 @@ API *nonicons-api*
Parameters: ~
{name} `string` Icon name (e.g. `'lua'`, `'python'`, `'git-branch'`)
Returns: ~
`string?` The single-character nonicons glyph
*nonicons.get_icon()*
`require('nonicons').get_icon(name, ext)`
Returns the nonicons character for a file, resolved by filename and/or
extension. Returns `nil` if no match is found (caller decides fallback).
Resolution order: exact extension → exact filename → extracted extension.
Parameters: ~
{name} `string?` Filename (e.g. `'init.lua'`, `'Makefile'`)
{ext} `string?` File extension (e.g. `'lua'`, `'py'`)
Returns: ~
`string?` The single-character nonicons glyph
*nonicons.get_icon_by_filetype()*
`require('nonicons').get_icon_by_filetype(ft)`
Returns the nonicons character for a vim filetype. Returns `nil` if no
match is found.
Resolution order: direct mapping key → extension table → filetype table.
Parameters: ~
{ft} `string` Vim filetype (e.g. `'python'`, `'typescriptreact'`)
Returns: ~
`string?` The single-character nonicons glyph
@ -128,8 +155,9 @@ mason.nvim ~
oil.nvim ~
No configuration needed. oil.nvim reads the devicons extension/filename
tables directly, which nonicons.nvim mutates on load.
No configuration needed. oil.nvim detects nonicons.nvim and uses it as a
direct icon provider. If devicons is also loaded, the devicons override
still applies to other plugins.
fzf-lua ~
>lua