Skip to content

Commit 2180ad8

Browse files
authored
(feat codewhisperer): inline tutorial (#4539)
* * inline hint implementation * active state indicator UI implementation * line tracker implementation * rebase of PR #4335 * cleanup and fix linter error * revert accidental added changes * update logs & send ui_click while tutorial dismissed * localize state.id * remove useless type declaration * use undefined insteadof null * add more line tracker test * revert package json * cleanup line tracker, remove unneeded async * fix not signed in but still see inlinehint * fix onDidChangeActiveEditor subscription doesn't pass editor LineTracker.ts * revert duplicate code * add back container doc string * remove prefix _ container.ts * add doc str * cleanup * try revert 1 changes breaking tests * clean * fix linter errors * move statusBarCLicked exit criteria to statusBarMenu.ts * fix linter errors * fix end state will not be persisted in some case * revert unneeded package.json change && call Container.instance insteadof injecting container into vscode declared command * revert previous changes as circular dependency * * remove function which is causing circular dependency * revert deleted package.json * fix circular dependency and bring back removed logic * remove testing logic * * fix linter * fix unreliable tests * fix not passing editor in lineTracker
1 parent eb48c5e commit 2180ad8

File tree

10 files changed

+502
-11
lines changed

10 files changed

+502
-11
lines changed

packages/core/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,12 @@
38853885
"mac": "escape",
38863886
"when": "inlineSuggestionVisible && !editorReadonly && aws.codewhisperer.connected || isCloud9 && suggestWidgetVisible && !editorReadonly"
38873887
},
3888+
{
3889+
"command": "aws.codeWhisperer.dismissTutorial",
3890+
"key": "escape",
3891+
"mac": "escape",
3892+
"when": "aws.codewhisperer.tutorial.workInProgress && !inlineSuggestionVisible && !suggestWidgetVisible"
3893+
},
38883894
{
38893895
"key": "right",
38903896
"command": "editor.action.inlineSuggest.showNext",

packages/core/src/codewhisperer/activation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ export async function activate(context: ExtContext): Promise<void> {
173173
await vscode.commands.executeCommand('workbench.action.openSettings', `aws.codeWhisperer`)
174174
}
175175
}),
176+
Commands.register('aws.codewhisperer.refreshAnnotation', async (forceProceed: boolean = false) => {
177+
const editor = vscode.window.activeTextEditor
178+
if (editor) {
179+
if (forceProceed) {
180+
await container.lineAnnotationController.refresh(editor, 'codewhisperer', true)
181+
} else {
182+
await container.lineAnnotationController.refresh(editor, 'codewhisperer')
183+
}
184+
}
185+
}),
176186
// show introduction
177187
showIntroduction.register(),
178188
// direct CodeWhisperer connection setup with customization

packages/core/src/codewhisperer/commands/onInlineAcceptance.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ImportAdderProvider } from '../service/importAdderProvider'
2929
import { session } from '../util/codeWhispererSession'
3030
import path from 'path'
3131
import { RecommendationService } from '../service/recommendationService'
32+
import { Container } from '../service/serviceContainer'
3233

3334
export const acceptSuggestion = Commands.declare(
3435
'aws.codeWhisperer.accept',
@@ -47,6 +48,7 @@ export const acceptSuggestion = Commands.declare(
4748
) => {
4849
RecommendationService.instance.incrementAcceptedCount()
4950
const editor = vscode.window.activeTextEditor
51+
await Container.instance.lineAnnotationController.refresh(editor, 'codewhisperer')
5052
const onAcceptanceFunc = isInlineCompletionEnabled() ? onInlineAcceptance : onAcceptance
5153
await onAcceptanceFunc(
5254
{

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ export const persistedCustomizationsKey = 'CODEWHISPERER_PERSISTED_CUSTOMIZATION
143143

144144
export const selectedCustomizationKey = 'CODEWHISPERER_SELECTED_CUSTOMIZATION'
145145

146+
export const inlinehintKey = 'CODEWHISPERER_HINT_DISPLAYED'
147+
148+
export const inlinehintWipKey = 'aws.codewhisperer.tutorial.workInProgress'
149+
150+
export type AnnotationChangeSource = 'codewhisperer' | 'selection' | 'editor' | 'content'
151+
146152
export const learnMoreUriGeneral = 'https://aws.amazon.com/codewhisperer/'
147153

148154
export const learnMoreUri = 'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/codewhisperer.html'

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const nextCommand = Commands.declare('editor.action.inlineSuggest.showNext', ()
6262

6363
const rejectCommand = Commands.declare('aws.codeWhisperer.rejectCodeSuggestion', () => async () => {
6464
RecommendationHandler.instance.reportUserDecisions(-1)
65+
66+
await Commands.tryExecute('aws.codewhisperer.refreshAnnotation')
6567
})
6668

6769
const lock = new AsyncLock({ maxPending: 1 })

packages/core/src/codewhisperer/service/serviceContainer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { AuthUtil } from '../util/authUtil'
7+
import { LineAnnotationController } from '../views/lineAnnotationController'
78
import { ActiveStateController } from '../views/activeStateController'
89
import { LineTracker } from '../tracker/lineTracker'
910

@@ -28,10 +29,12 @@ export class Container {
2829
}
2930

3031
readonly lineTracker: LineTracker
32+
readonly lineAnnotationController: LineAnnotationController
3133
readonly activeStateController: ActiveStateController
3234

3335
protected constructor(readonly auth: AuthUtil) {
3436
this.lineTracker = new LineTracker()
37+
this.lineAnnotationController = new LineAnnotationController(this)
3538
this.activeStateController = new ActiveStateController(this)
3639
}
3740

packages/core/src/codewhisperer/tracker/lineTracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class LineTracker implements vscode.Disposable {
4949
constructor() {
5050
this._disposable = vscode.Disposable.from(
5151
vscode.window.onDidChangeActiveTextEditor(async e => {
52-
await this.onActiveTextEditorChanged(undefined)
52+
await this.onActiveTextEditorChanged(e)
5353
}),
5454
vscode.window.onDidChangeTextEditorSelection(async e => {
5555
await this.onTextEditorSelectionChanged(e)

packages/core/src/codewhisperer/ui/statusBarMenu.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { createExitButton } from '../../shared/ui/buttons'
2929
import { isWeb } from '../../common/webUtils'
3030
import { telemetry } from '../../shared/telemetry/telemetry'
3131
import { once } from '../../shared/utilities/functionUtils'
32+
import { getLogger } from '../../shared/logger'
3233

3334
function getAmazonQCodeWhispererNodes() {
3435
const autoTriggerEnabled = CodeSuggestionsState.instance.isSuggestionsEnabled()
@@ -101,6 +102,13 @@ export function getQuickPickItems(): DataQuickPickItem<string>[] {
101102
export const listCodeWhispererCommandsId = 'aws.codewhisperer.listCommands'
102103
export const listCodeWhispererCommands = Commands.declare({ id: listCodeWhispererCommandsId }, () => () => {
103104
once(() => telemetry.ui_click.emit({ elementId: 'cw_statusBarMenu' }))()
105+
Commands.tryExecute('aws.codewhisperer.refreshAnnotation', true)
106+
.then()
107+
.catch(e => {
108+
getLogger().debug(
109+
`codewhisperer: running into error while executing command { refreshAnnotation } on user clicking statusbar: ${e}`
110+
)
111+
})
104112
return createQuickPick(getQuickPickItems(), {
105113
title: 'Amazon Q (Preview) + CodeWhisperer',
106114
buttons: [createExitButton()],

0 commit comments

Comments
 (0)