mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(highlight): add create param in nvim_get_hl
This commit is contained in:
parent
82150ca51b
commit
8afb3a49c0
@ -966,6 +966,8 @@ nvim_get_hl({ns_id}, {*opts}) *nvim_get_hl()*
|
|||||||
• id: (integer) Get a highlight definition by id.
|
• id: (integer) Get a highlight definition by id.
|
||||||
• link: (boolean, default true) Show linked group name
|
• link: (boolean, default true) Show linked group name
|
||||||
instead of effective definition |:hi-link|.
|
instead of effective definition |:hi-link|.
|
||||||
|
• create: (boolean, default true) When highlight group
|
||||||
|
doesn't exist create it.
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
Highlight groups as a map from group name to a highlight definition
|
Highlight groups as a map from group name to a highlight definition
|
||||||
|
2
runtime/lua/vim/_meta/api.lua
generated
2
runtime/lua/vim/_meta/api.lua
generated
@ -1193,6 +1193,8 @@ function vim.api.nvim_get_current_win() end
|
|||||||
--- • id: (integer) Get a highlight definition by id.
|
--- • id: (integer) Get a highlight definition by id.
|
||||||
--- • link: (boolean, default true) Show linked group name
|
--- • link: (boolean, default true) Show linked group name
|
||||||
--- instead of effective definition `:hi-link`.
|
--- instead of effective definition `:hi-link`.
|
||||||
|
--- • create: (boolean, default true) When highlight group
|
||||||
|
--- doesn't exist create it.
|
||||||
--- @return table<string,any>
|
--- @return table<string,any>
|
||||||
function vim.api.nvim_get_hl(ns_id, opts) end
|
function vim.api.nvim_get_hl(ns_id, opts) end
|
||||||
|
|
||||||
|
1
runtime/lua/vim/_meta/api_keysets.lua
generated
1
runtime/lua/vim/_meta/api_keysets.lua
generated
@ -126,6 +126,7 @@ error('Cannot require a meta file')
|
|||||||
--- @field id? integer
|
--- @field id? integer
|
||||||
--- @field name? string
|
--- @field name? string
|
||||||
--- @field link? boolean
|
--- @field link? boolean
|
||||||
|
--- @field create? boolean
|
||||||
|
|
||||||
--- @class vim.api.keyset.highlight
|
--- @class vim.api.keyset.highlight
|
||||||
--- @field bold? boolean
|
--- @field bold? boolean
|
||||||
|
@ -181,6 +181,7 @@ typedef struct {
|
|||||||
Integer id;
|
Integer id;
|
||||||
String name;
|
String name;
|
||||||
Boolean link;
|
Boolean link;
|
||||||
|
Boolean create;
|
||||||
} Dict(get_highlight);
|
} Dict(get_highlight);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -96,6 +96,7 @@ Integer nvim_get_hl_id_by_name(String name)
|
|||||||
/// - name: (string) Get a highlight definition by name.
|
/// - name: (string) Get a highlight definition by name.
|
||||||
/// - id: (integer) Get a highlight definition by id.
|
/// - id: (integer) Get a highlight definition by id.
|
||||||
/// - link: (boolean, default true) Show linked group name instead of effective definition |:hi-link|.
|
/// - link: (boolean, default true) Show linked group name instead of effective definition |:hi-link|.
|
||||||
|
/// - create: (boolean, default true) When highlight group doesn't exist create it.
|
||||||
///
|
///
|
||||||
/// @param[out] err Error details, if any.
|
/// @param[out] err Error details, if any.
|
||||||
/// @return Highlight groups as a map from group name to a highlight definition map as in |nvim_set_hl()|,
|
/// @return Highlight groups as a map from group name to a highlight definition map as in |nvim_set_hl()|,
|
||||||
|
@ -1569,7 +1569,13 @@ Dictionary ns_get_hl_defs(NS ns_id, Dict(get_highlight) *opts, Arena *arena, Err
|
|||||||
Boolean link = GET_BOOL_OR_TRUE(opts, get_highlight, link);
|
Boolean link = GET_BOOL_OR_TRUE(opts, get_highlight, link);
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if (HAS_KEY(opts, get_highlight, name)) {
|
if (HAS_KEY(opts, get_highlight, name)) {
|
||||||
id = syn_check_group(opts->name.data, opts->name.size);
|
Boolean create = GET_BOOL_OR_TRUE(opts, get_highlight, create);
|
||||||
|
id = create ? syn_check_group(opts->name.data, opts->name.size)
|
||||||
|
: syn_name2id_len(opts->name.data, opts->name.size);
|
||||||
|
if (id == 0 && !create) {
|
||||||
|
Dictionary attrs = ARRAY_DICT_INIT;
|
||||||
|
return attrs;
|
||||||
|
}
|
||||||
} else if (HAS_KEY(opts, get_highlight, id)) {
|
} else if (HAS_KEY(opts, get_highlight, id)) {
|
||||||
id = (int)opts->id;
|
id = (int)opts->id;
|
||||||
}
|
}
|
||||||
|
@ -439,6 +439,15 @@ describe('API: get highlight', function()
|
|||||||
eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' }))
|
eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' }))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('nvim_get_hl with create flag', function()
|
||||||
|
eq({}, nvim("get_hl", 0, {name = 'Foo', create = false}))
|
||||||
|
eq(0, funcs.hlexists('Foo'))
|
||||||
|
meths.get_hl(0, {name = 'Bar', create = true})
|
||||||
|
eq(1, funcs.hlexists('Bar'))
|
||||||
|
meths.get_hl(0, {name = 'FooBar'})
|
||||||
|
eq(1, funcs.hlexists('FooBar'))
|
||||||
|
end)
|
||||||
|
|
||||||
it('can get all highlights in current namespace', function()
|
it('can get all highlights in current namespace', function()
|
||||||
local ns = get_ns()
|
local ns = get_ns()
|
||||||
meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' })
|
meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' })
|
||||||
|
Loading…
Reference in New Issue
Block a user