diff.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ---@meta
  2. --- Optional parameters:
  3. --- @class vim.diff.Opts
  4. --- @inlinedoc
  5. ---
  6. --- Invoked for each hunk in the diff. Return a negative number
  7. --- to cancel the callback for any remaining hunks.
  8. --- Arguments:
  9. --- - `start_a` (`integer`): Start line of hunk in {a}.
  10. --- - `count_a` (`integer`): Hunk size in {a}.
  11. --- - `start_b` (`integer`): Start line of hunk in {b}.
  12. --- - `count_b` (`integer`): Hunk size in {b}.
  13. --- @field on_hunk? fun(start_a: integer, count_a: integer, start_b: integer, count_b: integer): integer?
  14. ---
  15. --- Form of the returned diff:
  16. --- - `unified`: String in unified format.
  17. --- - `indices`: Array of hunk locations.
  18. --- Note: This option is ignored if `on_hunk` is used.
  19. --- (default: `'unified'`)
  20. --- @field result_type? 'unified'|'indices'
  21. ---
  22. --- Run linematch on the resulting hunks from xdiff. When integer, only hunks
  23. --- upto this size in lines are run through linematch.
  24. --- Requires `result_type = indices`, ignored otherwise.
  25. --- @field linematch? boolean|integer
  26. ---
  27. --- Diff algorithm to use. Values:
  28. --- - `myers`: the default algorithm
  29. --- - `minimal`: spend extra time to generate the smallest possible diff
  30. --- - `patience`: patience diff algorithm
  31. --- - `histogram`: histogram diff algorithm
  32. --- (default: `'myers'`)
  33. --- @field algorithm? 'myers'|'minimal'|'patience'|'histogram'
  34. --- @field ctxlen? integer Context length
  35. --- @field interhunkctxlen? integer Inter hunk context length
  36. --- @field ignore_whitespace? boolean Ignore whitespace
  37. --- @field ignore_whitespace_change? boolean Ignore whitespace change
  38. --- @field ignore_whitespace_change_at_eol? boolean Ignore whitespace change at end-of-line.
  39. --- @field ignore_cr_at_eol? boolean Ignore carriage return at end-of-line
  40. --- @field ignore_blank_lines? boolean Ignore blank lines
  41. --- @field indent_heuristic? boolean Use the indent heuristic for the internal diff library.
  42. -- luacheck: no unused args
  43. --- Run diff on strings {a} and {b}. Any indices returned by this function,
  44. --- either directly or via callback arguments, are 1-based.
  45. ---
  46. --- Examples:
  47. ---
  48. --- ```lua
  49. --- vim.diff('a\n', 'b\nc\n')
  50. --- -- =>
  51. --- -- @@ -1 +1,2 @@
  52. --- -- -a
  53. --- -- +b
  54. --- -- +c
  55. ---
  56. --- vim.diff('a\n', 'b\nc\n', {result_type = 'indices'})
  57. --- -- =>
  58. --- -- {
  59. --- -- {1, 1, 1, 2}
  60. --- -- }
  61. --- ```
  62. ---
  63. ---@param a string First string to compare
  64. ---@param b string Second string to compare
  65. ---@param opts? vim.diff.Opts
  66. ---@return string|integer[][]?
  67. --- See {opts.result_type}. `nil` if {opts.on_hunk} is given.
  68. function vim.diff(a, b, opts) end