diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-04-13 14:08:36 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-04-13 14:17:12 +0200 |
commit | d05d63a18ff8394b31b3f3b85bfaebe2af358437 (patch) | |
tree | 61357eabcd06f1055eef4b3883e2acfdcb60628b | |
parent | 231e1988ed788caa6b15817c63e94f38cd8ac75c (diff) | |
download | rneovim-d05d63a18ff8394b31b3f3b85bfaebe2af358437.tar.gz rneovim-d05d63a18ff8394b31b3f3b85bfaebe2af358437.tar.bz2 rneovim-d05d63a18ff8394b31b3f3b85bfaebe2af358437.zip |
fix(api): make nvim_get_hl not return non-existing groups
fixes #23063
-rw-r--r-- | src/nvim/highlight_group.c | 4 | ||||
-rw-r--r-- | test/functional/api/highlight_spec.lua | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 6493408a58..3ab8a3bb88 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1530,6 +1530,10 @@ static bool hlgroup2dict(Dictionary *hl, NS ns_id, int hl_id, Arena *arena) if (link == -1) { return false; } + if (ns_id == 0 && sgp->sg_cleared && sgp->sg_set == 0) { + // table entry was created but not ever set + return false; + } HlAttrs attr = syn_attr2entry(ns_id == 0 ? sgp->sg_attr : ns_get_hl(&ns_id, hl_id, false, sgp->sg_set)); *hl = arena_dict(arena, HLATTRS_DICT_SIZE + 1); diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a4bd574a56..a6e9f9a42b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -575,4 +575,25 @@ describe('API: get highlight', function() meths.set_hl(0, 'Foo', hl) eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) end) + + it("doesn't contain unset groups", function() + local id = meths.get_hl_id_by_name "@foobar.hubbabubba" + ok(id > 0) + + local data = meths.get_hl(0, {}) + eq(nil, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + command 'hi @foobar.hubbabubba gui=bold' + data = meths.get_hl(0, {}) + eq({bold = true}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + -- @foobar.hubbabubba was explicitly cleared and thus shows up + -- but @foobar was never touched, and thus doesn't + command 'hi clear @foobar.hubbabubba' + data = meths.get_hl(0, {}) + eq({}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + end) end) |