@@ -4,6 +4,7 @@ local config = require("codecompanion").config
44
55local keymaps = require (" codecompanion.utils.keymaps" )
66local log = require (" codecompanion.utils.log" )
7+ local mini_diff = require (" codecompanion.strategies.inline.mini_diff" )
78local msg_utils = require (" codecompanion.utils.messages" )
89local ui = require (" codecompanion.utils.ui" )
910local util = require (" codecompanion.utils.util" )
173174--- Start the classification of the user's prompt
174175--- @param opts ? table
175176function Inline :start (opts )
177+ -- NOTE: we need to add this here to intiate the mini.diff early to be
178+ -- working properly
179+ if config .display .inline .diff .diff_method == " mini_diff" then
180+ log :trace (" CodeCompanion: Using mini diff for inline display" )
181+ require (" codecompanion.strategies.inline.mini_diff" ).setup ()
182+ end
183+
176184 log :trace (" Starting Inline with opts: %s" , opts )
177185
178186 if opts and opts [1 ] then
@@ -562,61 +570,72 @@ function Inline:start_diff()
562570 if config .display .inline .diff .enabled == false then
563571 return
564572 end
573+ if config .display .inline .diff .diff_method == " mini_diff" then
574+ return -- no need to do anything here, since it's handled in mini_diff.lua
575+ else
576+ -- Taken from the awesome:
577+ -- https://github.com/S1M0N38/dante.nvim
565578
566- -- Taken from the awesome:
567- -- https://github.com/S1M0N38/dante.nvim
568-
569- -- Get current window properties
570- local wrap = vim .wo .wrap
571- local linebreak = vim .wo .linebreak
572- local breakindent = vim .wo .breakindent
573- vim .cmd (" set diffopt=" .. table.concat (config .display .inline .diff .opts , " ," ))
579+ -- Get current window properties
580+ local wrap = vim .wo .wrap
581+ local linebreak = vim .wo .linebreak
582+ local breakindent = vim .wo .breakindent
583+ vim .cmd (" set diffopt=" .. table.concat (config .display .inline .diff .opts , " ," ))
574584
575- -- Close the chat buffer
576- local last_chat = require (" codecompanion" ).last_chat ()
577- if last_chat and last_chat :is_visible () and config .display .inline .diff .close_chat_at > vim .o .columns then
578- last_chat :hide ()
579- end
585+ -- Close the chat buffer
586+ local last_chat = require (" codecompanion" ).last_chat ()
587+ if last_chat and last_chat :is_visible () and config .display .inline .diff .close_chat_at > vim .o .columns then
588+ last_chat :hide ()
589+ end
580590
581- -- Create the diff buffer
582- if config .display .inline .diff .layout == " vertical" then
583- vim .cmd (" vsplit" )
584- else
585- vim .cmd (" split" )
591+ -- Create the diff buffer
592+ if config .display .inline .diff .layout == " vertical" then
593+ vim .cmd (" vsplit" )
594+ else
595+ vim .cmd (" split" )
596+ end
597+ self .diff .winnr = api .nvim_get_current_win ()
598+ self .diff .bufnr = api .nvim_create_buf (false , true )
599+ api .nvim_win_set_buf (self .diff .winnr , self .diff .bufnr )
600+ api .nvim_set_option_value (" filetype" , self .context .filetype , { buf = self .diff .bufnr })
601+ api .nvim_set_option_value (" wrap" , wrap , { win = self .diff .winnr })
602+ api .nvim_set_option_value (" linebreak" , linebreak , { win = self .diff .winnr })
603+ api .nvim_set_option_value (" breakindent" , breakindent , { win = self .diff .winnr })
604+
605+ -- Set the diff buffer to the contents, prior to any modifications
606+ api .nvim_buf_set_lines (self .diff .bufnr , 0 , 0 , true , self .diff .lines )
607+ api .nvim_win_set_cursor (self .diff .winnr , { self .context .cursor_pos [1 ], self .context .cursor_pos [2 ] })
608+
609+ -- Begin diffing
610+ api .nvim_set_current_win (self .diff .winnr )
611+ vim .cmd (" diffthis" )
612+ api .nvim_set_current_win (self .context .winnr )
613+ vim .cmd (" diffthis" )
586614 end
587- self .diff .winnr = api .nvim_get_current_win ()
588- self .diff .bufnr = api .nvim_create_buf (false , true )
589- api .nvim_win_set_buf (self .diff .winnr , self .diff .bufnr )
590- api .nvim_set_option_value (" filetype" , self .context .filetype , { buf = self .diff .bufnr })
591- api .nvim_set_option_value (" wrap" , wrap , { win = self .diff .winnr })
592- api .nvim_set_option_value (" linebreak" , linebreak , { win = self .diff .winnr })
593- api .nvim_set_option_value (" breakindent" , breakindent , { win = self .diff .winnr })
594-
595- -- Set the diff buffer to the contents, prior to any modifications
596- api .nvim_buf_set_lines (self .diff .bufnr , 0 , 0 , true , self .diff .lines )
597- api .nvim_win_set_cursor (self .diff .winnr , { self .context .cursor_pos [1 ], self .context .cursor_pos [2 ] })
598-
599- -- Begin diffing
600- api .nvim_set_current_win (self .diff .winnr )
601- vim .cmd (" diffthis" )
602- api .nvim_set_current_win (self .context .winnr )
603- vim .cmd (" diffthis" )
604615end
605616
606617--- Accept the changes in the diff
607618--- @return nil
608619function Inline :accept ()
609- api .nvim_win_close (self .diff .winnr , false )
610- self .diff = {}
620+ if config .display .inline .diff .diff_method == " mini_diff" then
621+ mini_diff .accept (self .context .bufnr )
622+ else
623+ api .nvim_win_close (self .diff .winnr , false )
624+ self .diff = {}
625+ end
611626end
612627
613628--- Reject the changes in the diff
614629--- @return nil
615630function Inline :reject ()
616- vim .cmd (" diffoff" )
617- api .nvim_win_close (self .diff .winnr , false )
618- api .nvim_buf_set_lines (self .context .bufnr , 0 , - 1 , true , self .diff .lines )
619- self .diff = {}
631+ if config .display .inline .diff .diff_method == " mini_diff" then
632+ mini_diff .reject (self .context .bufnr )
633+ else
634+ vim .cmd (" diffoff" )
635+ api .nvim_win_close (self .diff .winnr , false )
636+ api .nvim_buf_set_lines (self .context .bufnr , 0 , - 1 , true , self .diff .lines )
637+ self .diff = {}
638+ end
620639end
621640
622641return Inline
0 commit comments