fix(diff): normalize string highlight values before nvim_set_hl#91
Open
petrosAth wants to merge 2 commits into
Open
fix(diff): normalize string highlight values before nvim_set_hl#91petrosAth wants to merge 2 commits into
petrosAth wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
Configuring
highlights.inline.*(orcurrent/proposed) as a highlight-group-name string, e.g.added = "GitSignsAddLn", crashed the inline diff withExpected Lua table—nvim_set_hlrequires a table, anddiff.luapassed the raw config value straight through.neo_tree.luaalready normalized strings viadefine_hl; this port extracts that logic into a sharedhl.luamodule and fixes a second bug found along the way:default = trueis sticky for the process lifetime, so re-applying a changed string link was silently ignored.🔧 Changes
resolve()turns a string into{ link = ... }(nodefault = true, which caused the stickiness) or passes a table through.apply_highlights,apply_inline_highlights, anddefine_hlthroughhl.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.