aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkylo252 <59826753+kylo252@users.noreply.github.com>2023-07-18 15:00:44 +0200
committerGitHub <noreply@github.com>2023-07-18 06:00:44 -0700
commitd0ae529861594b2e89a436ed2cfb3d2243f8bfcc (patch)
treecb18a15d47e3c715cdc461997e7dd67ed4671bcc
parent9fcb0a64ee9195434113c10cb6e958cfe3b2c2cd (diff)
downloadrneovim-d0ae529861594b2e89a436ed2cfb3d2243f8bfcc.tar.gz
rneovim-d0ae529861594b2e89a436ed2cfb3d2243f8bfcc.tar.bz2
rneovim-d0ae529861594b2e89a436ed2cfb3d2243f8bfcc.zip
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
-rw-r--r--scripts/lsp_types.lua31
1 files changed, 18 insertions, 13 deletions
diff --git a/scripts/lsp_types.lua b/scripts/lsp_types.lua
index 8f3ed811d6..4a089bd76d 100644
--- a/scripts/lsp_types.lua
+++ b/scripts/lsp_types.lua
@@ -1,7 +1,9 @@
--[[
Generates lua-ls annotations for lsp
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 = {}
@@ -17,18 +19,17 @@ local function tofile(fname, text)
end
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')
end
vim.fn.system({
'curl',
- 'https://raw.githubusercontent.com/microsoft/lsprotocol/main/generator/lsp.json',
+ 'https://raw.githubusercontent.com/microsoft/lsprotocol/' .. opt.ref .. '/generator/lsp.json',
'-o',
'./lsp.json',
})
local protocol = vim.fn.json_decode(vim.fn.readfile('./lsp.json'))
vim.fn.delete('./lsp.json')
- local output_file = opt[1]
protocol = protocol or {}
local output = {
'--[[',
@@ -184,17 +185,21 @@ function M.gen(opt)
output[#output + 1] = line
end
- tofile(output_file, table.concat(output, '\n'))
+ tofile(opt.output_file, table.concat(output, '\n'))
end
-local opt = {}
-
-local index = 1
-for _, a in ipairs(arg) do
- if vim.startswith(a, '--') then
- local name = a:sub(3)
- opt[index] = name
- index = index + 1
+local opt = {
+ output_file = 'runtime/lua/vim/lsp/types/protocol.lua',
+ ref = 'main',
+}
+
+for i = 1, #_G.arg do
+ if _G.arg[i] == '--out' then
+ opt.output_file = _G.arg[i+1]
+ elseif _G.arg[i] == '--ref' then
+ opt.ref = _G.arg[i+1]
+ elseif vim.startswith(_G.arg[i], '--') then
+ opt.output_file = _G.arg[i]:sub(3)
end
end