From 4ce197bff9cb9b78a0bdcebb6f7ebbf22cd48c6a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Tue, 25 Feb 2025 10:48:03 +0100 Subject: [PATCH] fix(scope): use `rawequal` to check if scope impl is treesitter. Closes #1413 --- lua/snacks/scope.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/snacks/scope.lua b/lua/snacks/scope.lua index fca0cf5a..cd3a4d23 100644 --- a/lua/snacks/scope.lua +++ b/lua/snacks/scope.lua @@ -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