-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_opt.lua
118 lines (97 loc) · 2.56 KB
/
gen_opt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
local opt_keys = vim.api.nvim_get_all_options_info()
local inspect = vim.inspect
local opt_lines = {[[
---@meta
---@class vim.opt.Opt
local Opt = {}
---@return any
function Opt:get() end
---@param value any
function Opt:append(value) end
---@param value any
function Opt:prepend(value) end
---@param value any
function Opt:remove(value) end
]]}
local o_lines = {[[
---@meta
]]}
local function opt_ins(s)
table.insert(opt_lines, s)
end
local function o_ins(s)
table.insert(o_lines, s)
end
local docs = dofile('gen_opt_doc.lua')
local opts = {}
for opt in pairs(opt_keys) do
table.insert(opts, opt)
end
table.sort(opts)
local IGNORED_DEFAULTS = {
runtimepath = true,
packpath = true,
helpfile = true,
backupdir = true,
directory = true,
shell = true,
undodir = true,
viewdir = true,
}
for _, key in ipairs(opts) do
local opt = opt_keys[key]
local doc = docs[key]
local default = inspect(opt.default)
if IGNORED_DEFAULTS[opt.name] then
default = '""'
end
if doc then
for i, line in ipairs(doc) do
doc[i] = '---'..line
end
doc[#doc+1] = '---'
doc = table.concat(doc, '\n')
end
o_ins('')
if doc then o_ins(doc) end
o_ins(('---@type %s'):format(opt.type))
o_ins(('vim.o.%s = %s'):format(opt.name, default))
opt_ins('')
if doc then opt_ins(doc) end
opt_ins('---@type vim.opt.Opt')
opt_ins(('vim.opt.%s = %s'):format(opt.name, default))
-- vim.bo and vim.wo sucks anyway
-- if opt.scope == 'buf' then
-- o_ins(('---@type %s'):format(opt.type))
-- o_ins(('vim.bo.%s = %s'):format(opt.name, default))
-- elseif opt.scope == 'win' then
-- o_ins(('---@type %s'):format(opt.type))
-- o_ins(('vim.wo.%s = %s'):format(opt.name, default))
-- end
-- no short options
-- if opt.shortname and opt.shortname ~= '' then
-- o_ins(('--- %s'):format(opt.name))
-- o_ins(('---@type %s'):format(opt.type))
-- o_ins(('vim.o.%s = %s'):format(opt.shortname, default))
-- if opt.scope == 'buf' then
-- o_ins(('---@type %s'):format(opt.type))
-- o_ins(('vim.bo.%s = %s'):format(opt.shortname, default))
-- elseif opt.scope == 'win' then
-- o_ins(('---@type %s'):format(opt.type))
-- o_ins(('vim.wo.%s = %s'):format(opt.shortname, default))
-- end
-- end
end
opt_ins('')
opt_ins('vim.opt_local = vim.opt')
opt_ins('vim.opt_global = vim.opt')
do
local f = io.open('./nvim/library/vim.opt.lua', 'w+b')
f:write(table.concat(opt_lines, '\n'))
f:flush()
end
do
local f = io.open('./nvim/library/vim.o.lua', 'w+b')
f:write(table.concat(o_lines, '\n'))
f:flush()
end