Skip to content

fix(icons): add guard against a stale cwd#2458

Merged
echasnovski merged 2 commits into
nvim-mini:backlogfrom
abeldekat:fix_icons
Jun 11, 2026
Merged

fix(icons): add guard against a stale cwd#2458
echasnovski merged 2 commits into
nvim-mini:backlogfrom
abeldekat:fix_icons

Conversation

@abeldekat

Copy link
Copy Markdown
Member

Resolve #2455

Other approaches I considered:

  1. Add the pcall to H.filetype_match(). Reasoning: mini.icons should never fail...
  2. Skip the call with aaa.<the_extension>, only test for ~/aaa.<the_extension>. Reasoning: vim.filetype.match will create an absolute path anyway...

@echasnovski

Copy link
Copy Markdown
Member
  1. Add the pcall to H.filetype_match(). Reasoning: mini.icons should never fail...

This is what I'd expect, since H.filetype_match is used in other place. What made you not go this route?

2. Skip the call with aaa.<the_extension>, only test for ~/aaa.<the_extension>. Reasoning: vim.filetype.match will create an absolute path anyway...

I did think about this, but 1) the current aaa.ext works most of the time; 2) I am not confident that resolving ~/file is faster that resolving file (i.e. resolving ~ is faster than resolving current working directory).

@abeldekat

Copy link
Copy Markdown
Member Author

This is what I'd expect, since H.filetype_match is used in other place. What made you not go this route?

Our conversation yesterday, which in hindsight, I did not understand completely...).
I pushed a new commit.

Comment thread lua/mini/icons.lua Outdated
Comment on lines +2163 to +2167
local ok, ft = pcall(H.filetype_match, ('aaa.' .. name))
if not ok then
ok, ft = pcall(H.filetype_match, ('~/aaa.' .. name))
end
if ok and ft ~= nil then return MiniIcons.get('filetype', ft) end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this all to be done in H.filetype_match with early return for the "happy" path. Less lines and covers more cases.

There doesn't seem to be a reason for why filetype matching for extension and file cases should differ.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread tests/test_icons.lua Outdated
Comment thread tests/test_icons.lua Outdated
@echasnovski echasnovski changed the base branch from main to backlog June 11, 2026 12:29
@echasnovski echasnovski merged commit 08d8ee1 into nvim-mini:backlog Jun 11, 2026
12 checks passed
@echasnovski

Copy link
Copy Markdown
Member

Thanks for the PR! I've made some stylistic tweaks to make code more concise, have more direct "happy path", and with extra explanatory comment about why this is needed.

@abeldekat abeldekat deleted the fix_icons branch June 11, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in mini.icons when using mini.tabline and cwd does not exist

2 participants