Skip to content

Commit b3bb083

Browse files
authored
fix(codewhisperer): line tracker infinite loop when focus is on OUTPUT/LOGS #4591
Problem: `LineTracker` is subscribing `vscode.TextDocumentChangeEvent` and VSCode will also fire the above event when the plugin is adding new entry of logs. Therefore when user's focus is at log file, the following events will happen in order 1. VSCode `onContentChanged` 2. `LineTracker` emits events to update CWSPR UI components 3. `ActiveStateController.refresh()` & `LineAnnotationController.refresh()` 4. `refresh()` invoke `isConnectionValid()`, which will add logs 5. back to step (1)
1 parent ad1ff8f commit b3bb083

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeWhisperer: Infinite loop of logging if users' editor focus is on OUTPUT tab"
4+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ export class LineTracker implements vscode.Disposable {
115115

116116
// @VisibleForTesting
117117
onContentChanged(e: vscode.TextDocumentChangeEvent) {
118-
if (e.document === vscode.window.activeTextEditor?.document && e.contentChanges.length > 0) {
119-
this._editor = vscode.window.activeTextEditor
118+
const editor = vscode.window.activeTextEditor
119+
if (e.document === editor?.document && e.contentChanges.length > 0 && isTextEditor(editor)) {
120+
this._editor = editor
120121
this._selections = toLineSelections(this._editor?.selections)
121122

122123
this.notifyLinesChanged('content')

packages/core/src/codewhisperer/views/activeStateController.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ export class ActiveStateController implements vscode.Disposable {
114114
}, 1000)
115115

116116
private async _refresh(editor: vscode.TextEditor | undefined, shouldDisplay?: boolean) {
117-
if (!this.container.auth.isConnectionValid()) {
118-
this.clear(this._editor)
119-
return
120-
}
121-
122117
if (!editor && !this._editor) {
123118
return
124119
}
@@ -140,6 +135,11 @@ export class ActiveStateController implements vscode.Disposable {
140135
return
141136
}
142137

138+
if (!this.container.auth.isConnectionValid()) {
139+
this.clear(this._editor)
140+
return
141+
}
142+
143143
if (shouldDisplay !== undefined) {
144144
await this.updateDecorations(editor, selections, shouldDisplay)
145145
} else {

packages/core/src/codewhisperer/views/lineAnnotationController.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ export class LineAnnotationController implements vscode.Disposable {
327327
return
328328
}
329329

330-
if (!this.container.auth.isConnectionValid()) {
331-
this.clear()
332-
return
333-
}
334-
335330
if (this.isTutorialDone()) {
336331
this.clear()
337332
return
@@ -360,6 +355,11 @@ export class LineAnnotationController implements vscode.Disposable {
360355
return
361356
}
362357

358+
if (!this.container.auth.isConnectionValid()) {
359+
this.clear()
360+
return
361+
}
362+
363363
await this.updateDecorations(editor, selections, source, force)
364364
}
365365

0 commit comments

Comments
 (0)