Skip to content
Snippets Groups Projects

Fix incorrect Batched suggestions applications

2 unresolved threads
Files
4
@@ -7,17 +7,14 @@ class FileSuggestion
SuggestionForDifferentFileError = Class.new(StandardError)
def initialize
@suggestions = []
end
def add_suggestion(new_suggestion)
if for_different_file?(new_suggestion)
raise SuggestionForDifferentFileError,
'Only add suggestions for the same file.'
end
attr_reader :file_path
attr_reader :blob
attr_reader :suggestions
suggestions << new_suggestion
def initialize(file_path, suggestions)
@file_path = file_path
@suggestions = suggestions.sort_by(&:from_line_index)
@blob = suggestions.first&.diff_file&.new_blob
end
def line_conflict?
@@ -30,22 +27,8 @@ def new_content
@new_content ||= _new_content
end
def file_path
@file_path ||= _file_path
end
private
attr_accessor :suggestions
def sorted_suggestions
@sorted_suggestions ||= suggestions.sort_by(&:from_line_index)
end
def blob
first_suggestion&.diff_file&.new_blob
end
def blob_data_lines
blob.load_all_data!
blob.data.lines
@@ -60,7 +43,7 @@ def _new_content
# NOTE: We need to cater for line number changes when the range is more than one line.
offset = 0
sorted_suggestions.each do |suggestion|
suggestions.each do |suggestion|
range = line_range(suggestion, offset)
content[range] = suggestion.to_content
offset += range.count - 1
@@ -72,22 +55,6 @@ def line_range(suggestion, offset = 0)
(suggestion.from_line_index - offset)..(suggestion.to_line_index - offset)
end
def for_different_file?(suggestion)
file_path && file_path != suggestion_file_path(suggestion)
end
def suggestion_file_path(suggestion)
suggestion&.diff_file&.file_path
end
def first_suggestion
suggestions.first
end
def _file_path
suggestion_file_path(first_suggestion)
end
def _line_conflict?
has_conflict = false
Loading