Merge pull request #25039 from glepnir/fix_hl

fix(highlight): add create param in nvim_get_hl api function
This commit is contained in:
bfredl
2023-09-09 13:01:40 +02:00
committed by GitHub
7 changed files with 23 additions and 1 deletions

View File

@@ -181,6 +181,7 @@ typedef struct {
Integer id;
String name;
Boolean link;
Boolean create;
} Dict(get_highlight);
typedef struct {

View File

@@ -96,6 +96,7 @@ Integer nvim_get_hl_id_by_name(String name)
/// - name: (string) Get a highlight definition by name.
/// - id: (integer) Get a highlight definition by id.
/// - 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.
/// @return Highlight groups as a map from group name to a highlight definition map as in |nvim_set_hl()|,

View File

@@ -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);
int id = -1;
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)) {
id = (int)opts->id;
}