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()
|
vim.keymap.set("n", "<leader>gg", function()
|
||||||
require("git.status_win").toggle()
|
require("git.sidebar").toggle()
|
||||||
end, { desc = "Toggle git status sidebar" })
|
end, { desc = "Toggle git status sidebar" })
|
||||||
vim.keymap.set("n", "<leader>gl", function()
|
vim.keymap.set("n", "<leader>gl", function()
|
||||||
require("git.log_win").show()
|
require("git.log_win").show()
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ local SIDEBAR_WIDTH = 50
|
|||||||
---@field sha string
|
---@field sha string
|
||||||
---@field subject 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 gitdir string
|
||||||
---@field worktree string
|
---@field worktree string
|
||||||
---@field lines table<integer, ow.Git.StatusEntry>
|
---@field lines table<integer, ow.Git.SidebarEntry>
|
||||||
---@field sidebar_win integer?
|
---@field sidebar_win integer?
|
||||||
---@field diff_left_win integer?
|
---@field diff_left_win integer?
|
||||||
---@field diff_right_win integer?
|
---@field diff_right_win integer?
|
||||||
@@ -40,21 +40,20 @@ local SIDEBAR_WIDTH = 50
|
|||||||
---@field last_shown_key string?
|
---@field last_shown_key string?
|
||||||
---@field last_render_key string? fingerprint of the last rendered state
|
---@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 state = {}
|
||||||
|
|
||||||
local group =
|
local group = vim.api.nvim_create_augroup("ow.git.sidebar", { clear = false })
|
||||||
vim.api.nvim_create_augroup("ow.git.status_win", { clear = false })
|
local ns = vim.api.nvim_create_namespace("ow.git.sidebar")
|
||||||
local ns = vim.api.nvim_create_namespace("ow.git.status_win")
|
|
||||||
|
|
||||||
---Find the sidebar window in the current tabpage by filetype. Used as a
|
---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? win
|
||||||
---@return integer? bufnr
|
---@return integer? bufnr
|
||||||
local function find_sidebar()
|
local function find_sidebar()
|
||||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||||
local buf = vim.api.nvim_win_get_buf(win)
|
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
|
return win, buf
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -62,7 +61,7 @@ end
|
|||||||
|
|
||||||
---Return the sidebar window stashed on `s`, validating that it's still
|
---Return the sidebar window stashed on `s`, validating that it's still
|
||||||
---live. Falls back to `find_sidebar` if the stashed handle is gone.
|
---live. Falls back to `find_sidebar` if the stashed handle is gone.
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@return integer?
|
---@return integer?
|
||||||
local function sidebar_win_for(s)
|
local function sidebar_win_for(s)
|
||||||
local win = s.sidebar_win
|
local win = s.sidebar_win
|
||||||
@@ -74,7 +73,7 @@ local function sidebar_win_for(s)
|
|||||||
return win
|
return win
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entry ow.Git.StatusEntry
|
---@param entry ow.Git.SidebarEntry
|
||||||
---@return string?
|
---@return string?
|
||||||
local function entry_code(entry)
|
local function entry_code(entry)
|
||||||
if entry.section == "Untracked" then
|
if entry.section == "Untracked" then
|
||||||
@@ -88,7 +87,7 @@ local function entry_code(entry)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entry ow.Git.StatusEntry
|
---@param entry ow.Git.SidebarEntry
|
||||||
---@return string? line
|
---@return string? line
|
||||||
---@return string? hl_group
|
---@return string? hl_group
|
||||||
---@return integer? hl_len byte length of the symbol portion at column 2
|
---@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
|
---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.
|
---filled in by a follow-up `git log` once we know the upstream is set.
|
||||||
---@param stdout string
|
---@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 function parse_porcelain(stdout)
|
||||||
local branch = { ahead = 0, behind = 0 }
|
local branch = { ahead = 0, behind = 0 }
|
||||||
local groups = {
|
local groups = {
|
||||||
@@ -219,8 +218,8 @@ end
|
|||||||
---there's nothing to fetch).
|
---there's nothing to fetch).
|
||||||
---@param worktree string
|
---@param worktree string
|
||||||
---@param branch ow.Git.BranchInfo
|
---@param branch ow.Git.BranchInfo
|
||||||
---@param 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.StatusEntry[]>)
|
---@param callback fun(branch: ow.Git.BranchInfo, groups: table<string, ow.Git.SidebarEntry[]>)
|
||||||
local function enrich_with_log(worktree, branch, groups, callback)
|
local function enrich_with_log(worktree, branch, groups, callback)
|
||||||
local fetches = {}
|
local fetches = {}
|
||||||
if branch.upstream and branch.ahead > 0 then
|
if branch.upstream and branch.ahead > 0 then
|
||||||
@@ -283,7 +282,7 @@ end
|
|||||||
---we skip the duplicate subprocess. Otherwise the sidebar fetches its own.
|
---we skip the duplicate subprocess. Otherwise the sidebar fetches its own.
|
||||||
---@param worktree string
|
---@param worktree string
|
||||||
---@param prefetched_stdout 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)
|
local function fetch_status(worktree, prefetched_stdout, callback)
|
||||||
if prefetched_stdout then
|
if prefetched_stdout then
|
||||||
local branch, groups = parse_porcelain(prefetched_stdout)
|
local branch, groups = parse_porcelain(prefetched_stdout)
|
||||||
@@ -323,7 +322,7 @@ end
|
|||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param branch ow.Git.BranchInfo
|
---@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 function render(bufnr, branch, groups)
|
||||||
local lines = { "Head: " .. (branch.head or "?") }
|
local lines = { "Head: " .. (branch.head or "?") }
|
||||||
if branch.upstream then
|
if branch.upstream then
|
||||||
@@ -380,7 +379,7 @@ end
|
|||||||
---short-circuit when the porcelain state is byte-identical to the last
|
---short-circuit when the porcelain state is byte-identical to the last
|
||||||
---successful render.
|
---successful render.
|
||||||
---@param branch ow.Git.BranchInfo
|
---@param branch ow.Git.BranchInfo
|
||||||
---@param groups table<string, ow.Git.StatusEntry[]>
|
---@param groups table<string, ow.Git.SidebarEntry[]>
|
||||||
---@return string
|
---@return string
|
||||||
local function fingerprint(branch, groups)
|
local function fingerprint(branch, groups)
|
||||||
local parts = {
|
local parts = {
|
||||||
@@ -463,8 +462,8 @@ local function refresh(bufnr, prefetched_stdout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@return ow.Git.StatusState?
|
---@return ow.Git.SidebarState?
|
||||||
---@return ow.Git.StatusEntry?
|
---@return ow.Git.SidebarEntry?
|
||||||
local function current_entry(bufnr)
|
local function current_entry(bufnr)
|
||||||
local s = state[bufnr]
|
local s = state[bufnr]
|
||||||
if not s then
|
if not s then
|
||||||
@@ -514,7 +513,7 @@ local function worktree_empty_pane(path)
|
|||||||
return { buf = diff.empty_buf(), name = "git://worktree/" .. path }
|
return { buf = diff.empty_buf(), name = "git://worktree/" .. path }
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@param entry ow.Git.FileEntry
|
---@param entry ow.Git.FileEntry
|
||||||
---@return ow.Git.DiffSide
|
---@return ow.Git.DiffSide
|
||||||
local function index_pane(s, entry)
|
local function index_pane(s, entry)
|
||||||
@@ -529,7 +528,7 @@ local function index_pane(s, entry)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@param entry ow.Git.FileEntry
|
---@param entry ow.Git.FileEntry
|
||||||
---@return ow.Git.DiffSide?
|
---@return ow.Git.DiffSide?
|
||||||
local function other_pane(s, entry)
|
local function other_pane(s, entry)
|
||||||
@@ -556,7 +555,7 @@ local function other_pane(s, entry)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@param entry ow.Git.FileEntry
|
---@param entry ow.Git.FileEntry
|
||||||
---@return ow.Git.DiffPair?
|
---@return ow.Git.DiffPair?
|
||||||
local function compute_pair(s, entry)
|
local function compute_pair(s, entry)
|
||||||
@@ -610,7 +609,7 @@ local function set_diff(win, enabled)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@param sidebar_win integer
|
---@param sidebar_win integer
|
||||||
---@return integer? left
|
---@return integer? left
|
||||||
---@return integer? right
|
---@return integer? right
|
||||||
@@ -660,8 +659,8 @@ local function vsplit_at(target_win, dir)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param s ow.Git.StatusState
|
---@param s ow.Git.SidebarState
|
||||||
---@param entry ow.Git.StatusEntry
|
---@param entry ow.Git.SidebarEntry
|
||||||
---@param focus_left boolean
|
---@param focus_left boolean
|
||||||
local function show_diff(s, entry, focus_left)
|
local function show_diff(s, entry, focus_left)
|
||||||
if not entry.path then
|
if not entry.path then
|
||||||
@@ -883,7 +882,7 @@ local function open(worktree)
|
|||||||
|
|
||||||
local previous_win = vim.api.nvim_get_current_win()
|
local previous_win = vim.api.nvim_get_current_win()
|
||||||
local bufnr, win = git.new_scratch({ split = "left", bufhidden = "wipe" })
|
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].number = false
|
||||||
vim.wo[win].relativenumber = false
|
vim.wo[win].relativenumber = false
|
||||||
+34
-34
@@ -2,43 +2,43 @@ if exists("b:current_syntax")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syntax match gitstatusLabel /\v^(Head|Push)\ze:/
|
syntax match gitsidebarLabel /\v^(Head|Push)\ze:/
|
||||||
syntax match gitstatusBranch /\v(^(Head|Push):\s+)@<=\S+/
|
syntax match gitsidebarBranch /\v(^(Head|Push):\s+)@<=\S+/
|
||||||
syntax match gitstatusAhead /\v\+\d+/
|
syntax match gitsidebarAhead /\v\+\d+/
|
||||||
syntax match gitstatusBehind /\v-\d+/
|
syntax match gitsidebarBehind /\v-\d+/
|
||||||
|
|
||||||
syntax region gitstatusUntrackedHeader start=/\v^Untracked>/ end=/\v^$/
|
syntax region gitsidebarUntrackedHeader start=/\v^Untracked>/ end=/\v^$/
|
||||||
syntax region gitstatusUnstagedHeader start=/\v^Unstaged>/ end=/\v^$/
|
syntax region gitsidebarUnstagedHeader start=/\v^Unstaged>/ end=/\v^$/
|
||||||
syntax region gitstatusStagedHeader start=/\v^Staged>/ end=/\v^$/
|
syntax region gitsidebarStagedHeader start=/\v^Staged>/ end=/\v^$/
|
||||||
syntax region gitstatusUnmergedHeader start=/\v^Unmerged>/ end=/\v^$/
|
syntax region gitsidebarUnmergedHeader start=/\v^Unmerged>/ end=/\v^$/
|
||||||
syntax region gitstatusUnpushedHeader start=/\v^Unpushed>/ end=/\v^$/
|
syntax region gitsidebarUnpushedHeader start=/\v^Unpushed>/ end=/\v^$/
|
||||||
syntax region gitstatusUnpulledHeader start=/\v^Unpulled>/ end=/\v^$/
|
syntax region gitsidebarUnpulledHeader start=/\v^Unpulled>/ end=/\v^$/
|
||||||
|
|
||||||
syntax match gitstatusUntrackedLabel /\v^Untracked/ contained containedin=gitstatusUntrackedHeader
|
syntax match gitsidebarUntrackedLabel /\v^Untracked/ contained containedin=gitsidebarUntrackedHeader
|
||||||
syntax match gitstatusUnstagedLabel /\v^Unstaged/ contained containedin=gitstatusUnstagedHeader
|
syntax match gitsidebarUnstagedLabel /\v^Unstaged/ contained containedin=gitsidebarUnstagedHeader
|
||||||
syntax match gitstatusStagedLabel /\v^Staged/ contained containedin=gitstatusStagedHeader
|
syntax match gitsidebarStagedLabel /\v^Staged/ contained containedin=gitsidebarStagedHeader
|
||||||
syntax match gitstatusUnmergedLabel /\v^Unmerged/ contained containedin=gitstatusUnmergedHeader
|
syntax match gitsidebarUnmergedLabel /\v^Unmerged/ contained containedin=gitsidebarUnmergedHeader
|
||||||
syntax match gitstatusUnpushedLabel /\v^Unpushed/ contained containedin=gitstatusUnpushedHeader
|
syntax match gitsidebarUnpushedLabel /\v^Unpushed/ contained containedin=gitsidebarUnpushedHeader
|
||||||
syntax match gitstatusUnpulledLabel /\v^Unpulled/ contained containedin=gitstatusUnpulledHeader
|
syntax match gitsidebarUnpulledLabel /\v^Unpulled/ contained containedin=gitsidebarUnpulledHeader
|
||||||
|
|
||||||
syntax match gitstatusHeaderCount /\v\(\zs\d+\ze\)/ contained containedin=gitstatusUntrackedHeader,
|
syntax match gitsidebarHeaderCount /\v\(\zs\d+\ze\)/ contained containedin=gitsidebarUntrackedHeader,
|
||||||
\ gitstatusUnstagedHeader,
|
\ gitsidebarUnstagedHeader,
|
||||||
\ gitstatusStagedHeader,
|
\ gitsidebarStagedHeader,
|
||||||
\ gitstatusUnmergedHeader,
|
\ gitsidebarUnmergedHeader,
|
||||||
\ gitstatusUnpushedHeader,
|
\ gitsidebarUnpushedHeader,
|
||||||
\ gitstatusUnpulledHeader
|
\ gitsidebarUnpulledHeader
|
||||||
|
|
||||||
highlight default link gitstatusLabel Label
|
highlight default link gitsidebarLabel Label
|
||||||
highlight default link gitstatusBranch None
|
highlight default link gitsidebarBranch None
|
||||||
highlight default link gitstatusAhead GitUnpushed
|
highlight default link gitsidebarAhead GitUnpushed
|
||||||
highlight default link gitstatusBehind GitUnpulled
|
highlight default link gitsidebarBehind GitUnpulled
|
||||||
highlight default link gitstatusHeaderCount Number
|
highlight default link gitsidebarHeaderCount Number
|
||||||
|
|
||||||
highlight default link gitstatusUntrackedLabel gitstatusLabel
|
highlight default link gitsidebarUntrackedLabel gitsidebarLabel
|
||||||
highlight default link gitstatusUnstagedLabel gitstatusLabel
|
highlight default link gitsidebarUnstagedLabel gitsidebarLabel
|
||||||
highlight default link gitstatusStagedLabel gitstatusLabel
|
highlight default link gitsidebarStagedLabel gitsidebarLabel
|
||||||
highlight default link gitstatusUnmergedLabel gitstatusLabel
|
highlight default link gitsidebarUnmergedLabel gitsidebarLabel
|
||||||
highlight default link gitstatusUnpushedLabel gitstatusLabel
|
highlight default link gitsidebarUnpushedLabel gitsidebarLabel
|
||||||
highlight default link gitstatusUnpulledLabel gitstatusLabel
|
highlight default link gitsidebarUnpulledLabel gitsidebarLabel
|
||||||
|
|
||||||
let b:current_syntax = "gitstatus"
|
let b:current_syntax = "gitsidebar"
|
||||||
|
|||||||
Reference in New Issue
Block a user