mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(api): use hl id directly in nvim_buf_set_extmark
This commit is contained in:
parent
ba9f86a9ce
commit
646fdf1073
10
runtime/lua/vim/_meta/api_keysets.lua
generated
10
runtime/lua/vim/_meta/api_keysets.lua
generated
@ -246,7 +246,7 @@ error('Cannot require a meta file')
|
|||||||
--- @field end_line? integer
|
--- @field end_line? integer
|
||||||
--- @field end_row? integer
|
--- @field end_row? integer
|
||||||
--- @field end_col? integer
|
--- @field end_col? integer
|
||||||
--- @field hl_group? any
|
--- @field hl_group? integer
|
||||||
--- @field virt_text? any[]
|
--- @field virt_text? any[]
|
||||||
--- @field virt_text_pos? string
|
--- @field virt_text_pos? string
|
||||||
--- @field virt_text_win_col? integer
|
--- @field virt_text_win_col? integer
|
||||||
@ -264,10 +264,10 @@ error('Cannot require a meta file')
|
|||||||
--- @field virt_lines_leftcol? boolean
|
--- @field virt_lines_leftcol? boolean
|
||||||
--- @field strict? boolean
|
--- @field strict? boolean
|
||||||
--- @field sign_text? string
|
--- @field sign_text? string
|
||||||
--- @field sign_hl_group? any
|
--- @field sign_hl_group? integer
|
||||||
--- @field number_hl_group? any
|
--- @field number_hl_group? integer
|
||||||
--- @field line_hl_group? any
|
--- @field line_hl_group? integer
|
||||||
--- @field cursorline_hl_group? any
|
--- @field cursorline_hl_group? integer
|
||||||
--- @field conceal? string
|
--- @field conceal? string
|
||||||
--- @field spell? boolean
|
--- @field spell? boolean
|
||||||
--- @field ui_watched? boolean
|
--- @field ui_watched? boolean
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "nvim/buffer_defs.h"
|
#include "nvim/buffer_defs.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
#include "nvim/decoration.h"
|
#include "nvim/decoration.h"
|
||||||
|
#include "nvim/decoration_defs.h"
|
||||||
#include "nvim/decoration_provider.h"
|
#include "nvim/decoration_provider.h"
|
||||||
#include "nvim/drawscreen.h"
|
#include "nvim/drawscreen.h"
|
||||||
#include "nvim/extmark.h"
|
#include "nvim/extmark.h"
|
||||||
@ -540,36 +541,15 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
|||||||
col2 = (int)val;
|
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)
|
if (sign.hl_id || sign.cursorline_hl_id || sign.number_hl_id || sign.line_hl_id) {
|
||||||
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;
|
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 (HAS_KEY(opts, set_extmark, conceal)) {
|
if (HAS_KEY(opts, set_extmark, conceal)) {
|
||||||
|
@ -28,7 +28,7 @@ typedef struct {
|
|||||||
Integer end_line;
|
Integer end_line;
|
||||||
Integer end_row;
|
Integer end_row;
|
||||||
Integer end_col;
|
Integer end_col;
|
||||||
Object hl_group;
|
Integer hl_group;
|
||||||
Array virt_text;
|
Array virt_text;
|
||||||
String virt_text_pos;
|
String virt_text_pos;
|
||||||
Integer virt_text_win_col;
|
Integer virt_text_win_col;
|
||||||
@ -46,10 +46,10 @@ typedef struct {
|
|||||||
Boolean virt_lines_leftcol;
|
Boolean virt_lines_leftcol;
|
||||||
Boolean strict;
|
Boolean strict;
|
||||||
String sign_text;
|
String sign_text;
|
||||||
Object sign_hl_group;
|
Integer sign_hl_group;
|
||||||
Object number_hl_group;
|
Integer number_hl_group;
|
||||||
Object line_hl_group;
|
Integer line_hl_group;
|
||||||
Object cursorline_hl_group;
|
Integer cursorline_hl_group;
|
||||||
String conceal;
|
String conceal;
|
||||||
Boolean spell;
|
Boolean spell;
|
||||||
Boolean ui_watched;
|
Boolean ui_watched;
|
||||||
|
@ -135,6 +135,7 @@ typedef struct {
|
|||||||
size_t ptr_off;
|
size_t ptr_off;
|
||||||
ObjectType type; // kObjectTypeNil == untyped
|
ObjectType type; // kObjectTypeNil == untyped
|
||||||
int opt_index;
|
int opt_index;
|
||||||
|
bool is_hlgroup;
|
||||||
} KeySetLink;
|
} KeySetLink;
|
||||||
|
|
||||||
typedef KeySetLink *(*FieldHashfn)(const char *str, size_t len);
|
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);
|
char *mem = ((char *)retval + field->ptr_off);
|
||||||
Object *value = &dict.items[i].value;
|
Object *value = &dict.items[i].value;
|
||||||
|
|
||||||
if (field->type == kObjectTypeNil) {
|
if (field->type == kObjectTypeNil) {
|
||||||
*(Object *)mem = *value;
|
*(Object *)mem = *value;
|
||||||
} else if (field->type == kObjectTypeInteger) {
|
} else if (field->type == kObjectTypeInteger) {
|
||||||
|
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, {
|
VALIDATE_T(field->str, kObjectTypeInteger, value->type, {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
*(Integer *)mem = value->data.integer;
|
*(Integer *)mem = value->data.integer;
|
||||||
|
}
|
||||||
} else if (field->type == kObjectTypeFloat) {
|
} else if (field->type == kObjectTypeFloat) {
|
||||||
Float *val = (Float *)mem;
|
Float *val = (Float *)mem;
|
||||||
if (value->type == kObjectTypeInteger) {
|
if (value->type == kObjectTypeInteger) {
|
||||||
|
@ -72,6 +72,7 @@ local keysets = {}
|
|||||||
local function add_keyset(val)
|
local function add_keyset(val)
|
||||||
local keys = {}
|
local keys = {}
|
||||||
local types = {}
|
local types = {}
|
||||||
|
local hlgroups = {}
|
||||||
local is_set_name = 'is_set__' .. val.keyset_name .. '_'
|
local is_set_name = 'is_set__' .. val.keyset_name .. '_'
|
||||||
local has_optional = false
|
local has_optional = false
|
||||||
for i, field in ipairs(val.fields) do
|
for i, field in ipairs(val.fields) do
|
||||||
@ -80,6 +81,7 @@ local function add_keyset(val)
|
|||||||
end
|
end
|
||||||
if field.name ~= is_set_name and field.type ~= 'OptionalKeys' then
|
if field.name ~= is_set_name and field.type ~= 'OptionalKeys' then
|
||||||
table.insert(keys, field.name)
|
table.insert(keys, field.name)
|
||||||
|
hlgroups[field.name] = field.name:find('hl_group') and true or false
|
||||||
else
|
else
|
||||||
if i > 1 then
|
if i > 1 then
|
||||||
error("'is_set__{type}_' must be first if present")
|
error("'is_set__{type}_' must be first if present")
|
||||||
@ -91,10 +93,13 @@ local function add_keyset(val)
|
|||||||
has_optional = true
|
has_optional = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(
|
table.insert(keysets, {
|
||||||
keysets,
|
name = val.keyset_name,
|
||||||
{ name = val.keyset_name, keys = keys, types = types, has_optional = has_optional }
|
keys = keys,
|
||||||
)
|
types = types,
|
||||||
|
hlgroups = hlgroups,
|
||||||
|
has_optional = has_optional,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- read each input file, parse and append to the api metadata
|
-- read each input file, parse and append to the api metadata
|
||||||
@ -305,10 +310,12 @@ for _, k in ipairs(keysets) do
|
|||||||
.. typename(k.types[key])
|
.. typename(k.types[key])
|
||||||
.. ', '
|
.. ', '
|
||||||
.. ind
|
.. ind
|
||||||
|
.. ', '
|
||||||
|
.. (k.hlgroups[key] and 'true' or 'false')
|
||||||
.. '},\n'
|
.. '},\n'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
output:write(' {NULL, 0, kObjectTypeNil, -1},\n')
|
output:write(' {NULL, 0, kObjectTypeNil, -1, false},\n')
|
||||||
output:write('};\n\n')
|
output:write('};\n\n')
|
||||||
|
|
||||||
output:write(hashfun)
|
output:write(hashfun)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "nvim/eval/typval_encode.h"
|
#include "nvim/eval/typval_encode.h"
|
||||||
#include "nvim/eval/userfunc.h"
|
#include "nvim/eval/userfunc.h"
|
||||||
#include "nvim/gettext_defs.h"
|
#include "nvim/gettext_defs.h"
|
||||||
|
#include "nvim/highlight_group.h"
|
||||||
#include "nvim/lua/converter.h"
|
#include "nvim/lua/converter.h"
|
||||||
#include "nvim/lua/executor.h"
|
#include "nvim/lua/executor.h"
|
||||||
#include "nvim/macros_defs.h"
|
#include "nvim/macros_defs.h"
|
||||||
@ -1324,7 +1325,14 @@ void nlua_pop_keydict(lua_State *L, void *retval, FieldHashfn hashy, char **err_
|
|||||||
if (field->type == kObjectTypeNil) {
|
if (field->type == kObjectTypeNil) {
|
||||||
*(Object *)mem = nlua_pop_Object(L, true, err);
|
*(Object *)mem = nlua_pop_Object(L, true, err);
|
||||||
} else if (field->type == kObjectTypeInteger) {
|
} else if (field->type == kObjectTypeInteger) {
|
||||||
|
if (field->is_hlgroup && lua_type(L, -1) == LUA_TSTRING) {
|
||||||
|
size_t name_len;
|
||||||
|
const char *name = lua_tolstring(L, -1, &name_len);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
*(Integer *)mem = name_len > 0 ? syn_check_group(name, name_len) : 0;
|
||||||
|
} else {
|
||||||
*(Integer *)mem = nlua_pop_Integer(L, err);
|
*(Integer *)mem = nlua_pop_Integer(L, err);
|
||||||
|
}
|
||||||
} else if (field->type == kObjectTypeBoolean) {
|
} else if (field->type == kObjectTypeBoolean) {
|
||||||
*(Boolean *)mem = nlua_pop_Boolean_strict(L, err);
|
*(Boolean *)mem = nlua_pop_Boolean_strict(L, err);
|
||||||
} else if (field->type == kObjectTypeString) {
|
} else if (field->type == kObjectTypeString) {
|
||||||
|
Loading…
Reference in New Issue
Block a user