fix(git): rename status_win to sidebar
This commit is contained in:
+1
-1
@@ -93,7 +93,7 @@ function M.setup()
|
||||
})
|
||||
|
||||
vim.keymap.set("n", "<leader>gg", function()
|
||||
require("git.status_win").toggle()
|
||||
require("git.sidebar").toggle()
|
||||
end, { desc = "Toggle git status sidebar" })
|
||||
vim.keymap.set("n", "<leader>gl", function()
|
||||
require("git.log_win").show()
|
||||
|
||||
@@ -27,12 +27,12 @@ local SIDEBAR_WIDTH = 50
|
||||
---@field sha string
|
||||
---@field subject string?
|
||||
|
||||
---@alias ow.Git.StatusEntry ow.Git.FileEntry | ow.Git.CommitEntry
|
||||
---@alias ow.Git.SidebarEntry ow.Git.FileEntry | ow.Git.CommitEntry
|
||||
|
||||
---@class ow.Git.StatusState
|
||||
---@class ow.Git.SidebarState
|
||||
---@field gitdir string
|
||||
---@field worktree string
|
||||
---@field lines table<integer, ow.Git.StatusEntry>
|
||||
---@field lines table<integer, ow.Git.SidebarEntry>
|
||||
---@field sidebar_win integer?
|
||||
---@field diff_left_win integer?
|
||||
---@field diff_right_win integer?
|
||||
@@ -40,21 +40,20 @@ local SIDEBAR_WIDTH = 50
|
||||
---@field last_shown_key string?
|
||||
---@field last_render_key string? fingerprint of the last rendered state
|
||||
|
||||
---@type table<integer, ow.Git.StatusState>
|
||||
---@type table<integer, ow.Git.SidebarState>
|
||||
local state = {}
|
||||
|
||||
local group =
|
||||
vim.api.nvim_create_augroup("ow.git.status_win", { clear = false })
|
||||
local ns = vim.api.nvim_create_namespace("ow.git.status_win")
|
||||
local group = vim.api.nvim_create_augroup("ow.git.sidebar", { clear = false })
|
||||
local ns = vim.api.nvim_create_namespace("ow.git.sidebar")
|
||||
|
||||
---Find the sidebar window in the current tabpage by filetype. Used as a
|
||||
---fallback when we don't have a `StatusState` handy (e.g. M.toggle).
|
||||
---fallback when we don't have a `SidebarState` handy (e.g. M.toggle).
|
||||
---@return integer? win
|
||||
---@return integer? bufnr
|
||||
local function find_sidebar()
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.bo[buf].filetype == "gitstatus" then
|
||||
if vim.bo[buf].filetype == "gitsidebar" then
|
||||
return win, buf
|
||||
end
|
||||
end
|
||||
@@ -62,7 +61,7 @@ end
|
||||
|
||||
---Return the sidebar window stashed on `s`, validating that it's still
|
||||
---live. Falls back to `find_sidebar` if the stashed handle is gone.
|
||||
---@param s ow.Git.StatusState
|
||||
---@param s ow.Git.SidebarState
|
||||
---@return integer?
|
||||
local function sidebar_win_for(s)
|
||||
local win = s.sidebar_win
|
||||
@@ -74,7 +73,7 @@ local function sidebar_win_for(s)
|
||||
return win
|
||||
end
|
||||
|
||||
---@param entry ow.Git.StatusEntry
|
||||
---@param entry ow.Git.SidebarEntry
|
||||
---@return string?
|
||||
local function entry_code(entry)
|
||||
if entry.section == "Untracked" then
|
||||
@@ -88,7 +87,7 @@ local function entry_code(entry)
|
||||
end
|
||||
end
|
||||
|
||||
---@param entry ow.Git.StatusEntry
|
||||
---@param entry ow.Git.SidebarEntry
|
||||
---@return string? line
|
||||
---@return string? hl_group
|
||||
---@return integer? hl_len byte length of the symbol portion at column 2
|
||||
@@ -147,7 +146,7 @@ end
|
||||
---pair. `Unpushed` and `Unpulled` start empty here; ahead/behind commits are
|
||||
---filled in by a follow-up `git log` once we know the upstream is set.
|
||||
---@param stdout string
|
||||
---@return ow.Git.BranchInfo, table<string, ow.Git.StatusEntry[]>
|
||||
---@return ow.Git.BranchInfo, table<string, ow.Git.SidebarEntry[]>
|
||||
local function parse_porcelain(stdout)
|
||||
local branch = { ahead = 0, behind = 0 }
|
||||
local groups = {
|
||||
@@ -219,8 +218,8 @@ end
|
||||
---there's nothing to fetch).
|
||||
---@param worktree string
|
||||
---@param branch ow.Git.BranchInfo
|
||||
---@param groups table<string, ow.Git.StatusEntry[]>
|
||||
---@param callback fun(branch: ow.Git.BranchInfo, groups: table<string, ow.Git.StatusEntry[]>)
|
||||
---@param groups table<string, ow.Git.SidebarEntry[]>
|
||||
---@param callback fun(branch: ow.Git.BranchInfo, groups: table<string, ow.Git.SidebarEntry[]>)
|
||||
local function enrich_with_log(worktree, branch, groups, callback)
|
||||
local fetches = {}
|
||||
if branch.upstream and branch.ahead > 0 then
|
||||
@@ -283,7 +282,7 @@ end
|
||||
---we skip the duplicate subprocess. Otherwise the sidebar fetches its own.
|
||||
---@param worktree string
|
||||
---@param prefetched_stdout string?
|
||||
---@param callback fun(branch: ow.Git.BranchInfo, groups: table<string, ow.Git.StatusEntry[]>)
|
||||
---@param callback fun(branch: ow.Git.BranchInfo, groups: table<string, ow.Git.SidebarEntry[]>)
|
||||
local function fetch_status(worktree, prefetched_stdout, callback)
|
||||
if prefetched_stdout then
|
||||
local branch, groups = parse_porcelain(prefetched_stdout)
|
||||
@@ -323,7 +322,7 @@ end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param branch ow.Git.BranchInfo
|
||||
---@param groups table<string, ow.Git.StatusEntry[]>
|
||||
---@param groups table<string, ow.Git.SidebarEntry[]>
|
||||
local function render(bufnr, branch, groups)
|
||||
local lines = { "Head: " .. (branch.head or "?") }
|
||||
if branch.upstream then
|
||||
@@ -380,7 +379,7 @@ end
|
||||
---short-circuit when the porcelain state is byte-identical to the last
|
||||
---successful render.
|
||||
---@param branch ow.Git.BranchInfo
|
||||
---@param groups table<string, ow.Git.StatusEntry[]>
|
||||
---@param groups table<string, ow.Git.SidebarEntry[]>
|
||||
---@return string
|
||||
local function fingerprint(branch, groups)
|
||||
local parts = {
|
||||
@@ -463,8 +462,8 @@ local function refresh(bufnr, prefetched_stdout)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@return ow.Git.StatusState?
|
||||
---@return ow.Git.StatusEntry?
|
||||
---@return ow.Git.SidebarState?
|
||||
---@return ow.Git.SidebarEntry?
|
||||
local function current_entry(bufnr)
|
||||
local s = state[bufnr]
|
||||
if not s then
|
||||
@@ -514,7 +513,7 @@ local function worktree_empty_pane(path)
|
||||
return { buf = diff.empty_buf(), name = "git://worktree/" .. path }
|
||||
end
|
||||
|
||||
---@param s ow.Git.StatusState
|
||||
---@param s ow.Git.SidebarState
|
||||
---@param entry ow.Git.FileEntry
|
||||
---@return ow.Git.DiffSide
|
||||
local function index_pane(s, entry)
|
||||
@@ -529,7 +528,7 @@ local function index_pane(s, entry)
|
||||
}
|
||||
end
|
||||
|
||||
---@param s ow.Git.StatusState
|
||||
---@param s ow.Git.SidebarState
|
||||
---@param entry ow.Git.FileEntry
|
||||
---@return ow.Git.DiffSide?
|
||||
local function other_pane(s, entry)
|
||||
@@ -556,7 +555,7 @@ local function other_pane(s, entry)
|
||||
end
|
||||
end
|
||||
|
||||
---@param s ow.Git.StatusState
|
||||
---@param s ow.Git.SidebarState
|
||||
---@param entry ow.Git.FileEntry
|
||||
---@return ow.Git.DiffPair?
|
||||
local function compute_pair(s, entry)
|
||||
@@ -610,7 +609,7 @@ local function set_diff(win, enabled)
|
||||
end
|
||||
end
|
||||
|
||||
---@param s ow.Git.StatusState
|
||||
---@param s ow.Git.SidebarState
|
||||
---@param sidebar_win integer
|
||||
---@return integer? left
|
||||
---@return integer? right
|
||||
@@ -660,8 +659,8 @@ local function vsplit_at(target_win, dir)
|
||||
)
|
||||
end
|
||||
|
||||
---@param s ow.Git.StatusState
|
||||
---@param entry ow.Git.StatusEntry
|
||||
---@param s ow.Git.SidebarState
|
||||
---@param entry ow.Git.SidebarEntry
|
||||
---@param focus_left boolean
|
||||
local function show_diff(s, entry, focus_left)
|
||||
if not entry.path then
|
||||
@@ -883,7 +882,7 @@ local function open(worktree)
|
||||
|
||||
local previous_win = vim.api.nvim_get_current_win()
|
||||
local bufnr, win = git.new_scratch({ split = "left", bufhidden = "wipe" })
|
||||
vim.bo[bufnr].filetype = "gitstatus"
|
||||
vim.bo[bufnr].filetype = "gitsidebar"
|
||||
|
||||
vim.wo[win].number = false
|
||||
vim.wo[win].relativenumber = false
|
||||
Reference in New Issue
Block a user