-
Notifications
You must be signed in to change notification settings - Fork 437
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
feat(amazonq): enable code actions for awesome lightbulb #5620
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "Feature", | ||
"description": "feat(amazonq): enable code actions for awesome lightbulb" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as vscode from 'vscode' | ||
|
||
export class CodeActions implements vscode.CodeActionProvider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that there is a app/chat/ for application code for AmazonQ. If this CodeActions module is generally useful for all Q features, it could live in Or it could live in The main point is that the top-level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Will review |
||
public static readonly providedCodeActionKinds = [ | ||
vscode.CodeActionKind.QuickFix, | ||
vscode.CodeActionKind.RefactorRewrite, | ||
vscode.CodeActionKind.Empty, | ||
] | ||
|
||
private suffix: string = 'using Amazon Q' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be parametrized as well so that the code can be shared by Amazon Q and Toolkits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a preference as to where to add |
||
|
||
private commands: Map<string, { title: string; kind: vscode.CodeActionKind }> = new Map< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create an abstract class (or a common class) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. We can itemize as a fast follow |
||
string, | ||
{ title: string; kind: vscode.CodeActionKind } | ||
>([ | ||
['aws.amazonq.explainCode', { title: `Explain ${this.suffix}`, kind: vscode.CodeActionKind.Empty }], | ||
['aws.amazonq.refactorCode', { title: `Refactor ${this.suffix}`, kind: vscode.CodeActionKind.RefactorRewrite }], | ||
['aws.amazonq.fixCode', { title: `Fix ${this.suffix}`, kind: vscode.CodeActionKind.QuickFix }], | ||
['aws.amazonq.optimizeCode', { title: `Optimize ${this.suffix}`, kind: vscode.CodeActionKind.RefactorRewrite }], | ||
[ | ||
'aws.amazonq.sendToPrompt', | ||
{ title: `Add selection to ${this.suffix} prompt`, kind: vscode.CodeActionKind.Empty }, | ||
], | ||
]) | ||
|
||
provideCodeActions(): vscode.CodeAction[] { | ||
const editor = vscode.window.activeTextEditor | ||
if (!editor) { | ||
return [] | ||
} | ||
|
||
const selectedText = editor.document.getText(editor.selection) | ||
if (!selectedText) { | ||
return [] | ||
} | ||
|
||
const codeActions: vscode.CodeAction[] = [] | ||
|
||
this.commands.forEach(({ title, kind }, command) => { | ||
codeActions.push(this.createCodeAction(command, title, kind, selectedText)) | ||
}) | ||
|
||
return codeActions | ||
} | ||
|
||
private createCodeAction( | ||
command: string, | ||
title: string, | ||
kind: vscode.CodeActionKind, | ||
selectedText: string, | ||
isPreferred = false | ||
): vscode.CodeAction { | ||
const action = new vscode.CodeAction(title, kind) | ||
action.command = { | ||
command, | ||
title, | ||
arguments: [selectedText], | ||
} | ||
action.isPreferred = isPreferred | ||
return action | ||
} | ||
} |
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.
Thanks for including a changelog. Please review the changelog guidelines. Is this the most meaningful thing we can say about this improvement for customers that will be interested in it?