fix(api): set script context when using nvim_set_hl (#28123)

This commit is contained in:
zeertzjq
2024-03-31 20:21:47 +08:00
committed by GitHub
parent e1ff2c51ca
commit b25753381c
3 changed files with 67 additions and 12 deletions

View File

@@ -167,7 +167,7 @@ Dictionary nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena *arena, E
/// @param[out] err Error details, if any
///
// TODO(bfredl): val should take update vs reset flag
void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err)
void nvim_set_hl(uint64_t channel_id, Integer ns_id, String name, Dict(highlight) *val, Error *err)
FUNC_API_SINCE(7)
{
int hl_id = syn_check_group(name.data, name.size);
@@ -184,7 +184,9 @@ void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err)
HlAttrs attrs = dict2hlattrs(val, true, &link_id, err);
if (!ERROR_SET(err)) {
ns_hl_def((NS)ns_id, hl_id, attrs, link_id, val);
WITH_SCRIPT_CONTEXT(channel_id, {
ns_hl_def((NS)ns_id, hl_id, attrs, link_id, val);
});
}
}

View File

@@ -889,11 +889,13 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
g->sg_link = link_id;
g->sg_script_ctx = current_sctx;
g->sg_script_ctx.sc_lnum += SOURCING_LNUM;
nlua_set_sctx(&g->sg_script_ctx);
g->sg_set |= SG_LINK;
if (is_default) {
g->sg_deflink = link_id;
g->sg_deflink_sctx = current_sctx;
g->sg_deflink_sctx.sc_lnum += SOURCING_LNUM;
nlua_set_sctx(&g->sg_deflink_sctx);
}
} else {
g->sg_link = 0;
@@ -934,6 +936,7 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
g->sg_script_ctx = current_sctx;
g->sg_script_ctx.sc_lnum += SOURCING_LNUM;
nlua_set_sctx(&g->sg_script_ctx);
g->sg_attr = hl_get_syn_attr(0, id, attrs);