Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 41 additions & 41 deletions packages/amazonq/src/lsp/chat/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Commands, globals } from 'aws-core-vscode/shared'
// import { window } from 'vscode'
import { window } from 'vscode'
import { AmazonQChatViewProvider } from './webviewProvider'

/**
Expand All @@ -13,21 +13,21 @@ import { AmazonQChatViewProvider } from './webviewProvider'
*/
export function registerCommands(provider: AmazonQChatViewProvider) {
globals.context.subscriptions.push(
// registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
// registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
// registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
// registerGenericCommand('aws.amazonq.optimizeCode', 'Optimize', provider),
// Commands.register('aws.amazonq.sendToPrompt', (data) => {
// const triggerType = getCommandTriggerType(data)
// const selection = getSelectedText()
registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
registerGenericCommand('aws.amazonq.optimizeCode', 'Optimize', provider),
Commands.register('aws.amazonq.sendToPrompt', (data) => {
const triggerType = getCommandTriggerType(data)
const selection = getSelectedText()

// void focusAmazonQPanel().then(() => {
// void provider.webview?.postMessage({
// command: 'sendToPrompt',
// params: { selection: selection, triggerType },
// })
// })
// }),
void focusAmazonQPanel().then(() => {
void provider.webview?.postMessage({
command: 'sendToPrompt',
params: { selection: selection, triggerType },
})
})
}),
Commands.register('aws.amazonq.openTab', () => {
void focusAmazonQPanel().then(() => {
void provider.webview?.postMessage({
Expand All @@ -39,36 +39,36 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
)
}

// function getSelectedText(): string {
// const editor = window.activeTextEditor
// if (editor) {
// const selection = editor.selection
// const selectedText = editor.document.getText(selection)
// return selectedText
// }
function getSelectedText(): string {
const editor = window.activeTextEditor
if (editor) {
const selection = editor.selection
const selectedText = editor.document.getText(selection)
return selectedText
}

// return ' '
// }
return ' '
}

// function getCommandTriggerType(data: any): string {
// // data is undefined when commands triggered from keybinding or command palette. Currently no
// // way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
// return data === undefined ? 'hotkeys' : 'contextMenu'
// }
function getCommandTriggerType(data: any): string {
// data is undefined when commands triggered from keybinding or command palette. Currently no
// way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
return data === undefined ? 'hotkeys' : 'contextMenu'
}

// function registerGenericCommand(commandName: string, genericCommand: string, provider: AmazonQChatViewProvider) {
// return Commands.register(commandName, (data) => {
// const triggerType = getCommandTriggerType(data)
// const selection = getSelectedText()
function registerGenericCommand(commandName: string, genericCommand: string, provider: AmazonQChatViewProvider) {
return Commands.register(commandName, (data) => {
const triggerType = getCommandTriggerType(data)
const selection = getSelectedText()

// void focusAmazonQPanel().then(() => {
// void provider.webview?.postMessage({
// command: 'genericCommand',
// params: { genericCommand, selection, triggerType },
// })
// })
// })
// }
void focusAmazonQPanel().then(() => {
void provider.webview?.postMessage({
command: 'genericCommand',
params: { genericCommand, selection, triggerType },
})
})
})
}

/**
* Importing focusAmazonQPanel from aws-core-vscode/amazonq leads to several dependencies down the chain not resolving since AmazonQ chat
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codewhispererChat/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,5 @@ export function init(appContext: AmazonQAppInitContext) {

appContext.registerWebViewToAppMessagePublisher(new MessagePublisher<any>(cwChatUIInputEventEmitter), 'cwc')

registerCommands(cwChatControllerMessagePublishers)
registerCommands()
}
75 changes: 7 additions & 68 deletions packages/core/src/codewhispererChat/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { commandPalette } from '../../codewhisperer/commands/types'
import { CodeScanIssue } from '../../codewhisperer/models/model'
import { Commands, VsCodeCommandArg, placeholder } from '../../shared/vscode/commands2'
import { ChatControllerMessagePublishers } from '../controllers/chat/controller'

/**
* Opens the Amazon Q panel, showing the correct View that should
Expand Down Expand Up @@ -37,73 +36,13 @@ export const focusAmazonQPanelKeybinding = Commands.declare('_aws.amazonq.focusC
await focusAmazonQPanel.execute(placeholder, 'keybinding')
})

const getCommandTriggerType = (data: any): EditorContextCommandTriggerType => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming this fixes the double registering that was happening before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think what was happening was we were creating the commands here + the commands from commands.ts

// data is undefined when commands triggered from keybinding or command palette. Currently no
// way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
return data === undefined ? 'keybinding' : 'contextMenu'
}

export function registerCommands(controllerPublishers: ChatControllerMessagePublishers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify, these still register properly on non-hybrid chat right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is only broken for hybrid chat, everything works fine for the regular main branch

Commands.register('aws.amazonq.explainCode', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.explainCode').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.explainCode',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.refactorCode', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.refactorCode').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.refactorCode',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.fixCode', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.fixCode').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.fixCode',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.optimizeCode', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.optimizeCode').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.optimizeCode',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.sendToPrompt', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.sendToPrompt').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.sendToPrompt',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.explainIssue', async (issue) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.explainIssue').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.explainIssue',
triggerType: 'click',
issue,
})
})
})
Commands.register('aws.amazonq.generateUnitTests', async (data) => {
return focusAmazonQPanel.execute(placeholder, 'amazonq.generateUnitTests').then(() => {
controllerPublishers.processContextMenuCommand.publish({
type: 'aws.amazonq.generateUnitTests',
triggerType: getCommandTriggerType(data),
})
})
})
Commands.register('aws.amazonq.updateContextCommandItems', () => {
controllerPublishers.processContextCommandUpdateMessage.publish()
})
export function registerCommands() {
/**
* make these no-ops, since theres still callers that need to be deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these commands still exposed to the user? Should we disable them until they are hooked up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're only still enabled because other parts of the extension (like security scan) call them. In a future PR i'm going to fully deprecate them here and implement them in commands.ts but for now this just avoids spamming the logs with command not found

*/
Commands.register('aws.amazonq.explainIssue', async (issue) => {})
Commands.register('aws.amazonq.generateUnitTests', async (data) => {})
Commands.register('aws.amazonq.updateContextCommandItems', () => {})
}

export type EditorContextBaseCommandType =
Expand Down
Loading