fix(scope): possible loop? See #278

This commit is contained in:
Folke Lemaitre 2024-12-13 15:43:55 +01:00
parent ef114c0efe
commit ac6a74823b
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -394,6 +394,8 @@ function M.get(opts)
ret = Class:find(opts)
end
-- when end_pos is provided, get its scope and expand the current scope
-- to include it.
if ret and opts.end_pos and false then
local end_scope = M.get(vim.tbl_extend("keep", { pos = opts.end_pos, end_pos = false }, opts))
if end_scope and end_scope.from < ret.from then
@ -435,7 +437,7 @@ function M.get(opts)
prev_s = prev_s and prev_s:size() == 1 and prev_s
next_s = next_s and next_s:size() == 1 and next_s
local s = prev_dist < next_dist and prev_s or next_s or prev_s
if s then
if s and (s.from < ret.from or s.to > ret.to) then
ret = Scope.with(ret, { from = math.min(ret.from, s.from), to = math.max(ret.to, s.to) })
else
break