diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/autocmd.c | 2 | ||||
-rw-r--r-- | src/nvim/api/command.c | 4 | ||||
-rw-r--r-- | src/nvim/api/keysets_defs.h | 109 | ||||
-rw-r--r-- | src/nvim/api/private/defs.h | 2 | ||||
-rw-r--r-- | src/nvim/generators/c_grammar.lua | 36 | ||||
-rw-r--r-- | src/nvim/generators/gen_api_dispatch.lua | 10 | ||||
-rw-r--r-- | src/nvim/highlight.c | 4 |
7 files changed, 112 insertions, 55 deletions
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index 22932fd1a2..db87500d08 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -631,7 +631,7 @@ Integer nvim_create_augroup(uint64_t channel_id, String name, Dict(create_augrou FUNC_API_SINCE(9) { char *augroup_name = name.data; - bool clear_autocmds = api_object_to_bool(opts->clear, "clear", true, err); + bool clear_autocmds = GET_BOOL_OR_TRUE(opts, create_augroup, clear); int augroup = -1; WITH_SCRIPT_CONTEXT(channel_id, { diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index ab57d5c009..709e18af73 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -226,8 +226,8 @@ Dict(cmd) nvim_parse_cmd(String str, Dict(empty) *opts, Arena *arena, Error *err addr = "?"; break; } - PUT_KEY(result, cmd, addr, CSTR_AS_OBJ(addr)); - PUT_KEY(result, cmd, nextcmd, CSTR_AS_OBJ(ea.nextcmd)); + PUT_KEY(result, cmd, addr, cstr_as_string(addr)); + PUT_KEY(result, cmd, nextcmd, cstr_as_string(ea.nextcmd)); // TODO(bfredl): nested keydict would be nice.. Dict mods = arena_dict(arena, 20); diff --git a/src/nvim/api/keysets_defs.h b/src/nvim/api/keysets_defs.h index 96aabb851f..48f5f7246c 100644 --- a/src/nvim/api/keysets_defs.h +++ b/src/nvim/api/keysets_defs.h @@ -8,18 +8,18 @@ typedef struct { typedef struct { OptionalKeys is_set__context_; - Array types; + ArrayOf(String) types; } Dict(context); typedef struct { OptionalKeys is_set__set_decoration_provider_; - LuaRef on_start; - LuaRef on_buf; - LuaRef on_win; - LuaRef on_line; - LuaRef on_end; - LuaRef _on_hl_def; - LuaRef _on_spell_nav; + LuaRefOf(("start" _, Integer tick)) on_start; + LuaRefOf(("buf" _, Integer bufnr, Integer tick)) on_buf; + LuaRefOf(("win" _, Integer winid, Integer bufnr, Integer toprow, Integer botrow)) on_win; + LuaRefOf(("line" _, Integer winid, Integer bufnr, Integer row)) on_line; + LuaRefOf(("end" _, Integer tick)) on_end; + LuaRefOf(("hl_def" _)) _on_hl_def; + LuaRefOf(("spell_nav" _)) _on_spell_nav; } Dict(set_decoration_provider); typedef struct { @@ -116,7 +116,7 @@ typedef struct { String relative; String split; Window win; - Array bufpos; + ArrayOf(Integer) bufpos; Boolean external; Boolean focusable; Boolean mouse; @@ -172,17 +172,17 @@ typedef struct { Boolean altfont; Boolean nocombine; Boolean default_ DictKey(default); - Object cterm; - Object foreground; - Object fg; - Object background; - Object bg; - Object ctermfg; - Object ctermbg; - Object special; - Object sp; - Object link; - Object global_link; + Union(Integer, String) cterm; + Union(Integer, String) foreground; + Union(Integer, String) fg; + Union(Integer, String) background; + Union(Integer, String) bg; + Union(Integer, String) ctermfg; + Union(Integer, String) ctermbg; + Union(Integer, String) special; + Union(Integer, String) sp; + HLGroupID link; + HLGroupID global_link; Boolean fallback; Integer blend; Boolean fg_indexed; @@ -230,9 +230,9 @@ typedef struct { typedef struct { OptionalKeys is_set__clear_autocmds_; Buffer buffer; - Object event; - Object group; - Object pattern; + Union(String, ArrayOf(String)) event; + Union(Integer, String) group; + Union(String, ArrayOf(String)) pattern; } Dict(clear_autocmds); typedef struct { @@ -241,31 +241,32 @@ typedef struct { Object callback; String command; String desc; - Object group; + Union(Integer, String) group; Boolean nested; Boolean once; - Object pattern; + Union(String, ArrayOf(String)) pattern; } Dict(create_autocmd); typedef struct { OptionalKeys is_set__exec_autocmds_; Buffer buffer; - Object group; + Union(Integer, String) group; Boolean modeline; - Object pattern; + Union(String, ArrayOf(String)) pattern; Object data; } Dict(exec_autocmds); typedef struct { OptionalKeys is_set__get_autocmds_; - Object event; - Object group; - Object pattern; - Object buffer; + Union(String, ArrayOf(String)) event; + Union(Integer, String) group; + Union(String, ArrayOf(String)) pattern; + Union(Integer, ArrayOf(Integer)) buffer; } Dict(get_autocmds); typedef struct { - Object clear; + OptionalKeys is_set__create_augroup_; + Boolean clear; } Dict(create_augroup); typedef struct { @@ -275,12 +276,12 @@ typedef struct { Integer count; String reg; Boolean bang; - Array args; + ArrayOf(String) args; Dict magic; Dict mods; - Object nargs; - Object addr; - Object nextcmd; + Union(Integer, String) nargs; + String addr; + String nextcmd; } Dict(cmd); typedef struct { @@ -333,11 +334,30 @@ typedef struct { typedef struct { OptionalKeys is_set__buf_attach_; - LuaRef on_lines; - LuaRef on_bytes; - LuaRef on_changedtick; - LuaRef on_detach; - LuaRef on_reload; + LuaRefOf(("lines" _, + Integer bufnr, + Integer changedtick, + Integer first, + Integer last_old, + Integer last_new, + Integer byte_count, + Integer *deleted_codepoints, + Integer *deleted_codeunits), *Boolean) on_lines; + LuaRefOf(("bytes" _, + Integer bufnr, + Integer changedtick, + Integer start_row, + Integer start_col, + Integer start_byte, + Integer old_end_row, + Integer old_end_col, + Integer old_end_byte, + Integer new_end_row, + Integer new_end_col, + Integer new_end_byte), *Boolean) on_bytes; + LuaRefOf(("changedtick" _, Integer bufnr, Integer changedtick)) on_changedtick; + LuaRefOf(("detach" _, Integer bufnr)) on_detach; + LuaRefOf(("reload" _, Integer bufnr)) on_reload; Boolean utf_sizes; Boolean preview; } Dict(buf_attach); @@ -350,7 +370,7 @@ typedef struct { typedef struct { OptionalKeys is_set__open_term_; - LuaRef on_input; + LuaRefOf(("input" _, Integer term, Integer bufnr, any data)) on_input; Boolean force_crlf; } Dict(open_term); @@ -361,12 +381,13 @@ typedef struct { typedef struct { OptionalKeys is_set__xdl_diff_; - LuaRef on_hunk; + LuaRefOf((Integer start_a, Integer count_a, Integer start_b, Integer count_b), + *Integer) on_hunk; String result_type; String algorithm; Integer ctxlen; Integer interhunkctxlen; - Object linematch; + Union(Boolean, Integer) linematch; Boolean ignore_whitespace; Boolean ignore_whitespace_change; Boolean ignore_whitespace_change_at_eol; diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 26d5ac09a8..6dee86dcf5 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -21,6 +21,8 @@ # define Dict(name) KeyDict_##name # define DictHash(name) KeyDict_##name##_get_field # define DictKey(name) +# define LuaRefOf(...) LuaRef +# define Union(...) Object # include "api/private/defs.h.inline.generated.h" #endif diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua index ed6e30ea10..a0a9c86789 100644 --- a/src/nvim/generators/c_grammar.lua +++ b/src/nvim/generators/c_grammar.lua @@ -3,7 +3,7 @@ local lpeg = vim.lpeg -- lpeg grammar for building api metadata from a set of header files. It -- ignores comments and preprocessor commands and parses a very small subset -- of C prototypes with a limited set of types -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V local C, Ct, Cc, Cg = lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cg --- @param pat vim.lpeg.Pattern @@ -35,9 +35,39 @@ local cdoc_comment = P('///') * opt(Ct(Cg(rep(space) * rep(not_nl), 'comment'))) local c_preproc = P('#') * rep(not_nl) local dllexport = P('DLLEXPORT') * rep1(ws) -local typed_container = ((P('ArrayOf(') + P('DictOf(') + P('Dict(')) * rep1(any - P(')')) * P(')')) +--- @param x vim.lpeg.Pattern +local function comma1(x) + return x * rep(fill * P(',') * fill * x) +end + +-- Define the grammar + +local basic_id = letter * rep(alpha) + +local str = P('"') * rep(any - P('"')) * P('"') + +--- @param x vim.lpeg.Pattern +local function paren(x) + return P('(') * fill * x * fill * P(')') +end + +-- stylua: ignore start +local typed_container = P({ + 'S', + ID = V('S') + basic_id, + S = ( + (P('Union') * paren(comma1(V('ID')))) + + (P('ArrayOf') * paren(basic_id * opt(P(',') * fill * rep1(num)))) + + (P('DictOf') * paren(basic_id)) + + (P('LuaRefOf') * paren( + paren(comma1((V('ID') + str) * rep1(ws) * opt(P('*')) * basic_id)) + * opt(P(',') * fill * opt(P('*')) * V('ID')) + )) + + (P('Dict') * paren(basic_id))), +}) +-- stylua: ignore end -local c_id = (typed_container + (letter * rep(alpha))) +local c_id = typed_container + basic_id local c_void = P('void') local c_param_type = ( diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index a78f746fee..402382acd2 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -347,12 +347,16 @@ for _, k in ipairs(keysets) do local function typename(type) if type == 'HLGroupID' then return 'kObjectTypeInteger' + elseif not type or vim.startswith(type, 'Union') then + return 'kObjectTypeNil' + elseif vim.startswith(type, 'LuaRefOf') then + return 'kObjectTypeLuaRef' elseif type == 'StringArray' then return 'kUnpackTypeStringArray' - elseif type ~= nil then - return 'kObjectType' .. type + elseif vim.startswith(type, 'ArrayOf') then + return 'kObjectTypeArray' else - return 'kObjectTypeNil' + return 'kObjectType' .. type end end diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 5f0a2e0e4e..b063a7708d 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -1075,10 +1075,10 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e return hlattrs; } if (HAS_KEY_X(dict, global_link)) { - *link_id = object_to_hl_id(dict->global_link, "link", err); + *link_id = (int)dict->global_link; mask |= HL_GLOBAL; } else { - *link_id = object_to_hl_id(dict->link, "link", err); + *link_id = (int)dict->link; } if (ERROR_SET(err)) { |