Neovim sign gutter, designed to be mostly VCS agnostic
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Extend state module to include VCS stuff.

+46 -31
+10 -13
lua/vcsigns/actions.lua
··· 30 30 group = group, 31 31 buffer = bufnr, 32 32 callback = function() 33 - if not vim.b[bufnr].vcsigns_detecting then 33 + if not state.get(bufnr).vcs.detecting then 34 34 updates.deep_update(bufnr) 35 35 end 36 36 end, ··· 48 48 group = group, 49 49 buffer = bufnr, 50 50 callback = function() 51 - if not vim.b[bufnr].vcsigns_detecting then 51 + if not state.get(bufnr).vcs.detecting then 52 52 updates.shallow_update(bufnr) 53 53 end 54 54 end, ··· 60 60 ---@param bufnr integer The buffer number. 61 61 function M.start(bufnr) 62 62 -- Clear existing state. 63 - vim.b[bufnr].vcsigns_detecting = nil 64 - vim.b[bufnr].vcsigns_vcs = nil 63 + local s = state.get(bufnr) 64 + s.vcs.detecting = nil 65 + s.vcs.vcs = nil 65 66 66 67 local vcs = repo.detect_vcs(bufnr) 67 - vim.b[bufnr].vcsigns_detecting = false 68 + s.vcs.detecting = false 68 69 if not vcs then 69 70 util.verbose "No VCS detected" 70 71 return 71 72 end 72 73 util.verbose("Detected VCS " .. vcs.name) 73 - vim.b[bufnr].vcsigns_vcs = vcs 74 + s.vcs.vcs = vcs 74 75 75 76 _set_buflocal_autocmds(bufnr) 76 77 end ··· 78 79 --- Start VCSigns for the given buffer, but skip if detection was already done. 79 80 ---@param bufnr integer The buffer number. 80 81 function M.start_if_needed(bufnr) 81 - if vim.b[bufnr].vcsigns_vcs == nil then 82 + if state.get(bufnr).vcs.vcs == nil then 82 83 M.start(bufnr) 83 84 end 84 85 end ··· 94 95 95 96 -- Clear state. 96 97 state.clear(bufnr) 97 - 98 - -- Clear buffer-local variables. 99 - vim.b[bufnr].vcsigns_detecting = nil 100 - vim.b[bufnr].vcsigns_vcs = nil 101 98 end 102 99 103 100 local last_target_notification = nil ··· 148 145 return 149 146 end 150 147 local lnum = vim.fn.line "." 151 - local hunks = state.get(bufnr).hunks 148 + local hunks = state.get(bufnr).diff.hunks 152 149 local hunk = forward and hunkops.next_hunk(lnum, hunks, count) 153 150 or hunkops.prev_hunk(lnum, hunks, count) 154 151 if hunk then ··· 173 170 ---@param range integer[] The range of lines to consider for the hunks. 174 171 ---@return Hunk[] Hunks in the specified range. 175 172 local function _hunks_in_range(bufnr, range) 176 - local hunks = state.get(bufnr).hunks 173 + local hunks = state.get(bufnr).diff.hunks 177 174 ---@type Hunk[] 178 175 local hunks_in_range = {} 179 176 for _, hunk in ipairs(hunks) do
+1 -1
lua/vcsigns/fold.lua
··· 8 8 ---@param lnum integer 9 9 function M.fold_expression(lnum) 10 10 local bufnr = vim.api.nvim_get_current_buf() 11 - local hunks = state.get(bufnr).hunks 11 + local hunks = state.get(bufnr).diff.hunks 12 12 if hunks == nil then 13 13 return 0 14 14 end
+5 -2
lua/vcsigns/info.lua
··· 1 1 local M = {} 2 2 3 + local state = require "vcsigns.state" 4 + 3 5 function M.lualine_module() 4 6 return { 5 7 "diff", ··· 7 9 return vim.b.vcsigns_stats 8 10 end, 9 11 on_click = function() 12 + local bufnr = vim.api.nvim_get_current_buf() 10 13 local lines = {} 11 - lines[#lines + 1] = vim.b.vcsigns_vcs and vim.b.vcsigns_vcs.name 12 - or "No vcs detected" 14 + local vcs = state.get(bufnr).vcs.vcs 15 + lines[#lines + 1] = vcs and vcs.name or "No vcs detected" 13 16 if vim.b.vcsigns_resolved_rename then 14 17 lines[#lines + 1] = "File rename detected:" 15 18 lines[#lines + 1] = string.format(
+20 -6
lua/vcsigns/state.lua
··· 1 1 local M = {} 2 2 3 + ---@class BufferState 4 + ---@field diff DiffState 5 + ---@field vcs VcsState 6 + 3 7 ---@class DiffState 4 8 ---@field hunks Hunk[] 5 9 ---@field old_contents string 6 10 ---@field last_update integer 7 11 ---@field hunks_changedtick integer 8 12 9 - ---@type table<integer, DiffState> 13 + ---@class VcsState 14 + ---@field vcs Vcs|nil 15 + ---@field detecting boolean|nil 16 + 17 + ---@type table<integer, BufferState> 10 18 local buffers = {} 11 19 12 20 ---@param bufnr integer 13 - ---@return DiffState 21 + ---@return BufferState 14 22 function M.get(bufnr) 15 23 if bufnr == 0 then 16 24 bufnr = vim.api.nvim_get_current_buf() 17 25 end 18 26 if not buffers[bufnr] then 19 27 buffers[bufnr] = { 20 - hunks = {}, 21 - old_contents = "", 22 - last_update = 0, 23 - hunks_changedtick = 0, 28 + diff = { 29 + hunks = {}, 30 + old_contents = "", 31 + last_update = 0, 32 + hunks_changedtick = 0, 33 + }, 34 + vcs = { 35 + vcs = nil, 36 + detecting = nil, 37 + }, 24 38 } 25 39 end 26 40 return buffers[bufnr]
+1 -1
lua/vcsigns/textobj.lua
··· 5 5 6 6 function M.select_hunk(bufnr) 7 7 local lnum = vim.fn.line "." 8 - local hunks = state.get(bufnr).hunks 8 + local hunks = state.get(bufnr).diff.hunks 9 9 local hunk = hunkops.cur_hunk(lnum, hunks) 10 10 if not hunk then 11 11 vim.notify(
+9 -8
lua/vcsigns/updates.lua
··· 14 14 local buffer_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) 15 15 local new_contents = table.concat(buffer_lines, "\n") .. "\n" 16 16 local s = state.get(bufnr) 17 - local old_contents = s.old_contents 17 + local old_contents = s.diff.old_contents 18 18 19 19 if not old_contents then 20 20 util.verbose "No old contents available, skipping diff." ··· 40 40 end 41 41 42 42 local hunks = diff.compute_diff(old_contents, new_contents) 43 - s.hunks = hunks 43 + s.diff.hunks = hunks 44 44 sign.add_signs(bufnr, hunks) 45 45 46 46 if vim.b[bufnr].vcsigns_show_hunk_diffs then ··· 62 62 return 63 63 end 64 64 local s = state.get(bufnr) 65 - local last = s.last_update 65 + local last = s.diff.last_update 66 66 if start_time <= last then 67 67 util.verbose "Skipping updating old file, we already have a newer update." 68 68 return 69 69 end 70 - s.old_contents = old_contents 71 - s.last_update = start_time 72 - s.hunks_changedtick = vim.b[bufnr].changedtick 70 + s.diff.old_contents = old_contents 71 + s.diff.last_update = start_time 72 + s.diff.hunks_changedtick = vim.b[bufnr].changedtick 73 73 cb(bufnr) 74 74 end) 75 75 end ··· 77 77 ---@param bufnr integer The buffer number. 78 78 ---@return Vcs|nil The VCS object if ready, nil otherwise. 79 79 local function _get_vcs_if_ready(bufnr) 80 - local detecting = vim.b[bufnr].vcsigns_detecting 80 + local vcs_state = state.get(bufnr).vcs 81 + local detecting = vcs_state.detecting 81 82 if detecting == nil then 82 83 util.verbose "Buffer not initialized yet." 83 84 end ··· 85 86 util.verbose "Busy detecting, skipping." 86 87 return 87 88 end 88 - return vim.b[bufnr].vcsigns_vcs 89 + return vcs_state.vcs 89 90 end 90 91 91 92 --- Expensive update including vcs querying for file contents.