diff options
author | Thomas Vigouroux <thomas.vigouroux@protonmail.com> | 2022-09-10 11:26:23 +0200 |
---|---|---|
committer | Thomas Vigouroux <thomas.vigouroux@protonmail.com> | 2022-09-11 08:16:50 +0200 |
commit | 1939518ebab72878f2a8ca0cb85c09f7e70d1093 (patch) | |
tree | 3162ef57a3b4643876de36ada7cb5796263d2e06 /runtime/lua/vim/treesitter/query.lua | |
parent | 9b4cab012662514af6fda3648d544633e1d73d4b (diff) | |
download | rneovim-1939518ebab72878f2a8ca0cb85c09f7e70d1093.tar.gz rneovim-1939518ebab72878f2a8ca0cb85c09f7e70d1093.tar.bz2 rneovim-1939518ebab72878f2a8ca0cb85c09f7e70d1093.zip |
fix(treesitter): prevent endless loop on self-inheritence
Fixes #20139
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 2f6227af8e..90ed2a357c 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -34,6 +34,18 @@ local function safe_read(filename, read_quantifier) return content end +---@private +--- Adds @p ilang to @p base_langs, only if @p ilang is different than @lang +--- +---@return boolean true it lang == ilang +local function add_included_lang(base_langs, lang, ilang) + if lang == ilang then + return true + end + table.insert(base_langs, ilang) + return false +end + --- Gets the list of files used to make up a query --- ---@param lang The language @@ -84,10 +96,14 @@ function M.get_query_files(lang, query_name, is_included) if is_optional then if not is_included then - table.insert(base_langs, incllang:sub(2, #incllang - 1)) + if add_included_lang(base_langs, lang, incllang:sub(2, #incllang - 1)) then + extension = true + end end else - table.insert(base_langs, incllang) + if add_included_lang(base_langs, lang, incllang) then + extension = true + end end end elseif modeline:match(EXTENDS_FORMAT) then |