robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #38117 from noib3/fix-lua-lints-in-srcdce8bdd247

master
2.6 KiB83 linesraw
1local mpack = vim.mpack
2
3assert(#arg == 7)
4local funcs_metadata_inputf = arg[1] -- exported functions metadata
5local ui_metadata_inputf = arg[2] -- ui events metadata
6local ui_options_inputf = arg[3] -- for ui options
7local git_version_inputf = arg[4] -- git version header
8local nvim_version_inputf = arg[5] -- nvim version
9local dump_bin_array_inputf = arg[6]
10local api_metadata_outputf = arg[7]
11
12local version = loadfile(nvim_version_inputf)() --[[@as {[1]: string, [2]: any}[] ]]
13local git_version = io.open(git_version_inputf):read '*a'
14local version_build = git_version:match('#define NVIM_VERSION_BUILD "([^"]+)"') or vim.NIL
15
16local text = assert(io.open(ui_options_inputf)):read '*a'
17local ui_options_text = assert(text:match('ui_ext_names%[][^{]+{([^}]+)}')) --[[@as string]]
18local ui_options = { 'rgb' }
19for x in ui_options_text:gmatch('"([a-z][a-z_]+)"') do
20  table.insert(ui_options, x)
21end
22
23local pieces = {} --- @type string[]
24
25-- Naively using mpack.encode({foo=x, bar=y}) will make the build
26-- "non-reproducible". Emit maps directly as FIXDICT(2) "foo" x "bar" y instead
27local function fixdict(num)
28  if num > 15 then
29    error 'implement more dict codes'
30  end
31  pieces[#pieces + 1] = string.char(128 + num)
32end
33
34local function put(item, item2)
35  table.insert(pieces, mpack.encode(item))
36  if item2 ~= nil then
37    table.insert(pieces, mpack.encode(item2))
38  end
39end
40
41fixdict(6)
42
43put('version')
44fixdict(1 + #version)
45for _, item in ipairs(version) do
46  -- NB: all items are mandatory. But any error will be less confusing
47  -- with placeholder vim.NIL (than invalid mpack data)
48  local val = item[2] == nil and vim.NIL or item[2]
49  put(item[1], val)
50end
51put('build', version_build)
52
53put('functions')
54table.insert(pieces, io.open(funcs_metadata_inputf, 'rb'):read('*all'))
55put('ui_events')
56table.insert(pieces, io.open(ui_metadata_inputf, 'rb'):read('*all'))
57put('ui_options', ui_options)
58
59put('error_types')
60fixdict(2)
61put('Exception', { id = 0 })
62put('Validation', { id = 1 })
63
64put('types')
65local types =
66  { { 'Buffer', 'nvim_buf_' }, { 'Window', 'nvim_win_' }, { 'Tabpage', 'nvim_tabpage_' } }
67fixdict(#types)
68for i, item in ipairs(types) do
69  put(item[1])
70  fixdict(2)
71  put('id', i - 1)
72  put('prefix', item[2])
73end
74
75local packed = table.concat(pieces)
76--- @type fun(api_metadata: file*, name: string, packed: string)
77local dump_bin_array = loadfile(dump_bin_array_inputf)()
78
79-- serialize the API metadata using msgpack and embed into the resulting
80-- binary for easy querying by clients
81local api_metadata_output = assert(io.open(api_metadata_outputf, 'wb'))
82dump_bin_array(api_metadata_output, 'packed_api_metadata', packed)
83api_metadata_output:close()