mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
Merge pull request #27076 from glepnir/extmark_hlgroup
refactor(api): use hl id directly in nvim_buf_set_extmark
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "nvim/buffer_defs.h"
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/decoration.h"
|
||||
#include "nvim/decoration_defs.h"
|
||||
#include "nvim/decoration_provider.h"
|
||||
#include "nvim/drawscreen.h"
|
||||
#include "nvim/extmark.h"
|
||||
@@ -546,36 +547,15 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
col2 = (int)val;
|
||||
}
|
||||
|
||||
// uncrustify:off
|
||||
hl.hl_id = (int)opts->hl_group;
|
||||
has_hl = hl.hl_id > 0;
|
||||
sign.hl_id = (int)opts->sign_hl_group;
|
||||
sign.cursorline_hl_id = (int)opts->cursorline_hl_group;
|
||||
sign.number_hl_id = (int)opts->number_hl_group;
|
||||
sign.line_hl_id = (int)opts->line_hl_group;
|
||||
|
||||
// TODO(bfredl): keyset type alias for hl_group? (nil|int|string)
|
||||
struct {
|
||||
const char *name;
|
||||
Object *opt;
|
||||
int *dest;
|
||||
} hls[] = {
|
||||
{ "hl_group" , &opts->hl_group , &hl.hl_id },
|
||||
{ "sign_hl_group" , &opts->sign_hl_group , &sign.hl_id },
|
||||
{ "number_hl_group" , &opts->number_hl_group , &sign.number_hl_id },
|
||||
{ "line_hl_group" , &opts->line_hl_group , &sign.line_hl_id },
|
||||
{ "cursorline_hl_group", &opts->cursorline_hl_group, &sign.cursorline_hl_id },
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
// uncrustify:on
|
||||
|
||||
for (int j = 0; hls[j].name && hls[j].dest; j++) {
|
||||
if (hls[j].opt->type != kObjectTypeNil) {
|
||||
if (j > 0) {
|
||||
sign.flags |= kSHIsSign;
|
||||
} else {
|
||||
has_hl = true;
|
||||
}
|
||||
*hls[j].dest = object_to_hl_id(*hls[j].opt, hls[j].name, err);
|
||||
if (ERROR_SET(err)) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (sign.hl_id || sign.cursorline_hl_id || sign.number_hl_id || sign.line_hl_id) {
|
||||
sign.flags |= kSHIsSign;
|
||||
}
|
||||
|
||||
if (HAS_KEY(opts, set_extmark, conceal)) {
|
||||
|
@@ -28,7 +28,7 @@ typedef struct {
|
||||
Integer end_line;
|
||||
Integer end_row;
|
||||
Integer end_col;
|
||||
Object hl_group;
|
||||
HLGroupID hl_group;
|
||||
Array virt_text;
|
||||
String virt_text_pos;
|
||||
Integer virt_text_win_col;
|
||||
@@ -46,10 +46,10 @@ typedef struct {
|
||||
Boolean virt_lines_leftcol;
|
||||
Boolean strict;
|
||||
String sign_text;
|
||||
Object sign_hl_group;
|
||||
Object number_hl_group;
|
||||
Object line_hl_group;
|
||||
Object cursorline_hl_group;
|
||||
HLGroupID sign_hl_group;
|
||||
HLGroupID number_hl_group;
|
||||
HLGroupID line_hl_group;
|
||||
HLGroupID cursorline_hl_group;
|
||||
String conceal;
|
||||
Boolean spell;
|
||||
Boolean ui_watched;
|
||||
|
@@ -124,6 +124,7 @@ struct key_value_pair {
|
||||
};
|
||||
|
||||
typedef uint64_t OptionalKeys;
|
||||
typedef Integer HLGroupID;
|
||||
|
||||
// this is the prefix of all keysets with optional keys
|
||||
typedef struct {
|
||||
@@ -135,6 +136,7 @@ typedef struct {
|
||||
size_t ptr_off;
|
||||
ObjectType type; // kObjectTypeNil == untyped
|
||||
int opt_index;
|
||||
bool is_hlgroup;
|
||||
} KeySetLink;
|
||||
|
||||
typedef KeySetLink *(*FieldHashfn)(const char *str, size_t len);
|
||||
|
@@ -936,13 +936,26 @@ bool api_dict_to_keydict(void *retval, FieldHashfn hashy, Dictionary dict, Error
|
||||
|
||||
char *mem = ((char *)retval + field->ptr_off);
|
||||
Object *value = &dict.items[i].value;
|
||||
|
||||
if (field->type == kObjectTypeNil) {
|
||||
*(Object *)mem = *value;
|
||||
} else if (field->type == kObjectTypeInteger) {
|
||||
VALIDATE_T(field->str, kObjectTypeInteger, value->type, {
|
||||
return false;
|
||||
});
|
||||
*(Integer *)mem = value->data.integer;
|
||||
if (field->is_hlgroup) {
|
||||
int hl_id = 0;
|
||||
if (value->type != kObjectTypeNil) {
|
||||
hl_id = object_to_hl_id(*value, k.data, err);
|
||||
if (ERROR_SET(err)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*(Integer *)mem = hl_id;
|
||||
} else {
|
||||
VALIDATE_T(field->str, kObjectTypeInteger, value->type, {
|
||||
return false;
|
||||
});
|
||||
|
||||
*(Integer *)mem = value->data.integer;
|
||||
}
|
||||
} else if (field->type == kObjectTypeFloat) {
|
||||
Float *val = (Float *)mem;
|
||||
if (value->type == kObjectTypeInteger) {
|
||||
|
Reference in New Issue
Block a user