Skip to content

Commit 0d2c7fb

Browse files
authored
feat(amazonq): add tutorial trackers for lsp (#7264)
## Problem the tutorial trackers aren't implemented when using the language server ## Solution - re-add the inlineLineAnnotationController (inlineChatTutorialAnnotation) for adding hints with inline chat - re-add the lineAnnotationController (inlineTutorialAnnotation) for adding the inline suggestions tutorial ## Notes in a future PR I'll fully deprecate the old trackers --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent c77668d commit 0d2c7fb

File tree

9 files changed

+668
-52
lines changed

9 files changed

+668
-52
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from 'aws-core-vscode/codewhisperer'
3636
import { InlineGeneratingMessage } from './inlineGeneratingMessage'
3737
import { LineTracker } from './stateTracker/lineTracker'
38+
import { InlineTutorialAnnotation } from './tutorials/inlineTutorialAnnotation'
3839

3940
export class InlineCompletionManager implements Disposable {
4041
private disposable: Disposable
@@ -43,19 +44,27 @@ export class InlineCompletionManager implements Disposable {
4344
private sessionManager: SessionManager
4445
private recommendationService: RecommendationService
4546
private lineTracker: LineTracker
46-
private activeStateTracker: InlineGeneratingMessage
47+
private incomingGeneratingMessage: InlineGeneratingMessage
48+
private inlineTutorialAnnotation: InlineTutorialAnnotation
4749
private readonly logSessionResultMessageName = 'aws/logInlineCompletionSessionResults'
4850

49-
constructor(languageClient: LanguageClient) {
51+
constructor(
52+
languageClient: LanguageClient,
53+
sessionManager: SessionManager,
54+
lineTracker: LineTracker,
55+
inlineTutorialAnnotation: InlineTutorialAnnotation
56+
) {
5057
this.languageClient = languageClient
51-
this.sessionManager = new SessionManager()
52-
this.lineTracker = new LineTracker()
53-
this.activeStateTracker = new InlineGeneratingMessage(this.lineTracker)
54-
this.recommendationService = new RecommendationService(this.sessionManager, this.activeStateTracker)
58+
this.sessionManager = sessionManager
59+
this.lineTracker = lineTracker
60+
this.incomingGeneratingMessage = new InlineGeneratingMessage(this.lineTracker)
61+
this.recommendationService = new RecommendationService(this.sessionManager, this.incomingGeneratingMessage)
62+
this.inlineTutorialAnnotation = inlineTutorialAnnotation
5563
this.inlineCompletionProvider = new AmazonQInlineCompletionItemProvider(
5664
languageClient,
5765
this.recommendationService,
58-
this.sessionManager
66+
this.sessionManager,
67+
this.inlineTutorialAnnotation
5968
)
6069
this.disposable = languages.registerInlineCompletionItemProvider(
6170
CodeWhispererConstants.platformLanguageIds,
@@ -68,7 +77,7 @@ export class InlineCompletionManager implements Disposable {
6877
public dispose(): void {
6978
if (this.disposable) {
7079
this.disposable.dispose()
71-
this.activeStateTracker.dispose()
80+
this.incomingGeneratingMessage.dispose()
7281
this.lineTracker.dispose()
7382
}
7483
}
@@ -113,6 +122,7 @@ export class InlineCompletionManager implements Disposable {
113122
if (item.mostRelevantMissingImports?.length) {
114123
await ImportAdderProvider.instance.onAcceptRecommendation(editor, item, startLine)
115124
}
125+
this.sessionManager.incrementSuggestionCount()
116126
}
117127
commands.registerCommand('aws.amazonq.acceptInline', onInlineAcceptance)
118128

@@ -157,6 +167,7 @@ export class InlineCompletionManager implements Disposable {
157167
this.languageClient,
158168
this.recommendationService,
159169
this.sessionManager,
170+
this.inlineTutorialAnnotation,
160171
false
161172
)
162173
)
@@ -182,6 +193,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
182193
private readonly languageClient: LanguageClient,
183194
private readonly recommendationService: RecommendationService,
184195
private readonly sessionManager: SessionManager,
196+
private readonly inlineTutorialAnnotation: InlineTutorialAnnotation,
185197
private readonly isNewSession: boolean = true
186198
) {}
187199

@@ -198,6 +210,9 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
198210
return []
199211
}
200212

213+
// tell the tutorial that completions has been triggered
214+
await this.inlineTutorialAnnotation.triggered(context.triggerKind)
215+
201216
// make service requests if it's a new session
202217
await this.recommendationService.getAllRecommendations(
203218
this.languageClient,

packages/amazonq/src/app/inline/sessionManager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface CodeWhispererSession {
1818
export class SessionManager {
1919
private activeSession?: CodeWhispererSession
2020
private activeIndex: number = 0
21+
private _acceptedSuggestionCount: number = 0
22+
2123
constructor() {}
2224

2325
public startSession(
@@ -95,6 +97,14 @@ export class SessionManager {
9597
return items
9698
}
9799

100+
public get acceptedSuggestionCount(): number {
101+
return this._acceptedSuggestionCount
102+
}
103+
104+
public incrementSuggestionCount() {
105+
this._acceptedSuggestionCount += 1
106+
}
107+
98108
public clear() {
99109
this.activeSession = undefined
100110
this.activeIndex = 0

packages/amazonq/src/inlineChat/decorations/inlineLineAnnotationController.ts renamed to packages/amazonq/src/app/inline/tutorials/inlineChatTutorialAnnotation.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Container } from 'aws-core-vscode/codewhisperer'
76
import * as vscode from 'vscode'
7+
import { InlineTutorialAnnotation } from './inlineTutorialAnnotation'
8+
import { globals } from 'aws-core-vscode/shared'
89

9-
export class InlineLineAnnotationController {
10+
export class InlineChatTutorialAnnotation {
1011
private enabled: boolean = true
1112

12-
constructor(context: vscode.ExtensionContext) {
13-
context.subscriptions.push(
13+
constructor(private readonly inlineTutorialAnnotation: InlineTutorialAnnotation) {
14+
globals.context.subscriptions.push(
1415
vscode.window.onDidChangeTextEditorSelection(async ({ selections, textEditor }) => {
1516
let showShow = false
1617

@@ -33,12 +34,12 @@ export class InlineLineAnnotationController {
3334
private async setVisible(editor: vscode.TextEditor, visible: boolean) {
3435
let needsRefresh: boolean
3536
if (visible) {
36-
needsRefresh = await Container.instance.lineAnnotationController.tryShowInlineHint()
37+
needsRefresh = await this.inlineTutorialAnnotation.tryShowInlineHint()
3738
} else {
38-
needsRefresh = await Container.instance.lineAnnotationController.tryHideInlineHint()
39+
needsRefresh = await this.inlineTutorialAnnotation.tryHideInlineHint()
3940
}
4041
if (needsRefresh) {
41-
await Container.instance.lineAnnotationController.refresh(editor, 'codewhisperer')
42+
await this.inlineTutorialAnnotation.refresh(editor, 'codewhisperer')
4243
}
4344
}
4445

0 commit comments

Comments
 (0)