Skip to content

Commit d5e775b

Browse files
committed
ci(treesitter): revert tests to tree-sitter master branch
seems like enabling treesitter on the autocmd doesn't seem to work in testing. Need more time to get compatibility
1 parent 2bac23e commit d5e775b

2 files changed

Lines changed: 51 additions & 20 deletions

File tree

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ lint-fix:
2121

2222
# Install all test dependencies
2323
deps: deps/mini.nvim \
24-
deps/nvim-dap \
25-
deps/nvim-dap-python \
26-
deps/nvim-lspconfig \
27-
deps/LuaSnip \
28-
deps/neotest \
29-
deps/neotest-python \
30-
deps/nvim-treesitter
24+
deps/nvim-dap \
25+
deps/nvim-dap-python \
26+
deps/nvim-lspconfig \
27+
deps/LuaSnip \
28+
deps/neotest \
29+
deps/neotest-python \
30+
deps/nvim-treesitter
3131

3232
test_requirements:
3333
for req in "python3" "uv"; do \
@@ -40,7 +40,7 @@ test_requirements:
4040
deps/nvim-treesitter:
4141
set -x
4242
@mkdir -p deps
43-
git clone --filter=blob:none https://github.com/nvim-treesitter/nvim-treesitter $@
43+
git clone --branch master --filter=blob:none https://github.com/nvim-treesitter/nvim-treesitter $@
4444

4545
deps/mini.nvim:
4646
set -x

scripts/minimal_init.lua

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,51 @@ vim.cmd("set rtp+=" .. runtime_path)
1818
require("luasnip").setup()
1919
require("luasnip.extras.fmt")
2020
require("luasnip.nodes.absolute_indexer")
21+
require("nvim-treesitter.locals")
22+
require("nvim-treesitter").setup()
2123
require("mini.test").setup()
2224
require("mini.doc").setup()
25+
require("nvim-treesitter.configs").setup({
26+
modules = {
27+
"highlight",
28+
},
29+
sync_install = false,
30+
auto_install = true,
31+
ignore_install = {},
32+
ensure_installed = {},
33+
highlight = {
34+
enable = true,
35+
},
36+
})
2337

24-
-- Setup nvim-treesitter
25-
require("nvim-treesitter").install("python")
38+
-- Clean path for use in a prefix comparison
39+
---@param input string
40+
---@return string
41+
local function clean_path(input)
42+
local pth = vim.fn.fnamemodify(input, ":p")
43+
if vim.fn.has("win32") == 1 then
44+
pth = pth:gsub("/", "\\")
45+
end
46+
return pth
47+
end
2648

27-
vim.api.nvim_create_autocmd("FileType", {
28-
group = vim.api.nvim_create_augroup("PythonTreesitter", { clear = true }),
29-
pattern = "python",
30-
desc = "Enable treesitter highlighting and indentation",
31-
callback = function(event)
32-
local buf = event.buf
49+
local function ts_is_installed(lang)
50+
local matched_parsers = vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", true) or {}
51+
local configs = require("nvim-treesitter.configs")
52+
local install_dir = configs.get_parser_install_dir()
53+
if not install_dir then
54+
return false
55+
end
56+
install_dir = clean_path(install_dir)
57+
for _, path in ipairs(matched_parsers) do
58+
local abspath = clean_path(path)
59+
if vim.startswith(abspath, install_dir) then
60+
return true
61+
end
62+
end
63+
return false
64+
end
3365

34-
-- Start highlighting
35-
pcall(vim.treesitter.start, buf, "python")
36-
end,
37-
})
66+
if not ts_is_installed("python") then
67+
vim.cmd("TSInstallSync python")
68+
end

0 commit comments

Comments
 (0)