105105--- @param old_content table
106106--- @param new_content table
107107--- @return string
108- local function format_changes_as_diff (old_content , new_content )
108+ function Watchers : format_changes_as_diff (old_content , new_content )
109109 -- Convert line arrays to strings for vim.diff
110110 local old_str = table.concat (old_content , " \n " ) .. " \n "
111111 local new_str = table.concat (new_content , " \n " ) .. " \n "
@@ -116,7 +116,9 @@ local function format_changes_as_diff(old_content, new_content)
116116 algorithm = " myers" ,
117117 })
118118 if diff_result and diff_result ~= " " then
119- return fmt (" ```diff\n %s```" , diff_result )
119+ -- replace line numbers in diff to keep a common format
120+ diff_result = diff_result :gsub (" ^@@ .+ @@\n " , " @@\n " )
121+ return fmt (" ```\n %s```" , diff_result )
120122 end
121123
122124 return " "
@@ -132,7 +134,7 @@ function Watchers:check_for_changes(chat)
132134 if has_changed and old_content then
133135 local filename = vim .fn .fnamemodify (api .nvim_buf_get_name (ref .bufnr ), " :." )
134136 local current_content = api .nvim_buf_get_lines (ref .bufnr , 0 , - 1 , false )
135- local diff_content = format_changes_as_diff (old_content , current_content )
137+ local diff_content = self : format_changes_as_diff (old_content , current_content )
136138
137139 if diff_content ~= " " then
138140 local delta = fmt (" The file `%s`, has been modified. Here are the changes:\n %s" , filename , diff_content )
0 commit comments