@@ -170,24 +170,62 @@ package body LSP.Text_Documents is
170170 procedure Diff_C
171171 (Self : Text_Document'Class;
172172 New_Text : VSS.Strings.Virtual_String;
173+ Span : LSP.Structures.A_Range;
173174 Edit : out LSP.Structures.TextEdit_Vector)
174175 is
176+ use type LSP.Structures.A_Range;
177+
175178 C_Edit : constant XDiff.Edits := XDiff.XDiff
176- (VSS.Strings.Conversions.To_UTF_8_String (Self.Text),
179+ (VSS.Strings.Conversions.To_UTF_8_String
180+ (if Span /= LSP.Text_Documents.Empty_Range
181+ then Self.Slice (Span)
182+ else Self.Text),
177183 VSS.Strings.Conversions.To_UTF_8_String (New_Text),
178184 XDiff.XDF_NEED_MINIMAL);
179- Cur : XDiff.Edits := C_Edit;
185+
180186 New_Lines : constant VSS.String_Vectors.Virtual_String_Vector :=
181187 New_Text.Split_Lines
182188 (Terminators => LSP_New_Line_Function_Set,
183189 Keep_Terminator => False);
184190
191+ Cur : XDiff.Edits := C_Edit;
192+
193+ function Get_Range
194+ (Cur_Edit : XDiff.Edits) return LSP.Structures.A_Range;
195+
185196 function Get_Slice
186197 (Lines : VSS.String_Vectors.Virtual_String_Vector;
187198 Start_Line : Integer;
188199 End_Line : Integer)
189200 return VSS.Strings.Virtual_String;
190201
202+ -- -------------
203+ -- Get_Range --
204+ -- -------------
205+
206+ function Get_Range (Cur_Edit : XDiff.Edits) return LSP.Structures.A_Range
207+ is
208+ Start_Line : Natural;
209+ End_Line : Natural;
210+ -- Start_Bloc indicates the offset between the current line and the
211+ -- first from the buffer
212+ Start_Bloc : constant Natural :=
213+ (if Span /= LSP.Text_Documents.Empty_Range
214+ then Span.start.line
215+ else 0 );
216+ begin
217+ if XDiff.Delete_Line_Start (Cur_Edit) = -1 then
218+ Start_Line := XDiff.Delete_Line_End (Cur_Edit);
219+ else
220+ Start_Line := XDiff.Delete_Line_Start (Cur_Edit) - 1 ;
221+ end if ;
222+
223+ End_Line := XDiff.Delete_Line_End (Cur_Edit);
224+
225+ return (start => (Start_Line + Start_Bloc, 0 ),
226+ an_end => (End_Line + Start_Bloc, 0 ));
227+ end Get_Range ;
228+
191229 -- -------------
192230 -- Get_Slice --
193231 -- -------------
@@ -215,10 +253,7 @@ package body LSP.Text_Documents is
215253 if XDiff.Delete_Line_End (Cur) /= -1 then
216254 Edit.Append
217255 (LSP.Structures.TextEdit'
218- (a_range => (((if XDiff.Delete_Line_Start (Cur) = -1
219- then XDiff.Delete_Line_End (Cur)
220- else XDiff.Delete_Line_Start (Cur) - 1 ), 0 ),
221- (XDiff.Delete_Line_End (Cur), 0 )),
256+ (a_range => Get_Range (Cur),
222257 newText => Get_Slice (New_Lines,
223258 XDiff.Insert_Line_Start (Cur),
224259 XDiff.Insert_Line_End (Cur))));
0 commit comments