@@ -17,33 +17,15 @@ public record InlineCompletion(
1717 int widgetLineIndex ,
1818 IRegion modelRegion ,
1919 int widgetOffset ,
20- String firstLineContent ,
21- String content ,
22- /*
23- * if the completion is not the end of the line, this contains the next letter (otherwise null)
24- */
25- String firstLineSuffixCharacter ,
20+ String content , // the whole completion content
21+ List < String > lines , // the completion content line by line
22+ String firstLineFillPrefix ,
23+ String firstLineFillSuffix ,
24+ String firstLineSuffix , // the existing suffix of the line that is being completed
25+ String firstLineSuffixCharacter , // if the completion is not the end of the line, this contains the next letter (otherwise null)
2626 int lineSpacing ,
2727 int lineHeight ) {
2828
29- public String toDebugString () {
30- return """
31- =========================
32- lineIndex: %d
33- modelRegion: %s
34- widgetOffset: %d
35- firstLineContent: "%s"
36- content:
37- ---
38- %s
39- ---
40- firstLineSuffixCharacter: "%s"
41- lineSpacing: %d
42- lineHeight: %d
43- =========================
44- """ .formatted (this .widgetLineIndex , this .modelRegion , this .widgetOffset , this .firstLineContent , this .content , this .firstLineSuffixCharacter , this .lineSpacing , this .lineHeight );
45- }
46-
4729 public void applyTo (final IDocument document ) throws BadLocationException {
4830 final int replaceOffset = this .modelRegion ().getOffset ();
4931 final int replaceLength = this .modelRegion ().getLength ();
@@ -78,19 +60,21 @@ public static InlineCompletion create(AiCoderHistoryEntry historyEntry, IDocumen
7860 } else {
7961 lineSuffixLength = document .getLength () - modelOffset ;
8062 }
81- final String lineSuffix = document .get (modelOffset , lineSuffixLength );
82- final String firstLineSuffixCharacter = !lineSuffix .isBlank () && !isMultiline ? lineSuffix .substring (0 , 1 ) : null ;
83- String firstLineContent = content .lines ().findFirst ().orElse ("" );
84- final boolean contentContainsLineSuffix = content .startsWith (lineSuffix );
85- if (contentContainsLineSuffix ) {
86- content = content .substring (lineSuffixLength );
87- firstLineContent = firstLineContent .substring (Math .min (lineSuffixLength , firstLineContent .length ()));
88- }
63+ final String firstLineSuffix = document .get (modelOffset , lineSuffixLength );
64+ final String firstLineSuffixCharacter = !firstLineSuffix .isBlank () ? firstLineSuffix .substring (0 , 1 ) : null ;
65+ final String firstLineContent = content .lines ().findFirst ().orElse ("" );
66+ final boolean contentContainsLineSuffix = content .startsWith (firstLineSuffix );
8967 final int lineSpacing = (int ) (defaultLineSpacing + (content .lines ().count () - 1 ) * lineHeight );
90- final Region modelRegion = new Region (modelOffset , contentContainsLineSuffix || isMultiline ? lineSuffix .length () : 0 );
91- if (isMultiline && !lineSuffix .isBlank ()) {
92- content += lineSuffix ;
68+ final Region modelRegion = new Region (modelOffset , contentContainsLineSuffix || isMultiline ? firstLineSuffix .length () : 0 );
69+ final String firstLineFillPrefix ;
70+ final String firstLineFillSuffix ;
71+ if (!firstLineContent .isBlank () && !firstLineSuffix .isBlank () && firstLineContent .contains (firstLineSuffix )) {
72+ firstLineFillPrefix = firstLineContent .substring (0 , firstLineContent .indexOf (firstLineSuffix ));
73+ firstLineFillSuffix = firstLineContent .substring (firstLineContent .indexOf (firstLineSuffix ) + firstLineSuffix .length ());
74+ } else {
75+ firstLineFillPrefix = firstLineContent ;
76+ firstLineFillSuffix = "" ;
9377 }
94- return new InlineCompletion (historyEntry , widgetLine , modelRegion , widgetOffset , firstLineContent , content , firstLineSuffixCharacter , lineSpacing , lineHeight );
78+ return new InlineCompletion (historyEntry , widgetLine , modelRegion , widgetOffset , content , content . lines (). toList (), firstLineFillPrefix , firstLineFillSuffix , firstLineSuffix , firstLineSuffixCharacter , lineSpacing , lineHeight );
9579 }
9680}
0 commit comments