Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amazonq): tutorial always showing on start #5949

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "tutorial always showing on start"
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export class InlineChatController {
await this.reset()
}

public async updateTaskAndLenses(task: InlineTask, taskState?: TaskState) {
public async updateTaskAndLenses(task?: InlineTask, taskState?: TaskState) {
if (!task) {
Copy link
Contributor

@justinmk3 justinmk3 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this possible? The parameter type is non-nullable / non-falsey.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear when this could happen. This is an attempt to fix an issue reported by a customer where I believe the logic in this function is running with a undefined task, I can not find any other codepath that would produce this error:

Screenshot 2024-11-12 at 9 09 30 AM

I can make the task optional to make this clearer at least.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make the task optional to make this clearer at least.

That is the bare minimum, yes.

The cause of this bug is likely related to the fact that task = this.task may be undefined.

await this.updateTaskAndLenses(this.task, TaskState.WaitingForDecision)

It's probably a good idea to track down the root cause, because this signals that there are other parts of the code that are forcing things (e.g. with !) that they shouldn't be forcing. Or there is unclear initialization ordering.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code still missing tests?

return
}
if (taskState) {
task.state = taskState
} else if (!task.diff || task.diff.length === 0) {
Expand Down Expand Up @@ -200,7 +203,7 @@ export class InlineChatController {
this.task = await this.createTask(query, editor.document, editor.selection)
await this.inlineLineAnnotationController.disable(editor)
await this.computeDiffAndRenderOnEditor(query, editor.document).catch(async (err) => {
getLogger().error(err)
getLogger().error('computeDiffAndRenderOnEditor error: %s', (err as Error)?.message)
if (err instanceof Error) {
void vscode.window.showErrorMessage(`Amazon Q: ${err.message}`)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function fromId(id: string | undefined): AnnotationState | undefined {
return new TryMoreExState()
case EndState.id:
return new EndState()
case InlineChatState.id:
return new InlineChatState()
default:
return undefined
}
Expand Down Expand Up @@ -201,16 +203,15 @@ export class EndState implements AnnotationState {
}

export class InlineChatState implements AnnotationState {
static static = 'amazonq_annotation_inline_chat'
id = InlineChatState.static
static id = 'amazonq_annotation_inline_chat'
id = InlineChatState.id
suppressWhileRunning = false

text = () => {
if (os.platform() === 'darwin') {
return 'Amazon Q: Edit \u2318I'
} else {
return 'Amazon Q: Edit (Ctrl+I)'
}
return 'Amazon Q: Edit (Ctrl+I)'
}
updateState(_changeSource: AnnotationChangeSource, _force: boolean): AnnotationState {
return this
Expand Down Expand Up @@ -329,6 +330,10 @@ export class LineAnnotationController implements vscode.Disposable {
return this._currentState.id === new EndState().id
}

isInlineChatHint(): boolean {
return this._currentState.id === new InlineChatState().id
}

async dismissTutorial() {
this._currentState = new EndState()
await setContext('aws.codewhisperer.tutorial.workInProgress', false)
Expand Down Expand Up @@ -467,7 +472,9 @@ export class LineAnnotationController implements vscode.Disposable {
decorationOptions.range = range

await globals.globalState.update(inlinehintKey, this._currentState.id)
await setContext('aws.codewhisperer.tutorial.workInProgress', true)
if (!this.isInlineChatHint()) {
await setContext('aws.codewhisperer.tutorial.workInProgress', true)
}
editor.setDecorations(this.cwLineHintDecoration, [decorationOptions])
}

Expand Down
Loading