Merge pull request #13449 from nvim-treesitter/fix-language-for-range

fix(treesitter): incorrect method name call
This commit is contained in:
Thomas Vigouroux 2020-12-06 23:27:38 +01:00 committed by GitHub
commit 5855a3ea7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -445,7 +445,7 @@ end
function LanguageTree:language_for_range(range)
for _, child in pairs(self._children) do
if child:contains(range) then
return child:node_for_range(range)
return child:language_for_range(range)
end
end

View File

@ -919,4 +919,25 @@ local hl_query = [[
end)
end)
describe("when getting the language for a range", function()
before_each(function()
insert([[
int x = INT_MAX;
#define VALUE 123456789
]])
end)
it("should return the correct language tree", function()
local result = exec_lua([[
parser = vim.treesitter.get_parser(0, "c", {
queries = { c = "(preproc_def (preproc_arg) @c)"}})
local sub_tree = parser:language_for_range({1, 18, 1, 19})
return sub_tree == parser:children().c
]])
eq(result, true)
end)
end)
end)