Skip to content

Commit 260fb37

Browse files
authored
Merge pull request #7272 from nkomonen-amazon/spinningStatusBar
There was a regression that appeared while doing the port to flare where the status bar would not show the spinning icon when generating a suggestion. Now we will show the spinning symbol when generating a suggestion. Additionally the file was more appropriately named since it now only has the status bar related code.
2 parents 0d2c7fb + dd3b829 commit 260fb37

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

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

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CancellationToken, InlineCompletionContext, Position, TextDocument } fr
1212
import { LanguageClient } from 'vscode-languageclient'
1313
import { SessionManager } from './sessionManager'
1414
import { InlineGeneratingMessage } from './inlineGeneratingMessage'
15+
import { CodeWhispererStatusBarManager } from 'aws-core-vscode/codewhisperer'
1516

1617
export class RecommendationService {
1718
constructor(
@@ -34,34 +35,41 @@ export class RecommendationService {
3435
context,
3536
}
3637
const requestStartTime = Date.now()
38+
const statusBar = CodeWhispererStatusBarManager.instance
3739

38-
await this.inlineGeneratingMessage.showGenerating(context.triggerKind)
40+
try {
41+
// Show UI indicators that we are generating suggestions
42+
await this.inlineGeneratingMessage.showGenerating(context.triggerKind)
43+
await statusBar.setLoading()
3944

40-
// Handle first request
41-
const firstResult: InlineCompletionListWithReferences = await languageClient.sendRequest(
42-
inlineCompletionWithReferencesRequestType as any,
43-
request,
44-
token
45-
)
45+
// Handle first request
46+
const firstResult: InlineCompletionListWithReferences = await languageClient.sendRequest(
47+
inlineCompletionWithReferencesRequestType as any,
48+
request,
49+
token
50+
)
4651

47-
const firstCompletionDisplayLatency = Date.now() - requestStartTime
48-
this.sessionManager.startSession(
49-
firstResult.sessionId,
50-
firstResult.items,
51-
requestStartTime,
52-
firstCompletionDisplayLatency
53-
)
52+
const firstCompletionDisplayLatency = Date.now() - requestStartTime
53+
this.sessionManager.startSession(
54+
firstResult.sessionId,
55+
firstResult.items,
56+
requestStartTime,
57+
firstCompletionDisplayLatency
58+
)
5459

55-
if (firstResult.partialResultToken) {
56-
// If there are more results to fetch, handle them in the background
57-
this.processRemainingRequests(languageClient, request, firstResult, token).catch((error) => {
58-
languageClient.warn(`Error when getting suggestions: ${error}`)
59-
})
60-
} else {
61-
this.sessionManager.closeSession()
60+
if (firstResult.partialResultToken) {
61+
// If there are more results to fetch, handle them in the background
62+
this.processRemainingRequests(languageClient, request, firstResult, token).catch((error) => {
63+
languageClient.warn(`Error when getting suggestions: ${error}`)
64+
})
65+
} else {
66+
this.sessionManager.closeSession()
67+
}
68+
} finally {
69+
// Remove all UI indicators of message generation since we are done
70+
this.inlineGeneratingMessage.hideGenerating()
71+
void statusBar.refreshStatusBar() // effectively "stop loading"
6272
}
63-
64-
this.inlineGeneratingMessage.hideGenerating()
6573
}
6674

6775
private async processRemainingRequests(

packages/core/src/codewhisperer/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import {
6262
} from './service/diagnosticsProvider'
6363
import { SecurityPanelViewProvider, openEditorAtRange } from './views/securityPanelViewProvider'
6464
import { Commands, registerCommandErrorHandler, registerDeclaredCommands } from '../shared/vscode/commands2'
65-
import { refreshStatusBar } from './service/inlineCompletionService'
65+
import { refreshStatusBar } from './service/statusBar'
6666
import { AuthUtil } from './util/authUtil'
6767
import { ImportAdderProvider } from './service/importAdderProvider'
6868
import { openUrl } from '../shared/utilities/vsCodeUtils'

packages/core/src/codewhisperer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export {
3636
codeWhispererClient,
3737
} from './client/codewhisperer'
3838
export { listCodeWhispererCommands, listCodeWhispererCommandsId } from './ui/statusBarMenu'
39-
export { refreshStatusBar, CodeWhispererStatusBar } from './service/inlineCompletionService'
39+
export { refreshStatusBar, CodeWhispererStatusBarManager } from './service/statusBar'
4040
export { SecurityIssueHoverProvider } from './service/securityIssueHoverProvider'
4141
export { SecurityIssueCodeActionProvider } from './service/securityIssueCodeActionProvider'
4242
export {

packages/core/src/codewhisperer/service/inlineCompletionService.ts renamed to packages/core/src/codewhisperer/service/statusBar.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { codicon, getIcon } from '../../shared/icons'
1010
import { Commands } from '../../shared/vscode/commands2'
1111
import { listCodeWhispererCommandsId } from '../ui/statusBarMenu'
1212

13-
export class InlineCompletionService {
13+
export class CodeWhispererStatusBarManager {
1414
private statusBar: CodeWhispererStatusBar
1515

1616
constructor(statusBar: CodeWhispererStatusBar = CodeWhispererStatusBar.instance) {
@@ -21,7 +21,7 @@ export class InlineCompletionService {
2121
})
2222
}
2323

24-
static #instance: InlineCompletionService
24+
static #instance: CodeWhispererStatusBarManager
2525

2626
public static get instance() {
2727
return (this.#instance ??= new this())
@@ -41,6 +41,17 @@ export class InlineCompletionService {
4141
}
4242
}
4343

44+
/**
45+
* Sets the status bar in to a "loading state", effectively showing
46+
* the spinning circle.
47+
*
48+
* When loading is done, call {@link refreshStatusBar} to update the
49+
* status bar to the latest state.
50+
*/
51+
async setLoading(): Promise<void> {
52+
await this.setState('loading')
53+
}
54+
4455
private async setState(state: keyof typeof states) {
4556
switch (state) {
4657
case 'loading': {
@@ -76,7 +87,7 @@ const states = {
7687
needsProfile: 'needsProfile',
7788
} as const
7889

79-
export class CodeWhispererStatusBar {
90+
class CodeWhispererStatusBar {
8091
protected statusBar: vscode.StatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1)
8192

8293
static #instance: CodeWhispererStatusBar
@@ -127,10 +138,10 @@ export class CodeWhispererStatusBar {
127138
}
128139
}
129140

130-
/** In this module due to circulare dependency issues */
141+
/** In this module due to circular dependency issues */
131142
export const refreshStatusBar = Commands.declare(
132143
{ id: 'aws.amazonq.refreshStatusBar', logging: false },
133144
() => async () => {
134-
await InlineCompletionService.instance.refreshStatusBar()
145+
await CodeWhispererStatusBarManager.instance.refreshStatusBar()
135146
}
136147
)

packages/core/src/test/codewhisperer/commands/basicCommands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { waitUntil } from '../../../shared/utilities/timeoutUtils'
5656
import { listCodeWhispererCommands } from '../../../codewhisperer/ui/statusBarMenu'
5757
import { CodeScanIssue, CodeScansState, CodeSuggestionsState, codeScanState } from '../../../codewhisperer/models/model'
5858
import { cwQuickPickSource } from '../../../codewhisperer/commands/types'
59-
import { refreshStatusBar } from '../../../codewhisperer/service/inlineCompletionService'
59+
import { refreshStatusBar } from '../../../codewhisperer/service/statusBar'
6060
import { focusAmazonQPanel } from '../../../codewhispererChat/commands/registerCommands'
6161
import * as diagnosticsProvider from '../../../codewhisperer/service/diagnosticsProvider'
6262
import { randomUUID } from '../../../shared/crypto'

0 commit comments

Comments
 (0)