Skip to content

Commit

Permalink
fix: all broken queries and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jul 2, 2024
1 parent 1b9c756 commit a1d11bf
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 28 additions & 17 deletions queries/d/context.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,56 +21,67 @@
) @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
(block_statement (_) @context.end)
) @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

24 changes: 8 additions & 16 deletions queries/r/context.scm
Original file line number Diff line number Diff line change
@@ -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
(for_statement
body: (_) @context.end
) @context

(for
(while_statement
body: (_) @context.end
) @context

(while
body: (_) @context.end
(if_statement
consequence: (_) @context.end
) @context

(if
(if_statement
consequence: (_) @context.end
) @context

(function_definition
(brace_list) @context.end) @context
(braced_expression) @context.end) @context
4 changes: 1 addition & 3 deletions queries/svelte/context.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

([
(if_statement)
(else_statement)
(else_if_block)
(each_statement)
(await_statement)
(then_statement)
(catch_statement)
(key_statement)
] @context)
4 changes: 4 additions & 0 deletions test/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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>
54 changes: 30 additions & 24 deletions test/ts_context_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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()
Expand All @@ -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']]
Expand All @@ -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()]]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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>'
Expand Down Expand Up @@ -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>'
Expand Down Expand Up @@ -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>'
Expand Down Expand Up @@ -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()]]

Expand Down Expand Up @@ -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:{} |
|
|
Expand All @@ -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: }|
|
|
Expand All @@ -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>'
Expand Down Expand Up @@ -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()]]

Expand Down Expand Up @@ -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()]]

Expand Down

0 comments on commit a1d11bf

Please sign in to comment.