fix(api): nvim_get_hl drops groups defined with link_global #38492

Problem: hlgroup2dict passes &ns_id to ns_get_hl twice. The first call
(link=true) sets *ns_hl = 0 when link_global is set, so the second call
and the sg_cleared guard both see ns_id == 0 and bail out. The group is
silently dropped from the result.

Solution: use a temporary copy of ns_id for each ns_get_hl call so the
original value is preserved.
This commit is contained in:
glepnir
2026-04-12 20:38:35 +08:00
committed by GitHub
parent 2f6c560002
commit 49086862fc
8 changed files with 57 additions and 35 deletions

View File

@@ -2225,29 +2225,29 @@ function vim.api.nvim_set_decoration_provider(ns_id, opts) end
--- `nvim_set_hl_ns()` or `nvim_win_set_hl_ns()` to activate them.
--- @param name string Highlight group name, e.g. "ErrorMsg"
--- @param val vim.api.keyset.highlight Highlight definition map, accepts the following keys:
--- - altfont: boolean
--- - bg: color name or "#RRGGBB", see note.
--- - bg_indexed: boolean (default false) If true, bg is a terminal palette index (0-255).
--- - blend: integer between 0 and 100
--- - blink: boolean
--- - bold: boolean
--- - conceal: boolean Concealment at the UI level (terminal SGR), unrelated to `:syn-conceal`.
--- - cterm: cterm attribute map, like `highlight-args`. If not set, cterm attributes
--- will match those from the attribute map documented above.
--- - ctermbg: Sets background of cterm color `ctermbg`
--- - ctermfg: Sets foreground of cterm color `ctermfg`
--- - default: boolean Don't override existing definition `:hi-default`
--- - dim: boolean
--- - fg: color name or "#RRGGBB", see note.
--- - fg_indexed: boolean (default false) If true, fg is a terminal palette index (0-255).
--- - force: if true force update the highlight group when it exists.
--- - link: Name of highlight group to link to. `:hi-link`
--- - sp: color name or "#RRGGBB"
--- - update: boolean (default false) Update specified attributes only, leave others unchanged.
--- - altfont: boolean
--- - blink: boolean
--- - bold: boolean
--- - conceal: boolean Concealment at the UI level (terminal SGR), unrelated to `:syn-conceal`.
--- - dim: boolean
--- - italic: boolean
--- - link: Name of highlight group to link to. `:hi-link`
--- - link_global: Like "link", but always resolved in the global (ns=0) namespace.
--- - nocombine: boolean
--- - overline: boolean
--- - reverse: boolean
--- - sp: color name or "#RRGGBB"
--- - standout: boolean
--- - strikethrough: boolean
--- - undercurl: boolean
@@ -2255,6 +2255,7 @@ function vim.api.nvim_set_decoration_provider(ns_id, opts) end
--- - underdotted: boolean
--- - underdouble: boolean
--- - underline: boolean
--- - update: boolean (default false) Update specified attributes only, leave others unchanged.
function vim.api.nvim_set_hl(ns_id, name, val) end
--- Set active namespace for highlights defined with `nvim_set_hl()`. This can be set for