@@ -5,11 +5,18 @@ local GitRev = lazy.access("diffview.vcs.adapters.git.rev", "GitRev") ---@type G
55local RevType = lazy .access (" diffview.vcs.rev" , " RevType" ) --- @type RevType | LazyModule
66local async = lazy .require (" plenary.async" ) --- @module " plenary.async"
77local config = lazy .require (" diffview.config" ) --- @module " diffview.config"
8+ local debounce = lazy .require (" diffview.debounce" ) --- @module " diffview.debounce"
9+ local gs_actions = lazy .require (" gitsigns.actions" ) --- @module " gitsigns.actions"
810local lib = lazy .require (" diffview.lib" ) --- @module " diffview.lib"
911local utils = lazy .require (" diffview.utils" ) --- @module " diffview.utils"
1012
1113local pl = lazy .access (utils , " path" ) --- @type PathLib | LazyModule
1214
15+ local gs_refresh = debounce .debounce_trailing (20 , false , vim .schedule_wrap (function (callback )
16+ gs_actions .refresh ()
17+ if vim .is_callable (callback ) then callback () end
18+ end ))
19+
1320local api = vim .api
1421local M = {}
1522
@@ -279,10 +286,18 @@ end
279286--- @param t2 table
280287--- @return vcs.File.AttachState
281288local function prepare_attach_opt (t1 , t2 )
282- local res = vim .tbl_extend (" keep" , t1 , {
289+ --- @class vcs.File.AttachState
290+ local default_opt = {
283291 keymaps = {},
284292 disable_diagnostics = false ,
285- })
293+ inline_diff = {
294+ enabled = false ,
295+ base = nil --[[ @as string? ]] ,
296+ update = nil --[[ @as function? ]] ,
297+ }
298+ }
299+
300+ local res = vim .tbl_extend (" force" , default_opt , t1 )
286301
287302 for k , v in pairs (t2 ) do
288303 local t = type (res [k ])
@@ -299,10 +314,6 @@ local function prepare_attach_opt(t1, t2)
299314 return res
300315end
301316
302- --- @class vcs.File.AttachState
303- --- @field keymaps table
304- --- @field disable_diagnostics boolean
305-
306317--- @param force ? boolean
307318--- @param opt ? vcs.File.AttachState
308319function File :attach_buffer (force , opt )
@@ -332,6 +343,23 @@ function File:attach_buffer(force, opt)
332343 vim .diagnostic .disable (self .bufnr )
333344 end
334345
346+ -- Inline diff
347+ if state .inline_diff .enabled then
348+ local gitsigns = require (" gitsigns" )
349+ local gs_config = require (" gitsigns.config" ).config
350+ gitsigns .attach (self .bufnr , {
351+ file = self .path ,
352+ toplevel = self .adapter .ctx .toplevel ,
353+ gitdir = self .adapter .ctx .dir ,
354+ commit = self .rev .type ~= RevType .LOCAL and self .rev :object_name () or nil ,
355+ base = utils .sate (state .inline_diff .base , self .rev .type == RevType .STAGE and " HEAD" ),
356+ })
357+ gs_config .linehl = true
358+ gs_config .show_deleted = true
359+ gs_config .word_diff = true
360+ gs_refresh (state .inline_diff .update )
361+ end
362+
335363 File .attached [self .bufnr ] = state
336364 end
337365 end
@@ -359,6 +387,15 @@ function File:detach_buffer()
359387 vim .diagnostic .enable (self .bufnr )
360388 end
361389
390+ -- Inline diff
391+ if state .inline_diff .enabled then
392+ local gs_config = require (" gitsigns.config" ).config
393+ gs_config .linehl = false
394+ gs_config .show_deleted = false
395+ gs_config .word_diff = false
396+ gs_refresh (state .inline_diff .update )
397+ end
398+
362399 File .attached [self .bufnr ] = nil
363400 end
364401 end
0 commit comments