@@ -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'
2522
@@ -56,10 +53,19 @@ export class InlineCompletionManager implements Disposable {
5653 private disposable : Disposable
5754 private inlineCompletionProvider : AmazonQInlineCompletionItemProvider
5855 private languageClient : LanguageClient
56+ private sessionManager : SessionManager
57+ private recommendationService : RecommendationService
58+ private readonly logSessionResultMessageName = 'aws/logInlineCompletionSessionResults'
5959
6060 constructor ( languageClient : LanguageClient ) {
6161 this . languageClient = languageClient
62- this . inlineCompletionProvider = new AmazonQInlineCompletionItemProvider ( languageClient )
62+ this . sessionManager = new SessionManager ( )
63+ this . recommendationService = new RecommendationService ( this . sessionManager )
64+ this . inlineCompletionProvider = new AmazonQInlineCompletionItemProvider (
65+ languageClient ,
66+ this . recommendationService ,
67+ this . sessionManager
68+ )
6369 this . disposable = languages . registerInlineCompletionItemProvider (
6470 CodewhispererInlineCompletionLanguages ,
6571 this . inlineCompletionProvider
@@ -92,16 +98,16 @@ export class InlineCompletionManager implements Disposable {
9298 totalSessionDisplayTime : Date . now ( ) - requestStartTime ,
9399 firstCompletionDisplayLatency : firstCompletionDisplayLatency ,
94100 }
95- this . languageClient . sendNotification ( logInlineCompletionSessionResultsNotificationType as any , params )
101+ this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
96102 this . disposable . dispose ( )
97103 this . disposable = languages . registerInlineCompletionItemProvider (
98104 CodewhispererInlineCompletionLanguages ,
99105 this . inlineCompletionProvider
100106 )
101107 }
102- commands . registerCommand ( 'aws.sample-vscode-ext- amazonq.accept ' , onInlineAcceptance )
108+ commands . registerCommand ( 'aws.amazonq.acceptInline ' , onInlineAcceptance )
103109
104- const oninlineRejection = async ( sessionId : string , itemId : string ) => {
110+ const onInlineRejection = async ( sessionId : string , itemId : string ) => {
105111 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
106112 // TODO: also log the seen state for other suggestions in session
107113 const params : LogInlineCompletionSessionResultsParams = {
@@ -114,39 +120,49 @@ export class InlineCompletionManager implements Disposable {
114120 } ,
115121 } ,
116122 }
117- this . languageClient . sendNotification ( logInlineCompletionSessionResultsNotificationType as any , params )
123+ this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
118124 this . disposable . dispose ( )
119125 this . disposable = languages . registerInlineCompletionItemProvider (
120126 CodewhispererInlineCompletionLanguages ,
121127 this . inlineCompletionProvider
122128 )
123129 }
124- commands . registerCommand ( 'aws.sample-vscode-ext- amazonq.reject ' , oninlineRejection )
130+ commands . registerCommand ( 'aws.amazonq.rejectInline ' , onInlineRejection )
125131
126132 /*
127133 We have to overwrite the prev. and next. commands because the inlineCompletionProvider only contained the current item
128134 To show prev. and next. recommendation we need to re-register a new provider with the previous or next item
129135 */
130136
131137 const prevCommandHandler = async ( ) => {
132- SessionManager . instance . decrementActiveIndex ( )
138+ this . sessionManager . decrementActiveIndex ( )
133139 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
134140 this . disposable . dispose ( )
135141 this . disposable = languages . registerInlineCompletionItemProvider (
136142 CodewhispererInlineCompletionLanguages ,
137- new AmazonQInlineCompletionItemProvider ( this . languageClient , false )
143+ new AmazonQInlineCompletionItemProvider (
144+ this . languageClient ,
145+ this . recommendationService ,
146+ this . sessionManager ,
147+ false
148+ )
138149 )
139150 await commands . executeCommand ( 'editor.action.inlineSuggest.trigger' )
140151 }
141152 commands . registerCommand ( 'editor.action.inlineSuggest.showPrevious' , prevCommandHandler )
142153
143154 const nextCommandHandler = async ( ) => {
144- SessionManager . instance . incrementActiveIndex ( )
155+ this . sessionManager . incrementActiveIndex ( )
145156 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
146157 this . disposable . dispose ( )
147158 this . disposable = languages . registerInlineCompletionItemProvider (
148159 CodewhispererInlineCompletionLanguages ,
149- new AmazonQInlineCompletionItemProvider ( this . languageClient , false )
160+ new AmazonQInlineCompletionItemProvider (
161+ this . languageClient ,
162+ this . recommendationService ,
163+ this . sessionManager ,
164+ false
165+ )
150166 )
151167 await commands . executeCommand ( 'editor.action.inlineSuggest.trigger' )
152168 }
@@ -157,6 +173,8 @@ export class InlineCompletionManager implements Disposable {
157173export class AmazonQInlineCompletionItemProvider implements InlineCompletionItemProvider {
158174 constructor (
159175 private readonly languageClient : LanguageClient ,
176+ private readonly recommendationService : RecommendationService ,
177+ private readonly sessionManager : SessionManager ,
160178 private readonly isNewSesion : boolean = true
161179 ) { }
162180
@@ -168,7 +186,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
168186 ) : Promise < InlineCompletionItem [ ] | InlineCompletionList > {
169187 if ( this . isNewSesion ) {
170188 // make service requests if it's a new session
171- await RecommendationService . instance . getAllRecommendations (
189+ await this . recommendationService . getAllRecommendations (
172190 this . languageClient ,
173191 document ,
174192 position ,
@@ -177,6 +195,23 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
177195 )
178196 }
179197 // get active item from session for displaying
180- return SessionManager . instance . getActiveRecommendation ( )
198+ const items = this . sessionManager . getActiveRecommendation ( )
199+ const session = this . sessionManager . getActiveSession ( )
200+ if ( ! session || ! items . length ) {
201+ return [ ]
202+ }
203+ for ( const item of items ) {
204+ item . command = {
205+ command : 'aws.amazonq.acceptInline' ,
206+ title : 'On acceptance' ,
207+ arguments : [
208+ session . sessionId ,
209+ item . itemId ,
210+ session . requestStartTime ,
211+ session . firstCompletionDisplayLatency ,
212+ ] ,
213+ }
214+ }
215+ return items as InlineCompletionItem [ ]
181216 }
182217}
0 commit comments