Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/contexts_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ for _, lang in ipairs(langs_with_queries) do
setup(function()
cmd([[let $XDG_CACHE_HOME='scratch/cache']])
install_langs(lang)
cmd('edit ' .. test_file)
local bufnr = api.nvim_get_current_buf()
exec_lua(
[[
local bufnr, lang = ...
local root_parser = vim.treesitter.get_parser(bufnr, lang)
local line_count = vim.api.nvim_buf_line_count(bufnr)
root_parser:parse({ 0, line_count })
local langs_to_iterate = vim.tbl_keys(root_parser:children())
while #langs_to_iterate > 0 do
local current_lang = table.remove(langs_to_iterate, 1)
require('nvim-treesitter.configs').setup({
ensure_installed = current_lang,
sync_install = true,
})
local ok, current_parser = pcall(vim.treesitter.get_parser, bufnr, current_lang)
if ok then
current_parser:parse({ 0, line_count })
local child_langs = vim.tbl_keys(current_parser:children())
for _, child in ipairs(child_langs) do
table.insert(langs_to_iterate, child)
end
end
end
]],
bufnr,
lang
)
end)

for cursor_row, context_rows in pairs(contexts) do
Expand Down
10 changes: 8 additions & 2 deletions test/lang/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@



color: red; /* BUG: cannot test for injected lang here */
color: red; /* {{CURSOR}} */



Expand Down Expand Up @@ -133,8 +133,14 @@


var b = 2;
function test() {
function test() { // {{CONTEXT}}
let test = "asdasd";





// {{CURSOR}}
}

var c = a + b;
Expand Down
16 changes: 8 additions & 8 deletions test/lang/test.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
```html
<html>
<body>
```html <!-- {{CONTEXT}} -->
<html> <!-- {{CONTEXT}} -->
<body> <!-- {{CONTEXT}} -->






<script>
<script> <!-- {{CONTEXT}} -->



Expand All @@ -20,9 +20,8 @@



function test() {
if test != "" {

function test() { // {{CONTEXT}}
if test != "" { // {{CONTEXT}}



Expand All @@ -37,13 +36,14 @@



// {{CURSOR}}
}
}
</script>
</body>
</html>
```

{{TEST}}
# Title {{CONTEXT}}


Expand Down
Loading