fix(scope): use rawequal to check if scope impl is treesitter. Closes #1413

This commit is contained in:
Folke Lemaitre 2025-02-25 10:48:03 +01:00
parent 338eed18ac
commit 4ce197bff9
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -409,7 +409,7 @@ end
function TSScope:init(cb, opts)
local parser = self:parser(opts)
if not parser then
return
return cb()
end
if M.TS_ASYNC then
parser:parse(opts.treesitter.injections, cb)
@ -486,7 +486,7 @@ end
function Scope:__tostring()
local meta = getmetatable(self)
return ("%s(buf=%d, from=%d, to=%d, indent=%d)"):format(
meta == TSScope and "TSScope" or meta == IndentScope and "IndentSCope" or "Scope",
rawequal(meta, TSScope) and "TSScope" or rawequal(meta, IndentScope) and "IndentSCope" or "Scope",
self.buf or -1,
self.from or -1,
self.to or -1,
@ -513,8 +513,8 @@ function M.get(cb, opts)
end
---@type snacks.scope.Scope
local Class = opts.treesitter.enabled and TSScope.has_ts(opts.buf) and TSScope or IndentScope
if Class == TSScope and opts.parse ~= false then
local Class = (opts.treesitter.enabled and TSScope.has_ts(opts.buf)) and TSScope or IndentScope
if rawequal(Class, TSScope) and opts.parse ~= false then
TSScope:init(function()
opts.parse = false
M.get(cb, opts)
@ -524,7 +524,7 @@ function M.get(cb, opts)
local scope = Class:find(opts) --[[ @as snacks.scope.Scope? ]]
-- fallback to indent based detection
if not scope and Class == TSScope then
if not scope and rawequal(Class, TSScope) then
Class = IndentScope
scope = Class:find(opts)
end