Skip to content

fix(diff): normalize string highlight values before nvim_set_hl#91

Open
petrosAth wants to merge 2 commits into
Cannon07:mainfrom
petrosAth:fix/highlight-link-default-flag
Open

fix(diff): normalize string highlight values before nvim_set_hl#91
petrosAth wants to merge 2 commits into
Cannon07:mainfrom
petrosAth:fix/highlight-link-default-flag

Conversation

@petrosAth

Copy link
Copy Markdown

📋 Summary

Configuring highlights.inline.* (or current/proposed) as a highlight-group-name string, e.g. added = "GitSignsAddLn", crashed the inline diff with Expected Lua tablenvim_set_hl requires a table, and diff.lua passed the raw config value straight through. neo_tree.lua already normalized strings via define_hl; this port extracts that logic into a shared hl.lua module and fixes a second bug found along the way: default = true is sticky for the process lifetime, so re-applying a changed string link was silently ignored.

🔧 Changes

  • hl.lua (new): resolve() turns a string into { link = ... } (no default = true, which caused the stickiness) or passes a table through.
  • diff.lua, neo_tree.lua: route apply_highlights, apply_inline_highlights, and define_hl through hl.resolve.

🧪 Testing

  • tests/plugin/diff_lifecycle_spec.lua: string-link highlights for inline and tab/vsplit layouts, plus a regression test for re-linking to a changed target.

petrosAth added 2 commits July 3, 2026 00:29
highlights.current/proposed/inline accepted a highlight-group-name string
(e.g. `added = "GitSignsAddLn"`), but apply_highlights and
apply_inline_highlights passed it straight into nvim_set_hl, whose third
argument must be a table — throwing "Expected Lua table" and aborting the
render. Add resolve_hl() to wrap a bare string as { link = str, default =
true } before every nvim_set_hl call.
…icky

resolve_hl/define_hl passed `default = true` when a highlights config
value was a bare group-name string. nvim_set_hl's default flag is sticky
for the life of the process: once a group has any definition, a later
default=true call is silently ignored, even to change the link target.
Since apply_highlights/apply_inline_highlights run on every show_diff(),
re-sourcing config with a changed string-linked highlight never took
effect until Neovim was restarted.

Also extracts the string-or-table resolution (previously duplicated
between diff.lua's resolve_hl and neo_tree.lua's define_hl) into a
shared lua/code-preview/hl.lua module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant