Skip to content

Commit 5e7fefb

Browse files
authored
Merge branch 'main' into code-reference
2 parents cdf57f1 + 8b84484 commit 5e7fefb

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

plugin/src/software/aws/toolkits/eclipse/amazonq/handlers/QAcceptSuggestionsHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private void insertSuggestion(final String suggestion) {
3636
var insertOffset = widget.getCaretOffset();
3737
doc.replace(insertOffset, 0, suggestion);
3838
widget.setCaretOffset(insertOffset + suggestion.length());
39-
4039
QInvocationSession.getInstance().transitionToDecisionMade();
4140
QInvocationSession.getInstance().getViewer().getTextWidget().redraw();
4241
QInvocationSession.getInstance().executeCallbackForCodeReference();

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static ITextViewer getActiveTextViewer(final ITextEditor editor) {
6363
return asTextViewer(editor);
6464
}
6565

66-
public static boolean isLastLine(final StyledText textWidget, final int line) {
67-
return line == textWidget.getLineCount() - 1;
66+
public static boolean shouldIndentVertically(final StyledText textWidget, final int zeroIndexedLine) {
67+
return zeroIndexedLine + 1 < textWidget.getLineCount();
6868
}
6969

7070

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
package software.aws.toolkits.eclipse.amazonq.util;
55

6-
//import org.eclipse.swt.custom.StyledText;
76
import org.eclipse.swt.events.PaintEvent;
87
import org.eclipse.swt.events.PaintListener;
9-
//import org.eclipse.swt.graphics.Point;
8+
import org.eclipse.swt.graphics.Point;
109

1110
import static software.aws.toolkits.eclipse.amazonq.util.QConstants.Q_INLINE_HINT_TEXT_COLOR;
12-
//import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.isLastLine;
11+
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.shouldIndentVertically;
1312

1413
import java.util.Arrays;
1514

@@ -50,38 +49,38 @@ public final void paintControl(final PaintEvent e) {
5049
}
5150

5251
int renderHeadIndex = currentOffset - offsetAtCurrentLine;
53-
String[] remainderArray = Arrays.copyOfRange(suggestionParts, currentLineInSuggestion + 1, suggestionParts.length);
52+
String[] remainderArray = Arrays.copyOfRange(suggestionParts, currentLineInSuggestion + 1,
53+
suggestionParts.length);
5454
String remainder = String.join("\n", remainderArray);
5555

5656
// Draw first line inline
57-
String firstLine = renderHeadIndex >= 0
58-
? suggestionParts[currentLineInSuggestion].trim() : suggestionParts[currentLineInSuggestion];
57+
String firstLine = renderHeadIndex >= 0 ? suggestionParts[currentLineInSuggestion].trim()
58+
: suggestionParts[currentLineInSuggestion];
5959
int xLoc = renderHeadIndex >= 0 ? location.x : widget.getLeftMargin();
6060
if (renderHeadIndex < firstLine.length()) {
61-
gc.drawText(renderHeadIndex >= 0 ? firstLine.substring(renderHeadIndex) : firstLine, xLoc, location.y, true);
61+
gc.drawText(renderHeadIndex >= 0 ? firstLine.substring(renderHeadIndex) : firstLine, xLoc, location.y,
62+
true);
6263
}
6364

6465
// Draw other lines inline
6566
if (!remainder.isEmpty()) {
6667
// For last line case doesn't need to indent next line vertically
6768
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
68-
// Felix: Not really sure what this does and it is throwing under certain
69-
// circumstance
70-
// Will confirm with Andrew before adding this back in / modifying it.
71-
// if (!isLastLine(widget, caretLine + 1)) {
72-
// // when showing the suggestion need to add next line indent
73-
// Point textExtent = gc.stringExtent(" ");
74-
// int height = textExtent.y * suggestionParts[1].split("\\R").length;
75-
// widget.setLineVerticalIndent(caretLine + 1, height);
76-
// }
69+
if (shouldIndentVertically(widget, caretLine) && qInvocationSessionInstance.isPreviewingSuggestions()) {
70+
// when showing the suggestion need to add next line indent
71+
Point textExtent = gc.stringExtent(" ");
72+
int height = textExtent.y * remainder.split("\\R").length;
73+
qInvocationSessionInstance.setVerticalIndent(caretLine + 1, height);
74+
}
7775

7876
int lineHt = widget.getLineHeight();
7977
int fontHt = gc.getFontMetrics().getHeight();
8078
int x = widget.getLeftMargin();
8179
int y = location.y + lineHt * 2 - fontHt;
8280
gc.drawText(remainder, x, y, true);
81+
} else {
82+
qInvocationSessionInstance.unsetVerticalIndent();
8383
}
8484
}
8585

8686
}
87-

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class QInvocationSession extends QResource {
4848
private int[] headOffsetAtLine = new int[500];
4949
private boolean hasBeenTypedahead = false;
5050
private CodeReferenceAcceptanceCallback codeReferenceAcceptanceCallback = null;
51+
private Runnable unsetVerticalIndent;
5152

5253
// Private constructor to prevent instantiation
5354
private QInvocationSession() {
@@ -220,14 +221,7 @@ public void transitionToDecisionMade() {
220221
}
221222
state = QInvocationSessionState.DECISION_MADE;
222223

223-
// Clear previous next line indent in certain cases (always for now?)
224-
// From Felix: Not really sure when or where this is needed, disabling for now.
225-
// This is throwing under certain circumstances with IllegalArgument
226-
// var widget = viewer.getTextWidget();
227-
// var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
228-
// if (!isLastLine(widget, caretLine + 1)) {
229-
// widget.setLineVerticalIndent(caretLine + 1, 0);
230-
// }
224+
unsetVerticalIndent();
231225
}
232226

233227
public void setCaretMovementReason(final CaretMovementReason reason) {
@@ -345,6 +339,22 @@ public void executeCallbackForCodeReference() {
345339
codeReferenceAcceptanceCallback.onCallback(selectedSuggestion, startLine);
346340
}
347341
}
342+
343+
public void setVerticalIndent(int line, int height) {
344+
var widget = viewer.getTextWidget();
345+
widget.setLineVerticalIndent(line, height);
346+
unsetVerticalIndent = () -> {
347+
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
348+
widget.setLineVerticalIndent(caretLine + 1, 0);
349+
};
350+
}
351+
352+
public void unsetVerticalIndent() {
353+
if (unsetVerticalIndent != null) {
354+
unsetVerticalIndent.run();
355+
unsetVerticalIndent = null;
356+
}
357+
}
348358

349359
// Additional methods for the session can be added here
350360
@Override

0 commit comments

Comments
 (0)