build(scripts): allow a git ref for lsp_types #24377

USAGE:
nvim -l scripts/lsp_types.lua gen
nvim -l scripts/lsp_types.lua gen --build/new_lsp_types.lua
nvim -l scripts/lsp_types.lua gen --out runtime/lua/vim/lsp/types/protocol.lua --ref 2023.0.0a2
This commit is contained in:
kylo252 2023-07-18 15:00:44 +02:00 committed by GitHub
parent 9fcb0a64ee
commit d0ae529861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,9 @@
--[[ --[[
Generates lua-ls annotations for lsp Generates lua-ls annotations for lsp
USAGE: USAGE:
nvim -l scripts/lsp_types.lua gen --runtime/lua/vim/lsp/types/protocol.lua nvim -l scripts/lsp_types.lua gen # this will overwrite runtime/lua/vim/lsp/types/protocol.lua
nvim -l scripts/lsp_types.lua gen --build/new_lsp_types.lua
nvim -l scripts/lsp_types.lua gen --out runtime/lua/vim/lsp/types/protocol.lua --ref 2023.0.0a2 # specify a git reference from microsoft/lsprotocol
--]] --]]
local M = {} local M = {}
@ -17,18 +19,17 @@ local function tofile(fname, text)
end end
function M.gen(opt) function M.gen(opt)
if vim.loop.fs_stat('./lsp.json') then if vim.uv.fs_stat('./lsp.json') then
vim.fn.delete('./lsp.json') vim.fn.delete('./lsp.json')
end end
vim.fn.system({ vim.fn.system({
'curl', 'curl',
'https://raw.githubusercontent.com/microsoft/lsprotocol/main/generator/lsp.json', 'https://raw.githubusercontent.com/microsoft/lsprotocol/' .. opt.ref .. '/generator/lsp.json',
'-o', '-o',
'./lsp.json', './lsp.json',
}) })
local protocol = vim.fn.json_decode(vim.fn.readfile('./lsp.json')) local protocol = vim.fn.json_decode(vim.fn.readfile('./lsp.json'))
vim.fn.delete('./lsp.json') vim.fn.delete('./lsp.json')
local output_file = opt[1]
protocol = protocol or {} protocol = protocol or {}
local output = { local output = {
'--[[', '--[[',
@ -184,17 +185,21 @@ function M.gen(opt)
output[#output + 1] = line output[#output + 1] = line
end end
tofile(output_file, table.concat(output, '\n')) tofile(opt.output_file, table.concat(output, '\n'))
end end
local opt = {} local opt = {
output_file = 'runtime/lua/vim/lsp/types/protocol.lua',
ref = 'main',
}
local index = 1 for i = 1, #_G.arg do
for _, a in ipairs(arg) do if _G.arg[i] == '--out' then
if vim.startswith(a, '--') then opt.output_file = _G.arg[i+1]
local name = a:sub(3) elseif _G.arg[i] == '--ref' then
opt[index] = name opt.ref = _G.arg[i+1]
index = index + 1 elseif vim.startswith(_G.arg[i], '--') then
opt.output_file = _G.arg[i]:sub(3)
end end
end end