44 */
55
66import { Commands , globals } from 'aws-core-vscode/shared'
7- // import { window } from 'vscode'
7+ import { window } from 'vscode'
88import { AmazonQChatViewProvider } from './webviewProvider'
99
1010/**
@@ -13,21 +13,21 @@ import { AmazonQChatViewProvider } from './webviewProvider'
1313 */
1414export function registerCommands ( provider : AmazonQChatViewProvider ) {
1515 globals . context . subscriptions . push (
16- // registerGenericCommand('aws.amazonq.explainCode', 'Explain', provider),
17- // registerGenericCommand('aws.amazonq.refactorCode', 'Refactor', provider),
18- // registerGenericCommand('aws.amazonq.fixCode', 'Fix', provider),
19- // registerGenericCommand('aws.amazonq.optimizeCode', 'Optimize', provider),
20- // Commands.register('aws.amazonq.sendToPrompt', (data) => {
21- // const triggerType = getCommandTriggerType(data)
22- // const selection = getSelectedText()
16+ registerGenericCommand ( 'aws.amazonq.explainCode' , 'Explain' , provider ) ,
17+ registerGenericCommand ( 'aws.amazonq.refactorCode' , 'Refactor' , provider ) ,
18+ registerGenericCommand ( 'aws.amazonq.fixCode' , 'Fix' , provider ) ,
19+ registerGenericCommand ( 'aws.amazonq.optimizeCode' , 'Optimize' , provider ) ,
20+ Commands . register ( 'aws.amazonq.sendToPrompt' , ( data ) => {
21+ const triggerType = getCommandTriggerType ( data )
22+ const selection = getSelectedText ( )
2323
24- // void focusAmazonQPanel().then(() => {
25- // void provider.webview?.postMessage({
26- // command: 'sendToPrompt',
27- // params: { selection: selection, triggerType },
28- // })
29- // })
30- // }),
24+ void focusAmazonQPanel ( ) . then ( ( ) => {
25+ void provider . webview ?. postMessage ( {
26+ command : 'sendToPrompt' ,
27+ params : { selection : selection , triggerType } ,
28+ } )
29+ } )
30+ } ) ,
3131 Commands . register ( 'aws.amazonq.openTab' , ( ) => {
3232 void focusAmazonQPanel ( ) . then ( ( ) => {
3333 void provider . webview ?. postMessage ( {
@@ -39,36 +39,36 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
3939 )
4040}
4141
42- // function getSelectedText(): string {
43- // const editor = window.activeTextEditor
44- // if (editor) {
45- // const selection = editor.selection
46- // const selectedText = editor.document.getText(selection)
47- // return selectedText
48- // }
42+ function getSelectedText ( ) : string {
43+ const editor = window . activeTextEditor
44+ if ( editor ) {
45+ const selection = editor . selection
46+ const selectedText = editor . document . getText ( selection )
47+ return selectedText
48+ }
4949
50- // return ' '
51- // }
50+ return ' '
51+ }
5252
53- // function getCommandTriggerType(data: any): string {
54- // // data is undefined when commands triggered from keybinding or command palette. Currently no
55- // // way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
56- // return data === undefined ? 'hotkeys' : 'contextMenu'
57- // }
53+ function getCommandTriggerType ( data : any ) : string {
54+ // data is undefined when commands triggered from keybinding or command palette. Currently no
55+ // way to differentiate keybinding and command palette, so both interactions are recorded as keybinding
56+ return data === undefined ? 'hotkeys' : 'contextMenu'
57+ }
5858
59- // function registerGenericCommand(commandName: string, genericCommand: string, provider: AmazonQChatViewProvider) {
60- // return Commands.register(commandName, (data) => {
61- // const triggerType = getCommandTriggerType(data)
62- // const selection = getSelectedText()
59+ function registerGenericCommand ( commandName : string , genericCommand : string , provider : AmazonQChatViewProvider ) {
60+ return Commands . register ( commandName , ( data ) => {
61+ const triggerType = getCommandTriggerType ( data )
62+ const selection = getSelectedText ( )
6363
64- // void focusAmazonQPanel().then(() => {
65- // void provider.webview?.postMessage({
66- // command: 'genericCommand',
67- // params: { genericCommand, selection, triggerType },
68- // })
69- // })
70- // })
71- // }
64+ void focusAmazonQPanel ( ) . then ( ( ) => {
65+ void provider . webview ?. postMessage ( {
66+ command : 'genericCommand' ,
67+ params : { genericCommand, selection, triggerType } ,
68+ } )
69+ } )
70+ } )
71+ }
7272
7373/**
7474 * Importing focusAmazonQPanel from aws-core-vscode/amazonq leads to several dependencies down the chain not resolving since AmazonQ chat
0 commit comments