fix: all broken queries and tests

This commit is contained in:
Lewis Russell 2024-07-02 10:22:03 +01:00
parent 1b9c756c0c
commit a1d11bffa7
7 changed files with 107 additions and 62 deletions

View file

@ -26,7 +26,7 @@ test: nvim-test nvim-treesitter
--runner_version $(NEOVIM_VERSION) \
--target_version $(NEOVIM_VERSION) \
--lpath=$(PWD)/lua/?.lua \
--filter=$(FILTER) \
--filter="$(FILTER)" \
--verbose
.PHONY: parsers

View file

@ -6,8 +6,8 @@
(aggregate_body (_) @context.end)
) @context
(func_declaration
(specified_function_body (block_statement (_) @context.end))
(function_declaration
(function_body (block_statement (_) @context.end))
) @context
(template_declaration
@ -21,35 +21,35 @@
) @context
(enum_declaration
(enum_body (_) @context.end)
(enum_member) @context.end
) @context
(struct_declaration
(aggregate_body (_) @context.end)
) @context
(unit_test
(unittest_declaration
(block_statement (_) @context.end)
) @context
(try_statement
(block_statement (_) @context.end)
body: (scope_statement (_) @context.end)
) @context
(catch
(block_statement (_) @context.end)
(catch_statement
body: (scope_statement (_) @context.end)
) @context
(asm_statement
(asm_instruction_list (_) @context.end)
(asm_inline (_) @context.end)
) @context
(with_statement
(block_statement (_) @context.end)
(scope_statement (_) @context.end)
) @context
(while_statement
(block_statement (_) @context.end)
(scope_statement (_) @context.end)
) @context
(for_statement
@ -57,20 +57,31 @@
) @context
(foreach_statement
(block_statement (_) @context.end)
(scope_statement (_) @context.end)
) @context
(if_statement
(then_statement (
consequence: (scope_statement
(block_statement (_) @context.end)
))
)
) @context
(else_statement
(block_statement (_) @context.end)
) @context
(if_statement
(else) @context
.
(_) @context.end
; (scope_statement
; (block_statement (_) @context.end)
; )
)
(switch_statement
(block_statement (_) @context.end)
(scope_statement (_) @context.end)
) @context
(case_statement
(case)
.
(expression_list) @context.end
) @context

View file

@ -1,31 +1,23 @@
([
(call)
(binary)
(binary_operator)
]) @context
(left_assignment
value: (_) @context.end
) @context
(equals_assignment
value: (_) @context.end
) @context
(super_assignment
value: (_) @context.end
) @context
(for
(for_statement
body: (_) @context.end
) @context
(while
(while_statement
body: (_) @context.end
) @context
(if
(if_statement
consequence: (_) @context.end
) @context
(if_statement
consequence: (_) @context.end
) @context
(function_definition
(brace_list) @context.end) @context
(braced_expression) @context.end) @context

View file

@ -2,10 +2,8 @@
([
(if_statement)
(else_statement)
(else_if_block)
(each_statement)
(await_statement)
(then_statement)
(catch_statement)
(key_statement)
] @context)

View file

@ -144,6 +144,10 @@ class Foo : Bar
case 3: // valid: ends with 'break' (break out of the 'switch' only)
message ~= "three";
break;
case 4: // valid: ends with 'continue' (continue the enclosing loop)

View file

@ -55,7 +55,41 @@
{#if x > 10}
<p>{x} is greater than 10</p>
{:else if 5 > x}
<p>{x} is less than 5</p>
{:else}
<p>{x} is between 5 and 10</p>
{/if}
</div>

View file

@ -6,6 +6,22 @@ local exec_lua = helpers.exec_lua
local cmd = helpers.api.nvim_command
local feed = helpers.feed
local function 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 "<lang> has been installed".
print(' ')
]], langs)
end
local function get_langs()
local f = assert(io.open('README.md', 'r'))
local readme_langs = {} --- @type table<string,true>
@ -35,22 +51,6 @@ end
describe('ts_context', function()
local screen --- @type test.screen
local langs --- @type string[]
setup(function()
clear()
cmd [[set runtimepath+=.,./nvim-treesitter]]
langs = get_langs()
exec_lua([[
local langs = ...
require'nvim-treesitter.configs'.setup {
ensure_installed = langs,
sync_install = true,
}
]], langs)
end)
before_each(function()
clear()
@ -76,11 +76,7 @@ describe('ts_context', function()
cmd [[set runtimepath+=.,./nvim-treesitter]]
exec_lua([[
require'nvim-treesitter.configs'.setup {}
]])
-- Required for the proper Markdown support
-- Required to load custom predicates
exec_lua [[require'nvim-treesitter'.setup()]]
cmd [[let $XDG_CACHE_HOME='scratch/cache']]
@ -93,6 +89,7 @@ describe('ts_context', function()
end)
it('edit a file', function()
install_langs('lua')
exec_lua[[require'treesitter-context'.setup{}]]
cmd('edit test/test_file.lua')
exec_lua [[vim.treesitter.start()]]
@ -144,8 +141,10 @@ describe('ts_context', function()
f:close()
end)
for _, lang in ipairs(langs) do
for _, lang in ipairs(get_langs()) do
it(lang, function()
install_langs(lang)
local index --- @type integer
local line_orig --- @type string
@ -193,6 +192,7 @@ describe('ts_context', function()
end)
it('rust', function()
install_langs('rust')
cmd('edit test/test.rs')
exec_lua [[vim.treesitter.start()]]
feed'20<C-e>'
@ -239,6 +239,7 @@ describe('ts_context', function()
end)
it('c', function()
install_langs('c')
cmd('edit test/test.c')
exec_lua [[vim.treesitter.start()]]
feed'<C-e>'
@ -312,6 +313,7 @@ describe('ts_context', function()
end)
it('cpp', function()
install_langs('cpp')
cmd('edit test/test.cpp')
exec_lua [[vim.treesitter.start()]]
feed'<C-e>'
@ -378,6 +380,7 @@ describe('ts_context', function()
end)
it('php', function()
install_langs('php')
cmd('edit test/test.php')
exec_lua [[vim.treesitter.start()]]
@ -409,7 +412,7 @@ describe('ts_context', function()
|
|
^ {15:#[}ReturnTypeWillChange{15:]} |
{9:public} {4:function} {5:rot}{15:():} {9:voi}|
{4:public} {4:function} {5:rot}{15:():} {9:voi}|
{15:{} |
|
|
@ -425,7 +428,7 @@ describe('ts_context', function()
feed'5<C-e>'
screen:expect{grid=[[
{1:class}{2: }{7:Fruit}{2: }{14:{}{2: }|
{2: }{7:public}{2: }{1:function}{2: }{3:rot}{14:():}{2: }{7:voi}|
{2: }{1:public}{2: }{1:function}{2: }{3:rot}{14:():}{2: }{7:voi}|
{2: }{14:{}{2: }|
|
|
@ -444,6 +447,7 @@ describe('ts_context', function()
end)
it('typescript', function()
install_langs('typescript')
cmd('edit test/test.ts')
exec_lua [[vim.treesitter.start()]]
feed'<C-e>'
@ -491,6 +495,7 @@ describe('ts_context', function()
end)
it('markdown', function()
install_langs({'markdown', 'markdown_inline', 'html'})
cmd('edit test/test.md')
exec_lua [[vim.treesitter.start()]]
@ -532,6 +537,7 @@ describe('ts_context', function()
-- unsupported injected languages (markdown_inline does not
-- have queries specified)
it('markdown_inline', function()
install_langs({'markdown', 'markdown_inline'})
cmd('edit test/test.md')
exec_lua [[vim.treesitter.start()]]