commit d200ba654a31e1387df5ef5e91c067182cc405d7
parent 95580f31b384fddd162e0e1f6b7ed69b3e483ea1
Author: Christian Clason <c.clason@uni-graz.at>
Date: Thu, 19 May 2022 09:17:10 +0200
Merge pull request #18502 from drybalka/fix-languagetree-contains-description
treesitter: small improvements of languagetree.lua
Diffstat:
2 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
@@ -616,8 +616,6 @@ LanguageTree:children({self}) *LanguageTree:children()*
LanguageTree:contains({self}, {range}) *LanguageTree:contains()*
Determines whether {range} is contained in this language tree
- This goes down the tree to recursively check children.
-
Parameters: ~
{range} A range, that is a `{ start_line, start_col,
end_line, end_col }` table.
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
@@ -519,17 +519,11 @@ local function tree_contains(tree, range)
local start_fits = start_row < range[1] or (start_row == range[1] and start_col <= range[2])
local end_fits = end_row > range[3] or (end_row == range[3] and end_col >= range[4])
- if start_fits and end_fits then
- return true
- end
-
- return false
+ return start_fits and end_fits
end
--- Determines whether {range} is contained in this language tree
---
---- This goes down the tree to recursively check children.
----
---@param range A range, that is a `{ start_line, start_col, end_line, end_col }` table.
function LanguageTree:contains(range)
for _, tree in pairs(self._trees) do