-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds code reference view * Adds fqfn to file being changed * Separates model reference model types into their own class files * Includes changes to InlineCompletionItem --------- Co-authored-by: Jonathan Breedlove <[email protected]>
- Loading branch information
Showing
11 changed files
with
190 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
plugin/src/software/aws/toolkits/eclipse/amazonq/lsp/model/InlineCompletionReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.lsp.model; | ||
|
||
public class InlineCompletionReference { | ||
private String referenceName; | ||
private String referenceUrl; | ||
private String licenseName; | ||
private InlineCompletionReferencePosition position; | ||
|
||
public final void setReferenceName(final String referenceName) { | ||
this.referenceName = referenceName; | ||
} | ||
|
||
public final void setReferenceUrl(final String referenceUrl) { | ||
this.referenceUrl = referenceUrl; | ||
} | ||
|
||
public final void setLicenseName(final String licenseName) { | ||
this.licenseName = licenseName; | ||
} | ||
|
||
public final void setPosition(final InlineCompletionReferencePosition position) { | ||
this.position = position; | ||
} | ||
|
||
public final String getReferenceName() { | ||
return referenceName; | ||
} | ||
|
||
public final String getReferenceUrl() { | ||
return referenceUrl; | ||
} | ||
|
||
public final String getLicenseName() { | ||
return licenseName; | ||
} | ||
|
||
public final InlineCompletionReferencePosition getPosition() { | ||
return position; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/software/aws/toolkits/eclipse/amazonq/lsp/model/InlineCompletionReferencePosition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.lsp.model; | ||
|
||
public class InlineCompletionReferencePosition { | ||
private int startCharacter; | ||
private int endCharacter; | ||
|
||
public final void setStartCharacter(final int startCharacter) { | ||
this.startCharacter = startCharacter; | ||
} | ||
|
||
public final void setEndCharacter(final int endCharacter) { | ||
this.endCharacter = endCharacter; | ||
} | ||
|
||
public final int getStartCharacter() { | ||
return startCharacter; | ||
} | ||
|
||
public final int getEndCharacter() { | ||
return endCharacter; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
plugin/src/software/aws/toolkits/eclipse/amazonq/util/CodeReferenceAcceptanceCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package software.aws.toolkits.eclipse.amazonq.util; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.lsp.model.InlineCompletionItem; | ||
|
||
@FunctionalInterface | ||
public interface CodeReferenceAcceptanceCallback { | ||
void onCallback(InlineCompletionItem suggestionItem, int startLine); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQCodeReferenceView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package software.aws.toolkits.eclipse.amazonq.views; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.StyleRange; | ||
import org.eclipse.swt.custom.StyledText; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.part.ViewPart; | ||
import software.aws.toolkits.eclipse.amazonq.util.QInvocationSession; | ||
|
||
public final class AmazonQCodeReferenceView extends ViewPart { | ||
|
||
public static final String ID = "software.aws.toolkits.eclipse.amazonq.views.AmazonQCodeReferenceView"; | ||
private static final String CR_TEMPLATE = """ | ||
[%s] Accepted recommendation with code | ||
%s | ||
provided with reference under %s from repository %s. Added to %s (lines from %d to %d) | ||
"""; | ||
|
||
private StyledText textArea; | ||
|
||
@Override | ||
public void createPartControl(final Composite parent) { | ||
if (textArea == null) { | ||
textArea = new StyledText(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); | ||
} | ||
|
||
QInvocationSession qInvocationSessionInstance = QInvocationSession.getInstance(); | ||
|
||
qInvocationSessionInstance.registerCallbackForCodeReference((item, startLine) -> { | ||
var references = item.getReferences(); | ||
var editor = qInvocationSessionInstance.getEditor(); | ||
String fqfn = editor.getTitle(); | ||
if (references != null && references.length > 0) { | ||
LocalDateTime now = LocalDateTime.now(); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy, HH:mm:ss a"); | ||
String formattedDateTime = now.format(formatter); | ||
int suggestionTextDepth = item.getInsertText().split("\n").length; | ||
for (var reference : references) { | ||
String itemToShow = String.format(CR_TEMPLATE, formattedDateTime, item.getInsertText(), | ||
reference.getLicenseName(), reference.getReferenceUrl(), | ||
fqfn, startLine, startLine + suggestionTextDepth); | ||
int boldStart = textArea.getCharCount(); | ||
int boldLength = itemToShow.split("\n", 2)[0].length(); | ||
|
||
StyleRange styleRange = new StyleRange(); | ||
styleRange.start = boldStart; | ||
styleRange.length = boldLength; | ||
styleRange.fontStyle = SWT.BOLD; | ||
|
||
textArea.append(itemToShow); | ||
textArea.append("\n"); | ||
textArea.setStyleRange(styleRange); | ||
|
||
} | ||
} | ||
}); | ||
|
||
textArea.append( | ||
"Your organization controls whether suggestions include code with references. To update these settings, please contact your admin.\n"); | ||
} | ||
|
||
@Override | ||
public void setFocus() { | ||
return; | ||
} | ||
} |