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.

Only compute fine diff when the hunk diff view is enabled.

+15 -6
+13 -5
lua/vcsigns/diff.lua
··· 140 140 ---@param hunk_quad integer[] 141 141 ---@param old_lines string[] The old lines of the file. 142 142 ---@param new_lines string[] The new lines of the file. 143 + ---@param compute_fine_diff boolean Whether to compute fine grained diffs within the hunk. 143 144 ---@return Hunk 144 - local function _quad_to_hunk(hunk_quad, old_lines, new_lines) 145 + local function _quad_to_hunk(hunk_quad, old_lines, new_lines, compute_fine_diff) 145 146 local minus_lines = util.slice(old_lines, hunk_quad[1], hunk_quad[2]) 146 147 local plus_lines = util.slice(new_lines, hunk_quad[3], hunk_quad[4]) 147 148 local diff_opts = vim.g.vcsigns_diff_opts 148 - local intra_diff = 149 - _compute_intra_hunk_diff(minus_lines, plus_lines, diff_opts) 149 + local intra_diff = {} 150 + if compute_fine_diff then 151 + intra_diff = 152 + _compute_intra_hunk_diff(minus_lines, plus_lines, diff_opts) 153 + end 150 154 151 155 return { 152 156 minus_start = hunk_quad[1], ··· 162 166 ---Compute the diff between two contents. 163 167 ---@param old_contents string The old contents. 164 168 ---@param new_contents string The new contents. 169 + ---@param compute_fine_diff boolean Whether to compute fine grained diffs within the hunks. 165 170 ---@return Hunk[] The computed hunks. 166 - function M.compute_diff(old_contents, new_contents) 171 + function M.compute_diff(old_contents, new_contents, compute_fine_diff) 167 172 local diff_opts = vim.g.vcsigns_diff_opts 168 173 local old_lines = vim.split(old_contents, "\n", { plain = true }) 169 174 local new_lines = vim.split(new_contents, "\n", { plain = true }) ··· 171 176 local hunk_quads = _vim_diff(old_lines, new_lines, diff_opts) 172 177 local hunks = {} 173 178 for _, quad in ipairs(hunk_quads) do 174 - table.insert(hunks, _quad_to_hunk(quad, old_lines, new_lines)) 179 + table.insert( 180 + hunks, 181 + _quad_to_hunk(quad, old_lines, new_lines, compute_fine_diff) 182 + ) 175 183 end 176 184 return hunks 177 185 end
+2 -1
lua/vcsigns/updates.lua
··· 37 37 old_contents = "\n" 38 38 end 39 39 40 - local hunks = diff.compute_diff(old_contents, new_contents) 40 + local compute_fine_diff = vim.b[bufnr].vcsigns_show_hunk_diffs 41 + local hunks = diff.compute_diff(old_contents, new_contents, compute_fine_diff) 41 42 vim.b[bufnr].vcsigns_hunks = hunks 42 43 sign.add_signs(bufnr, hunks) 43 44