feat(scope): added __tostring for debugging

This commit is contained in:
Folke Lemaitre 2024-12-14 21:43:23 +01:00
parent be2779e942
commit 94e0849c3a
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -115,7 +115,7 @@ Scope.__index = Scope
---@param opts snacks.scope.Opts
---@return T
function Scope:new(scope, opts)
local ret = setmetatable(scope, { __index = self, __eq = self.__eq })
local ret = setmetatable(scope, { __index = self, __eq = self.__eq, __tostring = self.__tostring })
ret.opts = opts
return ret
end
@ -369,6 +369,17 @@ function TSScope:parent()
return parent and parent ~= self.node:tree():root() and self:with({ node = parent }):root() or nil
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",
self.buf or -1,
self.from or -1,
self.to or -1,
self.indent or 0
)
end
---@param opts? snacks.scope.Opts
---@return snacks.scope.Scope?
function M.get(opts)