mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
feat(keysets): teach Union and LuaRefOf
This commit is contained in:
committed by
Lewis Russell
parent
99e7323aa3
commit
8d55cc218c
2
runtime/lua/vim/_meta/api.lua
generated
2
runtime/lua/vim/_meta/api.lua
generated
@ -1012,7 +1012,7 @@ function vim.api.nvim_create_namespace(name) end
|
|||||||
--- ```
|
--- ```
|
||||||
---
|
---
|
||||||
--- @param name string Name of the new user command. Must begin with an uppercase letter.
|
--- @param name string Name of the new user command. Must begin with an uppercase letter.
|
||||||
--- @param command any Replacement command to execute when this user command is executed. When called
|
--- @param command string|fun(args: vim.api.keyset.create_user_command.command_args) Replacement command to execute when this user command is executed. When called
|
||||||
--- from Lua, the command can also be a Lua function. The function is called with a
|
--- from Lua, the command can also be a Lua function. The function is called with a
|
||||||
--- single table argument that contains the following keys:
|
--- single table argument that contains the following keys:
|
||||||
--- - name: (string) Command name
|
--- - name: (string) Command name
|
||||||
|
100
runtime/lua/vim/_meta/api_keysets.lua
generated
100
runtime/lua/vim/_meta/api_keysets.lua
generated
@ -4,11 +4,11 @@
|
|||||||
error('Cannot require a meta file')
|
error('Cannot require a meta file')
|
||||||
|
|
||||||
--- @class vim.api.keyset.buf_attach
|
--- @class vim.api.keyset.buf_attach
|
||||||
--- @field on_lines? function
|
--- @field on_lines? fun(_: "lines", bufnr: integer, changedtick: integer, first: integer, last_old: integer, last_new: integer, byte_count: integer, deleted_codepoints?: integer, deleted_codeunits?: integer): boolean?
|
||||||
--- @field on_bytes? function
|
--- @field on_bytes? fun(_: "bytes", 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: integer): boolean?
|
||||||
--- @field on_changedtick? function
|
--- @field on_changedtick? fun(_: "changedtick", bufnr: integer, changedtick: integer)
|
||||||
--- @field on_detach? function
|
--- @field on_detach? fun(_: "detach", bufnr: integer)
|
||||||
--- @field on_reload? function
|
--- @field on_reload? fun(_: "reload", bufnr: integer)
|
||||||
--- @field utf_sizes? boolean
|
--- @field utf_sizes? boolean
|
||||||
--- @field preview? boolean
|
--- @field preview? boolean
|
||||||
|
|
||||||
@ -18,9 +18,9 @@ error('Cannot require a meta file')
|
|||||||
|
|
||||||
--- @class vim.api.keyset.clear_autocmds
|
--- @class vim.api.keyset.clear_autocmds
|
||||||
--- @field buffer? integer
|
--- @field buffer? integer
|
||||||
--- @field event? any
|
--- @field event? string|string[]
|
||||||
--- @field group? any
|
--- @field group? integer|string
|
||||||
--- @field pattern? any
|
--- @field pattern? string|string[]
|
||||||
|
|
||||||
--- @class vim.api.keyset.cmd
|
--- @class vim.api.keyset.cmd
|
||||||
--- @field cmd? string
|
--- @field cmd? string
|
||||||
@ -28,12 +28,12 @@ error('Cannot require a meta file')
|
|||||||
--- @field count? integer
|
--- @field count? integer
|
||||||
--- @field reg? string
|
--- @field reg? string
|
||||||
--- @field bang? boolean
|
--- @field bang? boolean
|
||||||
--- @field args? any[]
|
--- @field args? string[]
|
||||||
--- @field magic? table<string,any>
|
--- @field magic? table<string,any>
|
||||||
--- @field mods? table<string,any>
|
--- @field mods? table<string,any>
|
||||||
--- @field nargs? any
|
--- @field nargs? integer|string
|
||||||
--- @field addr? any
|
--- @field addr? string
|
||||||
--- @field nextcmd? any
|
--- @field nextcmd? string
|
||||||
|
|
||||||
--- @class vim.api.keyset.cmd_magic
|
--- @class vim.api.keyset.cmd_magic
|
||||||
--- @field file? boolean
|
--- @field file? boolean
|
||||||
@ -72,20 +72,20 @@ error('Cannot require a meta file')
|
|||||||
--- @field info? string
|
--- @field info? string
|
||||||
|
|
||||||
--- @class vim.api.keyset.context
|
--- @class vim.api.keyset.context
|
||||||
--- @field types? any[]
|
--- @field types? string[]
|
||||||
|
|
||||||
--- @class vim.api.keyset.create_augroup
|
--- @class vim.api.keyset.create_augroup
|
||||||
--- @field clear? any
|
--- @field clear? boolean
|
||||||
|
|
||||||
--- @class vim.api.keyset.create_autocmd
|
--- @class vim.api.keyset.create_autocmd
|
||||||
--- @field buffer? integer
|
--- @field buffer? integer
|
||||||
--- @field callback? any
|
--- @field callback? string|(fun(args: vim.api.keyset.create_autocmd.callback_args): boolean?)
|
||||||
--- @field command? string
|
--- @field command? string
|
||||||
--- @field desc? string
|
--- @field desc? string
|
||||||
--- @field group? any
|
--- @field group? integer|string
|
||||||
--- @field nested? boolean
|
--- @field nested? boolean
|
||||||
--- @field once? boolean
|
--- @field once? boolean
|
||||||
--- @field pattern? any
|
--- @field pattern? string|string[]
|
||||||
|
|
||||||
--- @class vim.api.keyset.echo_opts
|
--- @class vim.api.keyset.echo_opts
|
||||||
--- @field verbose? boolean
|
--- @field verbose? boolean
|
||||||
@ -103,19 +103,19 @@ error('Cannot require a meta file')
|
|||||||
|
|
||||||
--- @class vim.api.keyset.exec_autocmds
|
--- @class vim.api.keyset.exec_autocmds
|
||||||
--- @field buffer? integer
|
--- @field buffer? integer
|
||||||
--- @field group? any
|
--- @field group? integer|string
|
||||||
--- @field modeline? boolean
|
--- @field modeline? boolean
|
||||||
--- @field pattern? any
|
--- @field pattern? string|string[]
|
||||||
--- @field data? any
|
--- @field data? any
|
||||||
|
|
||||||
--- @class vim.api.keyset.exec_opts
|
--- @class vim.api.keyset.exec_opts
|
||||||
--- @field output? boolean
|
--- @field output? boolean
|
||||||
|
|
||||||
--- @class vim.api.keyset.get_autocmds
|
--- @class vim.api.keyset.get_autocmds
|
||||||
--- @field event? any
|
--- @field event? string|string[]
|
||||||
--- @field group? any
|
--- @field group? integer|string
|
||||||
--- @field pattern? any
|
--- @field pattern? string|string[]
|
||||||
--- @field buffer? any
|
--- @field buffer? integer|integer[]
|
||||||
|
|
||||||
--- @class vim.api.keyset.get_commands
|
--- @class vim.api.keyset.get_commands
|
||||||
--- @field builtin? boolean
|
--- @field builtin? boolean
|
||||||
@ -154,17 +154,17 @@ error('Cannot require a meta file')
|
|||||||
--- @field altfont? boolean
|
--- @field altfont? boolean
|
||||||
--- @field nocombine? boolean
|
--- @field nocombine? boolean
|
||||||
--- @field default? boolean
|
--- @field default? boolean
|
||||||
--- @field cterm? any
|
--- @field cterm? integer|string
|
||||||
--- @field foreground? any
|
--- @field foreground? integer|string
|
||||||
--- @field fg? any
|
--- @field fg? integer|string
|
||||||
--- @field background? any
|
--- @field background? integer|string
|
||||||
--- @field bg? any
|
--- @field bg? integer|string
|
||||||
--- @field ctermfg? any
|
--- @field ctermfg? integer|string
|
||||||
--- @field ctermbg? any
|
--- @field ctermbg? integer|string
|
||||||
--- @field special? any
|
--- @field special? integer|string
|
||||||
--- @field sp? any
|
--- @field sp? integer|string
|
||||||
--- @field link? any
|
--- @field link? integer|string
|
||||||
--- @field global_link? any
|
--- @field global_link? integer|string
|
||||||
--- @field fallback? boolean
|
--- @field fallback? boolean
|
||||||
--- @field blend? integer
|
--- @field blend? integer
|
||||||
--- @field fg_indexed? boolean
|
--- @field fg_indexed? boolean
|
||||||
@ -201,7 +201,7 @@ error('Cannot require a meta file')
|
|||||||
--- @field wins? any[]
|
--- @field wins? any[]
|
||||||
|
|
||||||
--- @class vim.api.keyset.open_term
|
--- @class vim.api.keyset.open_term
|
||||||
--- @field on_input? function
|
--- @field on_input? fun(_: "input", term: integer, bufnr: integer, data: any)
|
||||||
--- @field force_crlf? boolean
|
--- @field force_crlf? boolean
|
||||||
|
|
||||||
--- @class vim.api.keyset.option
|
--- @class vim.api.keyset.option
|
||||||
@ -227,20 +227,20 @@ error('Cannot require a meta file')
|
|||||||
--- @field do_source? boolean
|
--- @field do_source? boolean
|
||||||
|
|
||||||
--- @class vim.api.keyset.set_decoration_provider
|
--- @class vim.api.keyset.set_decoration_provider
|
||||||
--- @field on_start? function
|
--- @field on_start? fun(_: "start", tick: integer)
|
||||||
--- @field on_buf? function
|
--- @field on_buf? fun(_: "buf", bufnr: integer, tick: integer)
|
||||||
--- @field on_win? function
|
--- @field on_win? fun(_: "win", winid: integer, bufnr: integer, toprow: integer, botrow: integer)
|
||||||
--- @field on_line? function
|
--- @field on_line? fun(_: "line", winid: integer, bufnr: integer, row: integer)
|
||||||
--- @field on_end? function
|
--- @field on_end? fun(_: "end", tick: integer)
|
||||||
--- @field _on_hl_def? function
|
--- @field _on_hl_def? fun(_: "hl_def")
|
||||||
--- @field _on_spell_nav? function
|
--- @field _on_spell_nav? fun(_: "spell_nav")
|
||||||
|
|
||||||
--- @class vim.api.keyset.set_extmark
|
--- @class vim.api.keyset.set_extmark
|
||||||
--- @field id? integer
|
--- @field id? integer
|
||||||
--- @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? number|string
|
--- @field hl_group? integer|string
|
||||||
--- @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
|
||||||
@ -258,10 +258,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? number|string
|
--- @field sign_hl_group? integer|string
|
||||||
--- @field number_hl_group? number|string
|
--- @field number_hl_group? integer|string
|
||||||
--- @field line_hl_group? number|string
|
--- @field line_hl_group? integer|string
|
||||||
--- @field cursorline_hl_group? number|string
|
--- @field cursorline_hl_group? integer|string
|
||||||
--- @field conceal? string
|
--- @field conceal? string
|
||||||
--- @field spell? boolean
|
--- @field spell? boolean
|
||||||
--- @field ui_watched? boolean
|
--- @field ui_watched? boolean
|
||||||
@ -292,7 +292,7 @@ error('Cannot require a meta file')
|
|||||||
--- @field relative? string
|
--- @field relative? string
|
||||||
--- @field split? string
|
--- @field split? string
|
||||||
--- @field win? integer
|
--- @field win? integer
|
||||||
--- @field bufpos? any[]
|
--- @field bufpos? integer[]
|
||||||
--- @field external? boolean
|
--- @field external? boolean
|
||||||
--- @field focusable? boolean
|
--- @field focusable? boolean
|
||||||
--- @field mouse? boolean
|
--- @field mouse? boolean
|
||||||
@ -315,12 +315,12 @@ error('Cannot require a meta file')
|
|||||||
--- @field end_vcol? integer
|
--- @field end_vcol? integer
|
||||||
|
|
||||||
--- @class vim.api.keyset.xdl_diff
|
--- @class vim.api.keyset.xdl_diff
|
||||||
--- @field on_hunk? function
|
--- @field on_hunk? fun(start_a: integer, count_a: integer, start_b: integer, count_b: integer): integer?
|
||||||
--- @field result_type? string
|
--- @field result_type? string
|
||||||
--- @field algorithm? string
|
--- @field algorithm? string
|
||||||
--- @field ctxlen? integer
|
--- @field ctxlen? integer
|
||||||
--- @field interhunkctxlen? integer
|
--- @field interhunkctxlen? integer
|
||||||
--- @field linematch? any
|
--- @field linematch? boolean|integer
|
||||||
--- @field ignore_whitespace? boolean
|
--- @field ignore_whitespace? boolean
|
||||||
--- @field ignore_whitespace_change? boolean
|
--- @field ignore_whitespace_change? boolean
|
||||||
--- @field ignore_whitespace_change_at_eol? boolean
|
--- @field ignore_whitespace_change_at_eol? boolean
|
||||||
|
@ -73,6 +73,51 @@ error('Cannot require a meta file')
|
|||||||
--- @field buflocal? boolean
|
--- @field buflocal? boolean
|
||||||
--- @field buffer? integer
|
--- @field buffer? integer
|
||||||
|
|
||||||
|
--- @class vim.api.keyset.create_autocmd.callback_args
|
||||||
|
--- @field id integer autocommand id
|
||||||
|
--- @field event string name of the triggered event |autocmd-events|
|
||||||
|
--- @field group? integer autocommand group id, if any
|
||||||
|
--- @field match string expanded value of <amatch>
|
||||||
|
--- @field buf integer expanded value of <abuf>
|
||||||
|
--- @field file string expanded value of <afile>
|
||||||
|
--- @field data? any arbitrary data passed from |nvim_exec_autocmds()| *event-data*
|
||||||
|
|
||||||
|
--- @class vim.api.keyset.create_user_command.command_args
|
||||||
|
--- @field name string Command name
|
||||||
|
---
|
||||||
|
--- The args passed to the command, if any <args>
|
||||||
|
--- @field args string
|
||||||
|
---
|
||||||
|
--- The args split by unescaped whitespace
|
||||||
|
--- (when more than one argument is allowed), if any <f-args>
|
||||||
|
--- @field fargs string[]
|
||||||
|
---
|
||||||
|
--- Number of arguments |:command-nargs|
|
||||||
|
--- @field nargs string
|
||||||
|
---
|
||||||
|
--- "true" if the command was executed with a ! modifier <bang>
|
||||||
|
--- @field bang boolean
|
||||||
|
---
|
||||||
|
--- The starting line of the command range <line1>
|
||||||
|
--- @field line1 integer
|
||||||
|
---
|
||||||
|
--- The final line of the command range <line2>
|
||||||
|
--- @field line2 integer
|
||||||
|
---
|
||||||
|
--- The number of items in the command range: 0, 1, or 2 <range>
|
||||||
|
--- @field range integer
|
||||||
|
---
|
||||||
|
--- Any count supplied <count>
|
||||||
|
--- @field count integer
|
||||||
|
--- The optional register, if specified <reg>
|
||||||
|
--- @field reg string
|
||||||
|
--- Command modifiers, if any <mods>
|
||||||
|
--- @field mods string
|
||||||
|
---
|
||||||
|
--- Command modifiers in a structured format. Has the same structure as the
|
||||||
|
--- "mods" key of |nvim_parse_cmd()|.
|
||||||
|
--- @field smods table
|
||||||
|
|
||||||
--- @class vim.api.keyset.command_info
|
--- @class vim.api.keyset.command_info
|
||||||
--- @field name string
|
--- @field name string
|
||||||
--- @field definition string
|
--- @field definition string
|
||||||
|
@ -47,6 +47,18 @@ local LUA_API_RETURN_OVERRIDES = {
|
|||||||
nvim_win_get_config = 'vim.api.keyset.win_config',
|
nvim_win_get_config = 'vim.api.keyset.win_config',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local LUA_API_KEYSET_OVERRIDES = {
|
||||||
|
create_autocmd = {
|
||||||
|
callback = 'string|(fun(args: vim.api.keyset.create_autocmd.callback_args): boolean?)',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local LUA_API_PARAM_OVERRIDES = {
|
||||||
|
nvim_create_user_command = {
|
||||||
|
command = 'string|fun(args: vim.api.keyset.create_user_command.command_args)',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
local LUA_META_HEADER = {
|
local LUA_META_HEADER = {
|
||||||
'--- @meta _',
|
'--- @meta _',
|
||||||
'-- THIS FILE IS GENERATED',
|
'-- THIS FILE IS GENERATED',
|
||||||
@ -118,7 +130,7 @@ local API_TYPES = {
|
|||||||
LuaRef = 'function',
|
LuaRef = 'function',
|
||||||
Dict = 'table<string,any>',
|
Dict = 'table<string,any>',
|
||||||
Float = 'number',
|
Float = 'number',
|
||||||
HLGroupID = 'number|string',
|
HLGroupID = 'integer|string',
|
||||||
void = '',
|
void = '',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +145,10 @@ end
|
|||||||
--- @param t string
|
--- @param t string
|
||||||
--- @return string
|
--- @return string
|
||||||
local function api_type(t)
|
local function api_type(t)
|
||||||
|
if vim.startswith(t, '*') then
|
||||||
|
return api_type(t:sub(2)) .. '?'
|
||||||
|
end
|
||||||
|
|
||||||
local as0 = t:match('^ArrayOf%((.*)%)')
|
local as0 = t:match('^ArrayOf%((.*)%)')
|
||||||
if as0 then
|
if as0 then
|
||||||
local as = split(as0, ', ')
|
local as = split(as0, ', ')
|
||||||
@ -149,6 +165,33 @@ local function api_type(t)
|
|||||||
return 'table<string,' .. api_type(d0) .. '>'
|
return 'table<string,' .. api_type(d0) .. '>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local u = t:match('^Union%((.*)%)')
|
||||||
|
if u then
|
||||||
|
local us = vim.split(u, ',%s*')
|
||||||
|
return table.concat(vim.tbl_map(api_type, us), '|')
|
||||||
|
end
|
||||||
|
|
||||||
|
local l = t:match('^LuaRefOf%((.*)%)')
|
||||||
|
if l then
|
||||||
|
--- @type string
|
||||||
|
l = l:gsub('%s+', ' ')
|
||||||
|
--- @type string?, string?
|
||||||
|
local as, r = l:match('%((.*)%),%s*(.*)')
|
||||||
|
if not as then
|
||||||
|
--- @type string
|
||||||
|
as = assert(l:match('%((.*)%)'))
|
||||||
|
end
|
||||||
|
|
||||||
|
local as1 = {} --- @type string[]
|
||||||
|
for a in vim.gsplit(as, ',%s') do
|
||||||
|
local a1 = vim.split(a, '%s+', { trimempty = true })
|
||||||
|
local nm = a1[2]:gsub('%*(.*)$', '%1?')
|
||||||
|
as1[#as1 + 1] = nm .. ': ' .. api_type(a1[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
return ('fun(%s)%s'):format(table.concat(as1, ', '), r and ': ' .. api_type(r) or '')
|
||||||
|
end
|
||||||
|
|
||||||
return API_TYPES[t] or t
|
return API_TYPES[t] or t
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -251,11 +294,13 @@ local function get_api_meta()
|
|||||||
sees[#sees + 1] = see.desc
|
sees[#sees + 1] = see.desc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pty_overrides = LUA_API_PARAM_OVERRIDES[fun.name] or {}
|
||||||
|
|
||||||
local params = {} --- @type [string,string][]
|
local params = {} --- @type [string,string][]
|
||||||
for _, p in ipairs(fun.params) do
|
for _, p in ipairs(fun.params) do
|
||||||
params[#params + 1] = {
|
params[#params + 1] = {
|
||||||
p.name,
|
p.name,
|
||||||
api_type(p.type),
|
api_type(pty_overrides[p.name] or p.type),
|
||||||
not deprecated and p.desc or nil,
|
not deprecated and p.desc or nil,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -382,9 +427,11 @@ local function get_api_keysets_meta()
|
|||||||
local keysets = metadata.keysets
|
local keysets = metadata.keysets
|
||||||
|
|
||||||
for _, k in ipairs(keysets) do
|
for _, k in ipairs(keysets) do
|
||||||
|
local pty_overrides = LUA_API_KEYSET_OVERRIDES[k.name] or {}
|
||||||
local params = {}
|
local params = {}
|
||||||
for _, key in ipairs(k.keys) do
|
for _, key in ipairs(k.keys) do
|
||||||
table.insert(params, { key .. '?', api_type(k.types[key] or 'any') })
|
local pty = pty_overrides[key] or k.types[key] or 'any'
|
||||||
|
table.insert(params, { key .. '?', api_type(pty) })
|
||||||
end
|
end
|
||||||
ret[k.name] = {
|
ret[k.name] = {
|
||||||
signature = 'NA',
|
signature = 'NA',
|
||||||
|
@ -631,7 +631,7 @@ Integer nvim_create_augroup(uint64_t channel_id, String name, Dict(create_augrou
|
|||||||
FUNC_API_SINCE(9)
|
FUNC_API_SINCE(9)
|
||||||
{
|
{
|
||||||
char *augroup_name = name.data;
|
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;
|
int augroup = -1;
|
||||||
WITH_SCRIPT_CONTEXT(channel_id, {
|
WITH_SCRIPT_CONTEXT(channel_id, {
|
||||||
|
@ -226,8 +226,8 @@ Dict(cmd) nvim_parse_cmd(String str, Dict(empty) *opts, Arena *arena, Error *err
|
|||||||
addr = "?";
|
addr = "?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PUT_KEY(result, cmd, addr, CSTR_AS_OBJ(addr));
|
PUT_KEY(result, cmd, addr, cstr_as_string(addr));
|
||||||
PUT_KEY(result, cmd, nextcmd, CSTR_AS_OBJ(ea.nextcmd));
|
PUT_KEY(result, cmd, nextcmd, cstr_as_string(ea.nextcmd));
|
||||||
|
|
||||||
// TODO(bfredl): nested keydict would be nice..
|
// TODO(bfredl): nested keydict would be nice..
|
||||||
Dict mods = arena_dict(arena, 20);
|
Dict mods = arena_dict(arena, 20);
|
||||||
|
@ -8,18 +8,18 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__context_;
|
OptionalKeys is_set__context_;
|
||||||
Array types;
|
ArrayOf(String) types;
|
||||||
} Dict(context);
|
} Dict(context);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__set_decoration_provider_;
|
OptionalKeys is_set__set_decoration_provider_;
|
||||||
LuaRef on_start;
|
LuaRefOf(("start" _, Integer tick)) on_start;
|
||||||
LuaRef on_buf;
|
LuaRefOf(("buf" _, Integer bufnr, Integer tick)) on_buf;
|
||||||
LuaRef on_win;
|
LuaRefOf(("win" _, Integer winid, Integer bufnr, Integer toprow, Integer botrow)) on_win;
|
||||||
LuaRef on_line;
|
LuaRefOf(("line" _, Integer winid, Integer bufnr, Integer row)) on_line;
|
||||||
LuaRef on_end;
|
LuaRefOf(("end" _, Integer tick)) on_end;
|
||||||
LuaRef _on_hl_def;
|
LuaRefOf(("hl_def" _)) _on_hl_def;
|
||||||
LuaRef _on_spell_nav;
|
LuaRefOf(("spell_nav" _)) _on_spell_nav;
|
||||||
} Dict(set_decoration_provider);
|
} Dict(set_decoration_provider);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -116,7 +116,7 @@ typedef struct {
|
|||||||
String relative;
|
String relative;
|
||||||
String split;
|
String split;
|
||||||
Window win;
|
Window win;
|
||||||
Array bufpos;
|
ArrayOf(Integer) bufpos;
|
||||||
Boolean external;
|
Boolean external;
|
||||||
Boolean focusable;
|
Boolean focusable;
|
||||||
Boolean mouse;
|
Boolean mouse;
|
||||||
@ -172,17 +172,17 @@ typedef struct {
|
|||||||
Boolean altfont;
|
Boolean altfont;
|
||||||
Boolean nocombine;
|
Boolean nocombine;
|
||||||
Boolean default_ DictKey(default);
|
Boolean default_ DictKey(default);
|
||||||
Object cterm;
|
Union(Integer, String) cterm;
|
||||||
Object foreground;
|
Union(Integer, String) foreground;
|
||||||
Object fg;
|
Union(Integer, String) fg;
|
||||||
Object background;
|
Union(Integer, String) background;
|
||||||
Object bg;
|
Union(Integer, String) bg;
|
||||||
Object ctermfg;
|
Union(Integer, String) ctermfg;
|
||||||
Object ctermbg;
|
Union(Integer, String) ctermbg;
|
||||||
Object special;
|
Union(Integer, String) special;
|
||||||
Object sp;
|
Union(Integer, String) sp;
|
||||||
Object link;
|
HLGroupID link;
|
||||||
Object global_link;
|
HLGroupID global_link;
|
||||||
Boolean fallback;
|
Boolean fallback;
|
||||||
Integer blend;
|
Integer blend;
|
||||||
Boolean fg_indexed;
|
Boolean fg_indexed;
|
||||||
@ -230,9 +230,9 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__clear_autocmds_;
|
OptionalKeys is_set__clear_autocmds_;
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
Object event;
|
Union(String, ArrayOf(String)) event;
|
||||||
Object group;
|
Union(Integer, String) group;
|
||||||
Object pattern;
|
Union(String, ArrayOf(String)) pattern;
|
||||||
} Dict(clear_autocmds);
|
} Dict(clear_autocmds);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -241,31 +241,32 @@ typedef struct {
|
|||||||
Object callback;
|
Object callback;
|
||||||
String command;
|
String command;
|
||||||
String desc;
|
String desc;
|
||||||
Object group;
|
Union(Integer, String) group;
|
||||||
Boolean nested;
|
Boolean nested;
|
||||||
Boolean once;
|
Boolean once;
|
||||||
Object pattern;
|
Union(String, ArrayOf(String)) pattern;
|
||||||
} Dict(create_autocmd);
|
} Dict(create_autocmd);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__exec_autocmds_;
|
OptionalKeys is_set__exec_autocmds_;
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
Object group;
|
Union(Integer, String) group;
|
||||||
Boolean modeline;
|
Boolean modeline;
|
||||||
Object pattern;
|
Union(String, ArrayOf(String)) pattern;
|
||||||
Object data;
|
Object data;
|
||||||
} Dict(exec_autocmds);
|
} Dict(exec_autocmds);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__get_autocmds_;
|
OptionalKeys is_set__get_autocmds_;
|
||||||
Object event;
|
Union(String, ArrayOf(String)) event;
|
||||||
Object group;
|
Union(Integer, String) group;
|
||||||
Object pattern;
|
Union(String, ArrayOf(String)) pattern;
|
||||||
Object buffer;
|
Union(Integer, ArrayOf(Integer)) buffer;
|
||||||
} Dict(get_autocmds);
|
} Dict(get_autocmds);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Object clear;
|
OptionalKeys is_set__create_augroup_;
|
||||||
|
Boolean clear;
|
||||||
} Dict(create_augroup);
|
} Dict(create_augroup);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -275,12 +276,12 @@ typedef struct {
|
|||||||
Integer count;
|
Integer count;
|
||||||
String reg;
|
String reg;
|
||||||
Boolean bang;
|
Boolean bang;
|
||||||
Array args;
|
ArrayOf(String) args;
|
||||||
Dict magic;
|
Dict magic;
|
||||||
Dict mods;
|
Dict mods;
|
||||||
Object nargs;
|
Union(Integer, String) nargs;
|
||||||
Object addr;
|
String addr;
|
||||||
Object nextcmd;
|
String nextcmd;
|
||||||
} Dict(cmd);
|
} Dict(cmd);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -333,11 +334,30 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__buf_attach_;
|
OptionalKeys is_set__buf_attach_;
|
||||||
LuaRef on_lines;
|
LuaRefOf(("lines" _,
|
||||||
LuaRef on_bytes;
|
Integer bufnr,
|
||||||
LuaRef on_changedtick;
|
Integer changedtick,
|
||||||
LuaRef on_detach;
|
Integer first,
|
||||||
LuaRef on_reload;
|
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 utf_sizes;
|
||||||
Boolean preview;
|
Boolean preview;
|
||||||
} Dict(buf_attach);
|
} Dict(buf_attach);
|
||||||
@ -350,7 +370,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__open_term_;
|
OptionalKeys is_set__open_term_;
|
||||||
LuaRef on_input;
|
LuaRefOf(("input" _, Integer term, Integer bufnr, any data)) on_input;
|
||||||
Boolean force_crlf;
|
Boolean force_crlf;
|
||||||
} Dict(open_term);
|
} Dict(open_term);
|
||||||
|
|
||||||
@ -361,12 +381,13 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OptionalKeys is_set__xdl_diff_;
|
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 result_type;
|
||||||
String algorithm;
|
String algorithm;
|
||||||
Integer ctxlen;
|
Integer ctxlen;
|
||||||
Integer interhunkctxlen;
|
Integer interhunkctxlen;
|
||||||
Object linematch;
|
Union(Boolean, Integer) linematch;
|
||||||
Boolean ignore_whitespace;
|
Boolean ignore_whitespace;
|
||||||
Boolean ignore_whitespace_change;
|
Boolean ignore_whitespace_change;
|
||||||
Boolean ignore_whitespace_change_at_eol;
|
Boolean ignore_whitespace_change_at_eol;
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
# define Dict(name) KeyDict_##name
|
# define Dict(name) KeyDict_##name
|
||||||
# define DictHash(name) KeyDict_##name##_get_field
|
# define DictHash(name) KeyDict_##name##_get_field
|
||||||
# define DictKey(name)
|
# define DictKey(name)
|
||||||
|
# define LuaRefOf(...) LuaRef
|
||||||
|
# define Union(...) Object
|
||||||
# include "api/private/defs.h.inline.generated.h"
|
# include "api/private/defs.h.inline.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ local lpeg = vim.lpeg
|
|||||||
-- lpeg grammar for building api metadata from a set of header files. It
|
-- lpeg grammar for building api metadata from a set of header files. It
|
||||||
-- ignores comments and preprocessor commands and parses a very small subset
|
-- ignores comments and preprocessor commands and parses a very small subset
|
||||||
-- of C prototypes with a limited set of types
|
-- 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
|
local C, Ct, Cc, Cg = lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cg
|
||||||
|
|
||||||
--- @param pat vim.lpeg.Pattern
|
--- @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 c_preproc = P('#') * rep(not_nl)
|
||||||
local dllexport = P('DLLEXPORT') * rep1(ws)
|
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
|
||||||
|
|
||||||
local c_id = (typed_container + (letter * rep(alpha)))
|
-- 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 + basic_id
|
||||||
local c_void = P('void')
|
local c_void = P('void')
|
||||||
|
|
||||||
local c_param_type = (
|
local c_param_type = (
|
||||||
|
@ -347,12 +347,16 @@ for _, k in ipairs(keysets) do
|
|||||||
local function typename(type)
|
local function typename(type)
|
||||||
if type == 'HLGroupID' then
|
if type == 'HLGroupID' then
|
||||||
return 'kObjectTypeInteger'
|
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
|
elseif type == 'StringArray' then
|
||||||
return 'kUnpackTypeStringArray'
|
return 'kUnpackTypeStringArray'
|
||||||
elseif type ~= nil then
|
elseif vim.startswith(type, 'ArrayOf') then
|
||||||
return 'kObjectType' .. type
|
return 'kObjectTypeArray'
|
||||||
else
|
else
|
||||||
return 'kObjectTypeNil'
|
return 'kObjectType' .. type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1075,10 +1075,10 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
|
|||||||
return hlattrs;
|
return hlattrs;
|
||||||
}
|
}
|
||||||
if (HAS_KEY_X(dict, global_link)) {
|
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;
|
mask |= HL_GLOBAL;
|
||||||
} else {
|
} else {
|
||||||
*link_id = object_to_hl_id(dict->link, "link", err);
|
*link_id = (int)dict->link;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ERROR_SET(err)) {
|
if (ERROR_SET(err)) {
|
||||||
|
Reference in New Issue
Block a user