summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ci/install_treesitter_parsers.lua72
-rw-r--r--scripts/tests/minimal.vim67
2 files changed, 130 insertions, 9 deletions
diff --git a/scripts/ci/install_treesitter_parsers.lua b/scripts/ci/install_treesitter_parsers.lua
new file mode 100644
index 0000000..6393fd8
--- /dev/null
+++ b/scripts/ci/install_treesitter_parsers.lua
@@ -0,0 +1,72 @@
+local install_dir = vim.fn.stdpath("data") .. "/site"
+local ok_setup, setup_err = pcall(function()
+ require("nvim-treesitter").setup({
+ install_dir = install_dir,
+ })
+end)
+
+if not ok_setup then
+ vim.api.nvim_echo(
+ { { "Error: " .. tostring(setup_err), "ErrorMsg" } },
+ true,
+ {}
+ )
+ vim.cmd("cq")
+end
+
+local ok_install, install_err = pcall(function()
+ require("nvim-treesitter").install({
+ "c",
+ "cpp",
+ "go",
+ "lua",
+ "php",
+ "python",
+ "typescript",
+ "javascript",
+ "java",
+ "ruby",
+ "tsx",
+ "c_sharp",
+ "vue",
+ }):wait(300000)
+end)
+
+if not ok_install then
+ vim.api.nvim_echo({
+ { "Error: " .. tostring(install_err), "ErrorMsg" },
+ }, true, {})
+ vim.cmd("cq")
+end
+
+local required_parsers = {
+ c = "c.so",
+ cpp = "cpp.so",
+ go = "go.so",
+ lua = "lua.so",
+ php = "php.so",
+ python = "python.so",
+ typescript = "typescript.so",
+ javascript = "javascript.so",
+ java = "java.so",
+ ruby = "ruby.so",
+ tsx = "tsx.so",
+ c_sharp = "c_sharp.so",
+ vue = "vue.so",
+}
+
+for lang, filename in pairs(required_parsers) do
+ local parser_path = install_dir .. "/parser/" .. filename
+ if not vim.uv.fs_stat(parser_path) then
+ vim.api.nvim_echo({
+ {
+ "Error: "
+ .. lang
+ .. " parser missing after install: "
+ .. parser_path,
+ "ErrorMsg",
+ },
+ }, true, {})
+ vim.cmd("cq")
+ end
+end
diff --git a/scripts/tests/minimal.vim b/scripts/tests/minimal.vim
index c267d9e..30093ba 100644
--- a/scripts/tests/minimal.vim
+++ b/scripts/tests/minimal.vim
@@ -21,18 +21,67 @@ runtime! plugin/plenary.vim
runtime! plugin/nvim-treesitter.lua
lua <<EOF
-local required_parsers = {
- 'c', 'cpp', 'go', 'lua', 'php', 'python', 'typescript', 'javascript', 'java', 'ruby', 'tsx', 'c_sharp', 'vue', 'elixir'
+vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site')
+
+-- parsers to attempt to install (for user convenience)
+local all_parsers = {
+ 'c', 'cpp', 'go', 'lua', 'php', 'python', 'typescript',
+ 'javascript', 'java', 'ruby', 'tsx', 'c_sharp', 'vue', 'elixir'
}
-local installed_parsers = require'nvim-treesitter.info'.installed_parsers()
-local to_install = vim.tbl_filter(function(parser)
- return not vim.tbl_contains(installed_parsers, parser)
-end, required_parsers)
-if #to_install > 0 then
+
+-- parsers actually required for tests to run
+local required_parsers = { 'lua', 'typescript' }
+
+local function missing_parsers(parsers)
+ local missing = {}
+ local buf = vim.api.nvim_create_buf(false, true)
+ for _, lang in ipairs(parsers) do
+ local ok = pcall(vim.treesitter.get_parser, buf, lang)
+ if not ok then
+ table.insert(missing, lang)
+ end
+ end
+ vim.api.nvim_buf_delete(buf, { force = true })
+ return missing
+end
+
+local function install_with_main_branch_api(parsers)
+ local install_dir = vim.fn.stdpath('data') .. '/site'
+ require('nvim-treesitter').setup({ install_dir = install_dir })
+ require('nvim-treesitter').install(parsers):wait(300000)
+end
+
+-- master branch is deprecated but still widely used
+local function install_with_master_branch_api(parsers)
-- fixes 'pos_delta >= 0' error - https://github.com/nvim-lua/plenary.nvim/issues/52
vim.cmd('set display=lastline')
-- make "TSInstall*" available
- vim.cmd 'runtime! plugin/nvim-treesitter.vim'
- vim.cmd('TSInstallSync ' .. table.concat(to_install, ' '))
+ vim.cmd('runtime! plugin/nvim-treesitter.vim')
+ vim.cmd('TSInstallSync ' .. table.concat(parsers, ' '))
+end
+
+local to_install = missing_parsers(all_parsers)
+if #to_install > 0 then
+ -- Detect which nvim-treesitter API is available (main vs master branch)
+ local has_main_api, ts = pcall(require, 'nvim-treesitter')
+ has_main_api = has_main_api and type(ts.install) == 'function'
+
+ if has_main_api then
+ local ok, err = pcall(install_with_main_branch_api, to_install)
+ if not ok then
+ print('Tree-sitter install error (main API): ' .. tostring(err))
+ end
+ else
+ local ok, err = pcall(install_with_master_branch_api, to_install)
+ if not ok then
+ print('Tree-sitter install error (master API): ' .. tostring(err))
+ end
+ end
+end
+
+-- only error if required parsers are still missing
+local still_missing = missing_parsers(required_parsers)
+if #still_missing > 0 then
+ error('Missing required Tree-sitter parsers: ' .. table.concat(still_missing, ', '))
end
EOF