4
4
*/
5
5
6
6
import { Commands , globals } from 'aws-core-vscode/shared'
7
- // import { window } from 'vscode'
7
+ import { window } from 'vscode'
8
8
import { AmazonQChatViewProvider } from './webviewProvider'
9
9
10
10
/**
@@ -13,21 +13,21 @@ import { AmazonQChatViewProvider } from './webviewProvider'
13
13
*/
14
14
export function registerCommands ( provider : AmazonQChatViewProvider ) {
15
15
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 ( )
23
23
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
+ } ) ,
31
31
Commands . register ( 'aws.amazonq.openTab' , ( ) => {
32
32
void focusAmazonQPanel ( ) . then ( ( ) => {
33
33
void provider . webview ?. postMessage ( {
@@ -39,36 +39,36 @@ export function registerCommands(provider: AmazonQChatViewProvider) {
39
39
)
40
40
}
41
41
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
+ }
49
49
50
- // return ' '
51
- // }
50
+ return ' '
51
+ }
52
52
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
+ }
58
58
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 ( )
63
63
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
+ }
72
72
73
73
/**
74
74
* Importing focusAmazonQPanel from aws-core-vscode/amazonq leads to several dependencies down the chain not resolving since AmazonQ chat
0 commit comments