Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3193b68
Separates key listeners from key verify listeners
dingfeli Sep 23, 2024
3156b3f
Simplifies key listeners
dingfeli Sep 23, 2024
33c942c
Removes logic for skipping leading whitespace
dingfeli Sep 24, 2024
71754e1
Adds logic for checking open brackets
dingfeli Sep 24, 2024
bca0631
Adds logic for checking close brackets
dingfeli Sep 24, 2024
7ccceda
Loosens caret movement check conditions
dingfeli Sep 24, 2024
c4d3ad0
Refines typeahead logic with regards to auto closing brackets
dingfeli Sep 25, 2024
f5e4ea8
Unsets vertical indent on new line inserted by eclipse
dingfeli Sep 25, 2024
dc518ac
Comments
dingfeli Sep 25, 2024
b079720
Merge branch 'main' of github.com:aws/amazon-q-eclipse into refactor-…
dingfeli Sep 25, 2024
ae140be
Fixes merging error
dingfeli Sep 25, 2024
e62b711
Merge branch 'main' into refactor-input-listener-for-inline
dingfeli Sep 25, 2024
ba40253
Moves decision transition ahead in acceptance handler to avoid null p…
dingfeli Sep 26, 2024
62cd9b6
Merge branch 'refactor-input-listener-for-inline' of github.com:aws/a…
dingfeli Sep 26, 2024
2c19bf7
Adds line param to unsetVerticalIndent
dingfeli Sep 26, 2024
c0d9021
Merge branch 'main' into refactor-input-listener-for-inline
breedloj Sep 26, 2024
5356715
Fixes checkstyle errors
dingfeli Sep 27, 2024
200758f
Merge branch 'refactor-input-listener-for-inline' into fix-vertical-i…
dingfeli Sep 27, 2024
69ac35b
Merge branch 'main' into fix-vertical-indent-unset
dingfeli Sep 27, 2024
450bb96
Fixes checkstyle errors
dingfeli Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

public final class QInlineCaretListener implements CaretListener {
private StyledText widget = null;
private int previousLine = -1;

public QInlineCaretListener(final StyledText widget) {
this.widget = widget;
this.previousLine = widget.getLineAtOffset(widget.getCaretOffset());
}

@Override
Expand All @@ -21,13 +23,16 @@ public void caretMoved(final CaretEvent event) {
// We want to ignore caret movements induced by text editing
if (caretMovementReason == CaretMovementReason.TEXT_INPUT) {
qInvocationSessionInstance.setCaretMovementReason(CaretMovementReason.UNEXAMINED);
previousLine = widget.getLineAtOffset(widget.getCaretOffset());
return;
}

if (qInvocationSessionInstance.isPreviewingSuggestions()) {
qInvocationSessionInstance.transitionToDecisionMade();
qInvocationSessionInstance.transitionToDecisionMade(previousLine + 1);
qInvocationSessionInstance.end();
return;
}

previousLine = widget.getCaretOffset();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ public void verifyKey(final VerifyEvent event) {
case SWT.CR:
if (lastKeyStrokeType == LastKeyStrokeType.OPEN_CURLY && isAutoClosingEnabled) {
lastKeyStrokeType = LastKeyStrokeType.OPEN_CURLY_FOLLOWED_BY_NEW_LINE;
// we need to unset the vertical indent prior to new line otherwise the line
// inserted by
// eclipse with the closing curly braces would inherit the extra vertical
// indent.
qInvocationSessionInstance.unsetVerticalIndent();
// we need to unset the vertical indent prior to new line otherwise the line inserted by
// eclipse with the closing curly braces would inherit the extra vertical indent.
int line = widget.getLineAtOffset(widget.getCaretOffset());
qInvocationSessionInstance.unsetVerticalIndent(line + 1);
} else {
lastKeyStrokeType = LastKeyStrokeType.NORMAL_INPUT;
}
Expand Down Expand Up @@ -196,9 +195,6 @@ public void verifyText(final VerifyEvent event) {
.setHasBeenTypedahead(currentOffset - qInvocationSessionInstance.getInvocationOffset() > 0);

boolean isOutOfBounds = distanceTraversed >= currentSuggestion.length() || distanceTraversed < 0;
if (!isOutOfBounds) {
System.out.println("current char in suggestion: " + currentSuggestion.charAt(distanceTraversed));
}
if (isOutOfBounds || !isInputAMatch(currentSuggestion, distanceTraversed, input)) {
qInvocationSessionInstance.transitionToDecisionMade();
qInvocationSessionInstance.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public final void paintControl(final PaintEvent e) {
int y = location.y + lineHt * 2 - fontHt;
gc.drawText(remainder, x, y, true);
} else {
qInvocationSessionInstance.unsetVerticalIndent();
int line = widget.getLineAtOffset(widget.getCaretOffset());
qInvocationSessionInstance.unsetVerticalIndent(line + 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Stack;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.function.Consumer;

import static software.aws.toolkits.eclipse.amazonq.util.QConstants.Q_INLINE_HINT_TEXT_STYLE;
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.getActiveTextViewer;
Expand All @@ -45,7 +46,7 @@ public final class QInvocationSession extends QResource {
private int[] headOffsetAtLine = new int[500];
private boolean hasBeenTypedahead = false;
private CodeReferenceAcceptanceCallback codeReferenceAcceptanceCallback = null;
private Runnable unsetVerticalIndent;
private Consumer<Integer> unsetVerticalIndent;

// Private constructor to prevent instantiation
private QInvocationSession() {
Expand Down Expand Up @@ -214,12 +215,17 @@ public void transitionToInactiveState() {
}

public void transitionToDecisionMade() {
var widget = viewer.getTextWidget();
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
transitionToDecisionMade(caretLine + 1);
}

public void transitionToDecisionMade(final int line) {
if (state != QInvocationSessionState.SUGGESTION_PREVIEWING) {
return;
}
state = QInvocationSessionState.DECISION_MADE;

unsetVerticalIndent();
unsetVerticalIndent(line);
}

public void setCaretMovementReason(final CaretMovementReason reason) {
Expand Down Expand Up @@ -325,15 +331,14 @@ public void executeCallbackForCodeReference() {
public void setVerticalIndent(final int line, final int height) {
var widget = viewer.getTextWidget();
widget.setLineVerticalIndent(line, height);
unsetVerticalIndent = () -> {
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
widget.setLineVerticalIndent(caretLine + 1, 0);
unsetVerticalIndent = (caretLine) -> {
widget.setLineVerticalIndent(caretLine, 0);
};
}

public void unsetVerticalIndent() {
public void unsetVerticalIndent(final int caretLine) {
if (unsetVerticalIndent != null) {
unsetVerticalIndent.run();
unsetVerticalIndent.accept(caretLine);
unsetVerticalIndent = null;
}
}
Expand Down