-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds code reference view #29
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7e7f260
Adds code reference view
dingfeli 5747767
Adds fqfn to file being changed
dingfeli e0f8f2a
Merge branch 'main' into code-reference
dingfeli 2795967
Merge branch 'main' into code-reference
dingfeli b799397
Merge branch 'main' into code-reference
dingfeli cdf57f1
Merge branch 'main' into code-reference
dingfeli 5e7fefb
Merge branch 'main' into code-reference
dingfeli 9b80fe7
Separates model reference model types into their own class files
dingfeli ad8d4aa
Includes changes to InlineCompletionItem
dingfeli 3bbf8ed
Merge branch 'main' into code-reference
breedloj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep each class in its own file