aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/convert-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/convert-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/convert-lockfile.lua')
-rwxr-xr-xscripts/convert-lockfile.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/convert-lockfile.lua b/scripts/convert-lockfile.lua
new file mode 100755
index 000000000..e0a694897
--- /dev/null
+++ b/scripts/convert-lockfile.lua
@@ -0,0 +1,21 @@
+#!/usr/bin/env -S nvim -l
+vim.opt.runtimepath:append('.')
+local util = require('nvim-treesitter.util')
+local parsers = require('nvim-treesitter.parsers')
+
+local filename = require('nvim-treesitter.install').get_package_path('lockfile.json')
+local lockfile = vim.json.decode(util.read_file(filename)) --[[@as table<string,{revision:string}>]]
+
+for k, p in pairs(parsers) do
+ if p.install_info then
+ p.install_info.revision = lockfile[k].revision
+ end
+end
+
+-- write new parser file
+local header = '---@type nvim-ts.parsers\nreturn '
+local parser_file = header .. vim.inspect(parsers)
+if vim.fn.executable('stylua') == 1 then
+ parser_file = vim.system({ 'stylua', '-' }, { stdin = parser_file }):wait().stdout --[[@as string]]
+end
+util.write_file('lua/nvim-treesitter/parsers.lua', parser_file)