aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/update-lockfile.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-04-14 16:25:28 +0200
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commitc17de5689045f75c6244462182ae3b4b62df02d9 (patch)
treeec7785ec523ad4704d09bb5dc5393e1f00046508 /scripts/update-lockfile.lua
parentfix: vim.tbl_flatten is deprecated (diff)
downloadnvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar.gz
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar.bz2
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar.lz
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar.xz
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.tar.zst
nvim-treesitter-c17de5689045f75c6244462182ae3b4b62df02d9.zip
feat!: track parser revision in Lua
Problem: Tracking parser revision in lockfile and allowing override through the parsers module complicates the code. In addition, only revision changes are handled robustly, not changes to other installation info. Solution: Track parser revision in the parsers module directly. Reload parser table on every install or update call. Support modifying parser table in a `User TSUpdate` autocommand.
Diffstat (limited to 'scripts/update-lockfile.lua')
-rwxr-xr-xscripts/update-lockfile.lua64
1 files changed, 0 insertions, 64 deletions
diff --git a/scripts/update-lockfile.lua b/scripts/update-lockfile.lua
deleted file mode 100755
index d77baed61..000000000
--- a/scripts/update-lockfile.lua
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env -S nvim -l
-vim.opt.runtimepath:append('.')
-local util = require('nvim-treesitter.util')
-local parsers = require('nvim-treesitter.parsers').configs
-
--- Load previous lockfile
-local filename = require('nvim-treesitter.install').get_package_path('lockfile.json')
-local old_lockfile = vim.json.decode(util.read_file(filename)) --[[@as table<string,{revision:string}>]]
-
-local jobs = {} ---@type table<string,vim.SystemObj>
-local new_lockfile = {} ---@type table<string,{revision:string}>
-local updates = {} ---@type string[]
-
--- check for new revisions
-for k, p in pairs(parsers) do
- if p.tier == 4 then
- new_lockfile[k] = old_lockfile[k]
- print('Skipping ' .. k)
- elseif p.install_info then
- print('Updating ' .. k)
- jobs[k] = vim.system({ 'git', 'ls-remote', p.install_info.url })
- end
-
- if #vim.tbl_keys(jobs) % 100 == 0 or next(parsers, k) == nil then
- for name, job in pairs(jobs) do
- local stdout = vim.split(job:wait().stdout, '\n')
- jobs[name] = nil
-
- local branch = parsers[name].install_info.branch
-
- local line = 1
- if branch then
- for j, l in ipairs(stdout) do
- if l:find(vim.pesc(branch)) then
- line = j
- break
- end
- end
- end
-
- local sha = vim.split(stdout[line], '\t')[1]
- new_lockfile[name] = { revision = sha }
- if new_lockfile[name].revision ~= old_lockfile[name].revision then
- updates[#updates + 1] = name
- end
- end
- end
-end
-
-assert(#vim.tbl_keys(jobs) == 0)
-
-if #updates > 0 then
- -- write new lockfile
- local lockfile_json = vim.json.encode(new_lockfile) --[[@as string]]
- if vim.fn.executable('jq') == 1 then
- lockfile_json =
- assert(vim.system({ 'jq', '--sort-keys' }, { stdin = lockfile_json }):wait().stdout)
- end
- util.write_file(filename, lockfile_json)
-
- print(string.format('\nUpdated parsers: %s', table.concat(updates, ', ')))
-else
- print('\nAll parsers up to date!')
-end