diff --git a/README.md b/README.md index fb4691bf3..82381839e 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ require'nvim-treesitter'.install { 'rust', 'javascript', 'zig' } (This is a no-op if the parsers are already installed.) Note that this function runs asynchronously; for synchronous installation in a script context ("bootstrapping"), use something like ```lua local done = nil -require('nvim-treesitter').install({ 'rust', 'javascript', 'zig' }, function(success) - done = success +require('nvim-treesitter').install({ 'rust', 'javascript', 'zig' }):await(function(_, ok) + done = ok end) vim.wait(3000000, function() return done ~= nil end) ``` diff --git a/TODO.md b/TODO.md index 5f12ac997..937a8b63b 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,6 @@ This document lists the planned and finished changes in this rewrite towards [Nv ## TODO -- [ ] **`install.lua`:** migrate to async v2 - [ ] **tests:** remove custom crate, plenary dependency - [ ] **indents:** rewrite (Helix or Zed compatible) - [ ] **textobjects:** include simple(!) `node`, `scope` (using `locals`) objects @@ -26,3 +25,4 @@ This document lists the planned and finished changes in this rewrite towards [Nv - [X] drop ensure_install (replace with install) - [X] **CI:** switch to ts_query_ls, add update readme as check (remove update job) - [X] **CI:** track versioned releases for tier 1 +- [X] **`install.lua`:** migrate to async v2 diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index c810023f7..9b20da31d 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -102,7 +102,7 @@ setup({opts}) *nvim-treesitter.setup()* directory to install parsers and queries to. Note: will be appended to |runtimepath|. -install({languages}, {opts}, {callback}) *nvim-treesitter.install()* +install({languages} [, {opts}]) *nvim-treesitter.install()* Download, compile, and install the specified treesitter parsers and copy the corresponding queries to a directory on |runtimepath|, enabling their @@ -110,12 +110,10 @@ install({languages}, {opts}, {callback}) *nvim-treesitter.install()* Note: This operation is performed asynchronously by default. For synchronous operation (e.g., in a bootstrapping script), you need to - provide a suitable {callback}: >lua + `await()` it: >lua local done = nil - require('nvim-treesitter').install({ 'rust', 'javascript', 'zig' }, - function(success) - done = success - end) + require('nvim-treesitter').install({ 'rust', 'javascript', 'zig' }) + :await(function(_, ok) done = ok end) vim.wait(3000000, function() return done ~= nil end) < Parameters: ~ @@ -129,7 +127,6 @@ install({languages}, {opts}, {callback}) *nvim-treesitter.install()* compiling. • {max_jobs} (`integer?`) limit parallel tasks (useful in combination with {generate} on memory-limited systems). - • {callback} `(function?`) Callback for synchronous execution. uninstall({languages}) *nvim-treesitter.uninstall()* @@ -139,25 +136,21 @@ uninstall({languages}) *nvim-treesitter.uninstall() • {languages} `(string[]|string)` (List of) languages or tiers (`stable`, `unstable`) to update. -update({languages}, {callback}) *nvim-treesitter.update()* +update([{languages}]) *nvim-treesitter.update()* Update the parsers and queries if older than the revision specified in the manifest. Note: This operation is performed asynchronously by default. For synchronous operation (e.g., in a bootstrapping script), you need to - provide a suitable {callback}: >lua + `await()` it: >lua local done = nil - require('nvim-treesitter').update(), - function(success) - done = success - end) + require('nvim-treesitter').update():await(function(_, ok) done = ok end) vim.wait(3000000, function() return done ~= nil end) < Parameters: ~ - • {languages} `(string[]|string)` (List of) languages or tiers to - uninstall. - • {callback} `(function?`) Callback for synchronous execution. + • {languages} `(string[]|string)?` (List of) languages or tiers to update + (default: all installed). indentexpr() *nvim-treesitter.indentexpr()* diff --git a/scripts/install-parsers.lua b/scripts/install-parsers.lua index 6dbc73d68..31b662a35 100755 --- a/scripts/install-parsers.lua +++ b/scripts/install-parsers.lua @@ -21,24 +21,22 @@ vim.opt.runtimepath:append('.') -- needed on CI vim.fn.mkdir(vim.fn.stdpath('cache'), 'p') -local ok = nil +local done = nil if update then - require('nvim-treesitter.install').update('all', {}, function(success) - ok = success + require('nvim-treesitter.install').update('all'):await(function(_err, ok) + done = ok end) else - require('nvim-treesitter.install').install( - #parsers > 0 and parsers or 'all', - { force = true, generate = generate, max_jobs = max_jobs }, - function(success) - ok = success - end - ) + require('nvim-treesitter.install') + .install(#parsers > 0 and parsers or 'all', { force = true, generate = generate, max_jobs = max_jobs }) + :await(function(_err, ok) + done = ok + end) end vim.wait(6000000, function() - return ok ~= nil + return done ~= nil end) -if not ok then +if not done then vim.cmd.cq() end