Something went wrong. Try again.
jujutsu file annotations for neovim (like blame)
Something went wrong. Try again.
1.8 kB · 58 lines
Lua
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859---@class jjannotate.Cache---@field wins table<integer, jjannotate.Window?> win id -> Window---@field win_by_revision table<string, table<string, table<string, jjannotate.Window?>>> root -> path -> change id -> Windowlocal Cache = {}Cache.__index = Cache
---@return jjannotate.Cachefunction Cache.new() ---@type jjannotate.Cache local c = { wins = {}, win_by_revision = {}, } return setmetatable(c, Cache)end
---@param revision jjannotate.RevisionRef---@return jjannotate.Window?function Cache:get_by_revision(revision) return self.win_by_revision[revision.repo] and self.win_by_revision[revision.repo][revision.path] and self.win_by_revision[revision.repo][revision.path][revision.change_id]end
---@param win_id integer---@return jjannotate.Window?function Cache:get_by_id(win_id) return self.wins[win_id] end
---@param revision jjannotate.RevisionRef---@param w jjannotate.Windowfunction Cache:set_win(revision, w) self.wins[w.id] = w if not self.win_by_revision[revision.repo] then self.win_by_revision[revision.repo] = {} end if not self.win_by_revision[revision.repo][revision.path] then self.win_by_revision[revision.repo][revision.path] = {} end self.win_by_revision[revision.repo][revision.path][revision.change_id] = wend
---@param win_id integer---@return booleanfunction Cache:del_win(win_id) local w = self:get_by_id(win_id) if not w then return false end self.wins[win_id] = nil
local repo, path, change_id = w.revision.repo, w.revision.path, w.revision.change_id local by_path = self.win_by_revision[repo][path] by_path[change_id] = nil if vim.tbl_isempty(by_path) then self.win_by_revision[repo][path] = nil if vim.tbl_isempty(self.win_by_revision[repo]) then self.win_by_revision[repo] = nil end end
return trueend
return Cache.new()