diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bb529ec..3edccdf7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,8 +51,7 @@ jobs: fail-fast: false matrix: neovim_version: - - 'v0.9.5' - - 'v0.10.2' + - 'v0.11.1' env: NVIM_TEST_VERSION: ${{ matrix.neovim_version }} diff --git a/Makefile b/Makefile index 8516651d..65f75b90 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ export XDG_DATA_HOME ?= $(HOME)/.data # nvim-treesitter # ------------------------------------------------------------------------------ -NVIM_TS_SHA ?= 2cade9e +NVIM_TS_SHA ?= 61b0a05e NVIM_TS := deps/nvim-treesitter .PHONY: nvim-treesitter @@ -24,8 +24,8 @@ $(NVIM_TS): FILTER=.* -export NVIM_TEST_VERSION ?= v0.10.2 -export NVIM_RUNNER_VERSION ?= v0.10.2 +export NVIM_TEST_VERSION ?= v0.11.1 +export NVIM_RUNNER_VERSION ?= v0.11.1 NVIM_TEST := deps/nvim-test NVIM_TEST_REV = v1.1.0 @@ -52,7 +52,7 @@ test: $(NVIM_TEST) $(NVIM_TS) .PHONY: parsers parsers: $(NVIM_TEST) $(NVIM_TS) $(XDG_DATA_HOME)/nvim-test/nvim-runner-$(NVIM_RUNNER_VERSION)/bin/nvim \ - --clean -u NONE -c 'source install_parsers.lua' + -l test/helpers.lua install lint: luacheck lua diff --git a/README.md b/README.md index 8ae673d9..59fe0eec 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Note: support for specific languages is strictly community maintained and can br
Supported (click to expand) - for l in f:lines() do - --- @type string? - local lang = l:match('%- %[x%] `([^`]+)`') - if lang then - readme_langs[lang] = true - end - end - f:close() - - f = assert(io.open('deps/nvim-treesitter/lockfile.json', 'r')) - local txt = f:read('*a') - local j = vim.json.decode(txt) - - local langs = {} --- @type string[] - for k in pairs(j) do - if readme_langs[k] then - langs[#langs+1] = k - readme_langs[k] = nil - end - end - print('Invalid languages:', table.concat(vim.tbl_keys(readme_langs), ', ')) - return langs -end - -vim.cmd [[set runtimepath+=.,./deps/nvim-treesitter]] -require'nvim-treesitter.install'.prefer_git = false -require("nvim-treesitter").setup() -require'nvim-treesitter.install'.ensure_installed_sync(get_langs()) -vim.cmd.quit() diff --git a/queries/norg/context.scm b/queries/norg/context.scm deleted file mode 100644 index f6ac284a..00000000 --- a/queries/norg/context.scm +++ /dev/null @@ -1,7 +0,0 @@ -([ - (heading1) - (heading2) - (heading3) - (heading4) - (heading5) -] @context) diff --git a/queries/org/context.scm b/queries/org/context.scm deleted file mode 100644 index c810c67b..00000000 --- a/queries/org/context.scm +++ /dev/null @@ -1,3 +0,0 @@ -(section - body: (_) @context.end -) @context diff --git a/queries/tcl/context.scm b/queries/tcl/context.scm index b70be88a..321f9c7e 100644 --- a/queries/tcl/context.scm +++ b/queries/tcl/context.scm @@ -1,4 +1,6 @@ (procedure) @context (while) @context -(conditional) @context +(if) @context +(else) @context +(elseif) @context (command) @context diff --git a/test/contexts_spec.lua b/test/contexts_spec.lua index c1a5c71d..0a580c33 100644 --- a/test/contexts_spec.lua +++ b/test/contexts_spec.lua @@ -1,5 +1,4 @@ local helpers = require('nvim-test.helpers') -local clear = helpers.clear local exec_lua = helpers.exec_lua local cmd = helpers.api.nvim_command local feed = helpers.feed @@ -71,7 +70,7 @@ local function install_langs_for_file(filename, root_lang) if seen_langs[current_lang] then goto continue end - install_langs(current_lang) + exec_lua(install_langs, current_lang) -- Query for injections in the current language, and queue them for installation. --- @diagnostic disable-next-line: redefined-local Not actually redefining locals @@ -121,28 +120,24 @@ end local lang_to_test_files = {} --- @type table setup(function() - clear() - cmd([[set runtimepath+=.,./deps/nvim-treesitter]]) + helpers.clear() + exec_lua(tc_helpers.setup) - -- Required to load custom predicates - exec_lua([[require'nvim-treesitter'.setup()]]) + exec_lua(install_langs, 'lua') local test_files = fn.globpath('test/lang', '*', true, true) --- @type string[] for _, test_file in ipairs(test_files) do cmd('edit ' .. test_file) local bufnr = api.nvim_get_current_buf() --- @type string - local treesitter_lang = exec_lua( - [[ - local ok, parser = pcall(vim.treesitter.get_parser, ...) - if not ok then - return nil - end - return parser:lang() - ]], - bufnr - ) - if treesitter_lang ~= vim.NIL and treesitter_lang ~= '' then + local treesitter_lang = exec_lua(function(...) + local ok, parser = pcall(vim.treesitter.get_parser, ...) + if not ok then + return nil + end + return parser:lang() + end, bufnr) + if treesitter_lang ~= nil and treesitter_lang ~= '' then if not lang_to_test_files[treesitter_lang] then lang_to_test_files[treesitter_lang] = {} end diff --git a/test/helpers.lua b/test/helpers.lua index 5ba905ac..fed1c5aa 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -1,25 +1,12 @@ -local helpers = require('nvim-test.helpers') -local exec_lua = helpers.exec_lua - local M = {} function M.install_langs(langs) if type(langs) == 'string' then langs = { langs } end - exec_lua( - [[ - local langs = ... - require'nvim-treesitter.configs'.setup { - ensure_installed = langs, - sync_install = true, - } - - -- Clear the message " has been installed". - print(' ') - ]], - langs - ) + require('nvim-treesitter').install(langs):wait() + -- Dirty hack to clear ext_messages + vim.cmd.normal(':') end local langs --- @type string[]? @@ -41,9 +28,10 @@ function M.get_langs() end f:close() - f = assert(io.open('deps/nvim-treesitter/lockfile.json', 'r')) + ---@type table + local parsers = require('deps/nvim-treesitter/lua/nvim-treesitter/parsers') - for k in vim.spairs(vim.json.decode(f:read('*a'))) do + for k in vim.spairs(parsers) do langs[#langs + 1] = k if readme_langs[k] then readme_langs[k] = nil @@ -55,4 +43,25 @@ function M.get_langs() return langs end +function M.setup() + -- Do not pull in parsers from /usr/local/share/ as they may + -- be the wrong ABI + vim.opt.runtimepath = { + vim.env.VIMRUNTIME, + '.', + './deps/nvim-treesitter', + } + require('nvim-treesitter').setup({ + install_dir = vim.fs.joinpath('deps', 'nvim-treesitter-data'), + }) + + vim.env.XDG_CACHE_HOME = 'scratch/cache' + vim.opt.packpath = '' +end + +if arg[0] == 'test/helpers.lua' and arg[1] == 'install' then + M.setup() + M.install_langs(M.get_langs()) +end + return M diff --git a/test/queries_spec.lua b/test/queries_spec.lua index ff076222..45a9d7b1 100644 --- a/test/queries_spec.lua +++ b/test/queries_spec.lua @@ -1,8 +1,6 @@ --- Test the query for each language is valid and update the README. local helpers = require('nvim-test.helpers') -local clear = helpers.clear local exec_lua = helpers.exec_lua -local cmd = helpers.api.nvim_command local tc_helpers = require('test.helpers') local install_langs = tc_helpers.install_langs @@ -12,11 +10,8 @@ describe('query:', function() local readme_lines = {} --- @type string[] setup(function() - clear() - cmd([[set runtimepath+=.,./deps/nvim-treesitter]]) - -- Required to load custom predicates - exec_lua([[require'nvim-treesitter'.setup()]]) - cmd([[let $XDG_CACHE_HOME='scratch/cache']]) + helpers.clear() + exec_lua(tc_helpers.setup) local f = assert(io.open('README.md', 'r')) for l in f:lines() do @@ -56,7 +51,7 @@ describe('query:', function() table.insert(readme_lines, last_lang_index, (' - [ ] `%s`'):format(lang)) pending('no queries/' .. lang .. '/context.scm') else - install_langs(lang) + exec_lua(install_langs, lang) local ok = exec_lua([[return pcall(vim.treesitter.query.get, ...)]], lang, 'context') table.insert( readme_lines, diff --git a/test/ts_context_spec.lua b/test/ts_context_spec.lua index 99e66c8d..587ae339 100644 --- a/test/ts_context_spec.lua +++ b/test/ts_context_spec.lua @@ -1,4 +1,5 @@ local helpers = require('nvim-test.helpers') +local tc_helpers = require('test.helpers') local Screen = require('nvim-test.screen') local install_langs = require('test.helpers').install_langs @@ -7,21 +8,19 @@ local clear = helpers.clear local exec_lua = helpers.exec_lua local cmd = helpers.api.nvim_command local feed = helpers.feed -local fn = helpers.fn - -local function requires_nvim10() - if fn.has('nvim-0.10') == 0 then - pending('Requires nvim-0.10') - end -end describe('ts_context', function() local screen --- @type test.screen before_each(function() clear() + exec_lua(tc_helpers.setup) screen = Screen.new(30, 16) - screen:attach() + + -- Need ext_messages as nvim-treesitter parser installation + -- uses nvim_echo which can cause press enter prompts and thus blocks + screen:attach({ ext_messages = true }) + local default_attrs = { [1] = { foreground = Screen.colors.Brown, @@ -51,25 +50,10 @@ describe('ts_context', function() [18] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.Blue }, } - -- Use the classic vim colorscheme, not the new defaults in nvim >= 0.10 - if fn.has('nvim-0.10') > 0 then - cmd('colorscheme vim') - else - cmd('hi link @variable.builtin Special') - cmd('hi link @type.builtin Special') - cmd('hi link @keyword.type Type') - cmd('hi link @attribute PreProc') - end + cmd('colorscheme vim') screen:set_default_attr_ids(default_attrs) - cmd([[set runtimepath+=.,./deps/nvim-treesitter]]) - - -- Required to load custom predicates - exec_lua([[require'nvim-treesitter'.setup()]]) - - cmd([[let $XDG_CACHE_HOME='scratch/cache']]) - cmd([[set packpath=]]) cmd('syntax enable') end) @@ -78,7 +62,7 @@ describe('ts_context', function() end) it('edit a file', function() - install_langs('lua') + exec_lua(install_langs, 'lua') exec_lua([[require'treesitter-context'.setup{}]]) cmd('edit test/test_file.lua') exec_lua([[vim.treesitter.start()]]) @@ -98,8 +82,7 @@ describe('ts_context', function() {4:end} | | {4:end} | - {6:~ }| - | + {6:~ }|*2 ]], }) @@ -117,8 +100,7 @@ describe('ts_context', function() {4:end} | | {4:end} | - {6:~ }|*3 - | + {6:~ }|*4 ]], }) end) @@ -133,7 +115,7 @@ describe('ts_context', function() end) it('rust', function() - install_langs('rust') + exec_lua(install_langs, 'rust') cmd('edit test/snapshots/snapshot.rs') exec_lua([[vim.treesitter.start()]]) feed('20') @@ -183,9 +165,7 @@ describe('ts_context', function() end) it('c', function() - requires_nvim10() - - install_langs('c') + exec_lua(install_langs, 'c') cmd('edit test/test.c') exec_lua([[vim.treesitter.start()]]) feed('') @@ -205,8 +185,7 @@ describe('ts_context', function() {11:E1}{15:,} | {11:E2}{15:,} | {11:E3} | - {8:// comment} | - | + {8:// comment} |*2 ]], }) @@ -245,8 +224,7 @@ describe('ts_context', function() {8:// comment} |*5 | {15:}} {4:while} {15:(}{11:1}{15:);} | - {8:// comment} | - | + {8:// comment} |*2 ]], }) @@ -260,16 +238,13 @@ describe('ts_context', function() {2: }{14:}}{2: }{1:else}{2: }{1:if}{2: }{14:(}{3:arg1}{2: }{1:==}{2: }{10:4}{14:)}{2: }{14:{}{2: }| {2: }{14:}}{2: }{1:else}{2: }{14:{}{2: }| ^ {8:// comment} | - {8:// comment} |*9 - | + {8:// comment} |*10 ]], }) end) it('cpp', function() - requires_nvim10() - - install_langs('cpp') + exec_lua(install_langs, 'cpp') cmd('edit test/snapshots/snapshot.cpp') exec_lua([[vim.treesitter.start()]]) feed('') @@ -281,7 +256,8 @@ describe('ts_context', function() |*3 ^ {8:// cursor position 1} | {15:};} | - |*9 + |*8 + {9:class} {9:Class} {15:{} | ]], }) feed('16') @@ -293,7 +269,8 @@ describe('ts_context', function() |*3 ^ {8:// cursor position 2} | {15:};} | - |*9 + |*8 + {9:typedef} {9:enum} {15:{} | ]], }) @@ -323,7 +300,8 @@ describe('ts_context', function() {15:}} | {15:}} | {15:}} | - |*7 + |*6 + {4:do} {15:{} | ]], }) @@ -339,14 +317,13 @@ describe('ts_context', function() {15:}} | {15:}} {4:while} {15:(}{11:1}{15:);} | {15:}} | - {6:~ }|*6 - | + {6:~ }|*7 ]], }) end) it('php', function() - install_langs('php') + exec_lua(install_langs, 'php') cmd('edit test/snapshots/snapshot.php') exec_lua([[vim.treesitter.start()]]) @@ -368,7 +345,7 @@ describe('ts_context', function() {4:if} {15:(}{5:$indexValue} {4:<} {5:$key}{15:)} {15:{} | {8:// comment} | | - | + {5:$low} {4:=} {5:$index} {4:+} {11:1}{15:;} | ]], }) @@ -390,7 +367,7 @@ describe('ts_context', function() | | | - | + {8:// comment} | ]], }) @@ -413,13 +390,13 @@ describe('ts_context', function() | | | - | + {15:}} | ]], }) end) it('typescript', function() - install_langs('typescript') + exec_lua(install_langs, 'typescript') cmd('edit test/snapshots/snapshot.ts') exec_lua([[vim.treesitter.start()]]) feed('') @@ -452,7 +429,8 @@ describe('ts_context', function() |*4 {15:}} | {15:}} | - |*3 + |*2 + {4:function} {5:wrapInArray}{15:(}{5:obj}{15::} {15:stri}| ]], }) @@ -466,16 +444,13 @@ describe('ts_context', function() {15:}} | {4:return} {5:obj}{15:;} | {15:}} | - {6:~ }|*6 - | + {6:~ }|*7 ]], }) end) it('markdown', function() - requires_nvim10() - - install_langs({ 'markdown', 'markdown_inline', 'html' }) + exec_lua(install_langs, { 'markdown', 'markdown_inline', 'html' }) cmd('edit test/snapshots/snapshot.md') exec_lua([[vim.treesitter.start()]]) @@ -503,20 +478,20 @@ describe('ts_context', function() ^ | |*8 {8: }{4:function}{8: }{5:test}{15:()}{8: }{15:{} | - | + {8: }{4:if}{8: }{5:test}{8: }{4:!=}{8: }{11:""}{8: }{15:{} | ]], }) feed('12') screen:expect({ grid = [[ - {14:}{2: }| - {2: }{14:}{2: }| - {2: }{14: