@@ -16,10 +16,7 @@ import {
1616 Disposable ,
1717} from 'vscode'
1818import { LanguageClient } from 'vscode-languageclient'
19- import {
20- logInlineCompletionSessionResultsNotificationType ,
21- LogInlineCompletionSessionResultsParams ,
22- } from '@aws/language-server-runtimes/protocol'
19+ import { LogInlineCompletionSessionResultsParams } from '@aws/language-server-runtimes/protocol'
2320import { SessionManager } from './sessionManager'
2421import { RecommendationService } from './recommendationService'
2522import { CodeWhispererConstants } from 'aws-core-vscode/codewhisperer'
@@ -28,10 +25,19 @@ export class InlineCompletionManager implements Disposable {
2825 private disposable : Disposable
2926 private inlineCompletionProvider : AmazonQInlineCompletionItemProvider
3027 private languageClient : LanguageClient
28+ private sessionManager : SessionManager
29+ private recommendationService : RecommendationService
30+ private readonly logSessionResultMessageName = 'aws/logInlineCompletionSessionResults'
3131
3232 constructor ( languageClient : LanguageClient ) {
3333 this . languageClient = languageClient
34- this . inlineCompletionProvider = new AmazonQInlineCompletionItemProvider ( languageClient )
34+ this . sessionManager = new SessionManager ( )
35+ this . recommendationService = new RecommendationService ( this . sessionManager )
36+ this . inlineCompletionProvider = new AmazonQInlineCompletionItemProvider (
37+ languageClient ,
38+ this . recommendationService ,
39+ this . sessionManager
40+ )
3541 this . disposable = languages . registerInlineCompletionItemProvider (
3642 CodeWhispererConstants . platformLanguageIds ,
3743 this . inlineCompletionProvider
@@ -64,16 +70,16 @@ export class InlineCompletionManager implements Disposable {
6470 totalSessionDisplayTime : Date . now ( ) - requestStartTime ,
6571 firstCompletionDisplayLatency : firstCompletionDisplayLatency ,
6672 }
67- this . languageClient . sendNotification ( logInlineCompletionSessionResultsNotificationType as any , params )
73+ this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
6874 this . disposable . dispose ( )
6975 this . disposable = languages . registerInlineCompletionItemProvider (
7076 CodeWhispererConstants . platformLanguageIds ,
7177 this . inlineCompletionProvider
7278 )
7379 }
74- commands . registerCommand ( 'aws.sample-vscode-ext- amazonq.accept ' , onInlineAcceptance )
80+ commands . registerCommand ( 'aws.amazonq.acceptInline ' , onInlineAcceptance )
7581
76- const oninlineRejection = async ( sessionId : string , itemId : string ) => {
82+ const onInlineRejection = async ( sessionId : string , itemId : string ) => {
7783 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
7884 // TODO: also log the seen state for other suggestions in session
7985 const params : LogInlineCompletionSessionResultsParams = {
@@ -86,39 +92,49 @@ export class InlineCompletionManager implements Disposable {
8692 } ,
8793 } ,
8894 }
89- this . languageClient . sendNotification ( logInlineCompletionSessionResultsNotificationType as any , params )
95+ this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
9096 this . disposable . dispose ( )
9197 this . disposable = languages . registerInlineCompletionItemProvider (
9298 CodeWhispererConstants . platformLanguageIds ,
9399 this . inlineCompletionProvider
94100 )
95101 }
96- commands . registerCommand ( 'aws.sample-vscode-ext- amazonq.reject ' , oninlineRejection )
102+ commands . registerCommand ( 'aws.amazonq.rejectInline ' , onInlineRejection )
97103
98104 /*
99105 We have to overwrite the prev. and next. commands because the inlineCompletionProvider only contained the current item
100106 To show prev. and next. recommendation we need to re-register a new provider with the previous or next item
101107 */
102108
103109 const prevCommandHandler = async ( ) => {
104- SessionManager . instance . decrementActiveIndex ( )
110+ this . sessionManager . decrementActiveIndex ( )
105111 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
106112 this . disposable . dispose ( )
107113 this . disposable = languages . registerInlineCompletionItemProvider (
108114 CodeWhispererConstants . platformLanguageIds ,
109- new AmazonQInlineCompletionItemProvider ( this . languageClient , false )
115+ new AmazonQInlineCompletionItemProvider (
116+ this . languageClient ,
117+ this . recommendationService ,
118+ this . sessionManager ,
119+ false
120+ )
110121 )
111122 await commands . executeCommand ( 'editor.action.inlineSuggest.trigger' )
112123 }
113124 commands . registerCommand ( 'editor.action.inlineSuggest.showPrevious' , prevCommandHandler )
114125
115126 const nextCommandHandler = async ( ) => {
116- SessionManager . instance . incrementActiveIndex ( )
127+ this . sessionManager . incrementActiveIndex ( )
117128 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
118129 this . disposable . dispose ( )
119130 this . disposable = languages . registerInlineCompletionItemProvider (
120131 CodeWhispererConstants . platformLanguageIds ,
121- new AmazonQInlineCompletionItemProvider ( this . languageClient , false )
132+ new AmazonQInlineCompletionItemProvider (
133+ this . languageClient ,
134+ this . recommendationService ,
135+ this . sessionManager ,
136+ false
137+ )
122138 )
123139 await commands . executeCommand ( 'editor.action.inlineSuggest.trigger' )
124140 }
@@ -129,6 +145,8 @@ export class InlineCompletionManager implements Disposable {
129145export class AmazonQInlineCompletionItemProvider implements InlineCompletionItemProvider {
130146 constructor (
131147 private readonly languageClient : LanguageClient ,
148+ private readonly recommendationService : RecommendationService ,
149+ private readonly sessionManager : SessionManager ,
132150 private readonly isNewSesion : boolean = true
133151 ) { }
134152
@@ -140,7 +158,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
140158 ) : Promise < InlineCompletionItem [ ] | InlineCompletionList > {
141159 if ( this . isNewSesion ) {
142160 // make service requests if it's a new session
143- await RecommendationService . instance . getAllRecommendations (
161+ await this . recommendationService . getAllRecommendations (
144162 this . languageClient ,
145163 document ,
146164 position ,
@@ -149,6 +167,23 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
149167 )
150168 }
151169 // get active item from session for displaying
152- return SessionManager . instance . getActiveRecommendation ( )
170+ const items = this . sessionManager . getActiveRecommendation ( )
171+ const session = this . sessionManager . getActiveSession ( )
172+ if ( ! session || ! items . length ) {
173+ return [ ]
174+ }
175+ for ( const item of items ) {
176+ item . command = {
177+ command : 'aws.amazonq.acceptInline' ,
178+ title : 'On acceptance' ,
179+ arguments : [
180+ session . sessionId ,
181+ item . itemId ,
182+ session . requestStartTime ,
183+ session . firstCompletionDisplayLatency ,
184+ ] ,
185+ }
186+ }
187+ return items as InlineCompletionItem [ ]
153188 }
154189}
0 commit comments