Skip to content

Commit bf50433

Browse files
authored
fix(amazonq): fix the status bar duplication (#7995)
## Problem ## Solution --- - 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 e45f2c7 commit bf50433

File tree

1 file changed

+5
-106
lines changed

1 file changed

+5
-106
lines changed

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

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@ import { TelemetryHelper } from '../util/telemetryHelper'
1414
import { AuthUtil } from '../util/authUtil'
1515
import { shared } from '../../shared/utilities/functionUtils'
1616
import { ClassifierTrigger } from './classifierTrigger'
17-
import { getSelectedCustomization } from '../util/customizationUtil'
18-
import { codicon, getIcon } from '../../shared/icons'
1917
import { session } from '../util/codeWhispererSession'
2018
import { noSuggestions } from '../models/constants'
21-
import { listCodeWhispererCommandsId } from '../ui/statusBarMenu'
19+
import { CodeWhispererStatusBarManager } from './statusBar'
2220

2321
export class InlineCompletionService {
2422
private maxPage = 100
25-
private statusBar: CodeWhispererStatusBar
23+
private statusBar: CodeWhispererStatusBarManager
2624
private _showRecommendationTimer?: NodeJS.Timer
2725

28-
constructor(statusBar: CodeWhispererStatusBar = CodeWhispererStatusBar.instance) {
26+
constructor(statusBar: CodeWhispererStatusBarManager = CodeWhispererStatusBarManager.instance) {
2927
this.statusBar = statusBar
3028

3129
RecommendationHandler.instance.onDidReceiveRecommendation((e) => {
3230
this.startShowRecommendationTimer()
3331
})
3432

3533
CodeSuggestionsState.instance.onDidChangeState(() => {
36-
return this.refreshStatusBar()
34+
return this.statusBar.refreshStatusBar()
3735
})
3836
}
3937

@@ -109,7 +107,7 @@ export class InlineCompletionService {
109107
}
110108
}
111109

112-
await this.setState('loading')
110+
await this.statusBar.setLoading()
113111

114112
RecommendationHandler.instance.checkAndResetCancellationTokens()
115113
RecommendationHandler.instance.documentUri = editor.document.uri
@@ -162,103 +160,4 @@ export class InlineCompletionService {
162160
recommendationCount: session.recommendations.length,
163161
}
164162
}
165-
166-
/** Updates the status bar to represent the latest CW state */
167-
refreshStatusBar() {
168-
if (AuthUtil.instance.isConnectionValid()) {
169-
if (AuthUtil.instance.requireProfileSelection()) {
170-
return this.setState('needsProfile')
171-
}
172-
return this.setState('ok')
173-
} else if (AuthUtil.instance.isConnectionExpired()) {
174-
return this.setState('expired')
175-
} else {
176-
return this.setState('notConnected')
177-
}
178-
}
179-
180-
private async setState(state: keyof typeof states) {
181-
switch (state) {
182-
case 'loading': {
183-
await this.statusBar.setState('loading')
184-
break
185-
}
186-
case 'ok': {
187-
await this.statusBar.setState('ok', CodeSuggestionsState.instance.isSuggestionsEnabled())
188-
break
189-
}
190-
case 'expired': {
191-
await this.statusBar.setState('expired')
192-
break
193-
}
194-
case 'notConnected': {
195-
await this.statusBar.setState('notConnected')
196-
break
197-
}
198-
case 'needsProfile': {
199-
await this.statusBar.setState('needsProfile')
200-
break
201-
}
202-
}
203-
}
204-
}
205-
206-
/** The states that the completion service can be in */
207-
const states = {
208-
loading: 'loading',
209-
ok: 'ok',
210-
expired: 'expired',
211-
notConnected: 'notConnected',
212-
needsProfile: 'needsProfile',
213-
} as const
214-
215-
export class CodeWhispererStatusBar {
216-
protected statusBar: vscode.StatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1)
217-
218-
static #instance: CodeWhispererStatusBar
219-
static get instance() {
220-
return (this.#instance ??= new this())
221-
}
222-
223-
protected constructor() {}
224-
225-
async setState(state: keyof Omit<typeof states, 'ok'>): Promise<void>
226-
async setState(status: keyof Pick<typeof states, 'ok'>, isSuggestionsEnabled: boolean): Promise<void>
227-
async setState(status: keyof typeof states, isSuggestionsEnabled?: boolean): Promise<void> {
228-
const statusBar = this.statusBar
229-
statusBar.command = listCodeWhispererCommandsId
230-
statusBar.backgroundColor = undefined
231-
232-
const title = 'Amazon Q'
233-
switch (status) {
234-
case 'loading': {
235-
const selectedCustomization = getSelectedCustomization()
236-
statusBar.text = codicon` ${getIcon('vscode-loading~spin')} ${title}${
237-
selectedCustomization.arn === '' ? '' : ` | ${selectedCustomization.name}`
238-
}`
239-
break
240-
}
241-
case 'ok': {
242-
const selectedCustomization = getSelectedCustomization()
243-
const icon = isSuggestionsEnabled ? getIcon('vscode-debug-start') : getIcon('vscode-debug-pause')
244-
statusBar.text = codicon`${icon} ${title}${
245-
selectedCustomization.arn === '' ? '' : ` | ${selectedCustomization.name}`
246-
}`
247-
break
248-
}
249-
250-
case 'expired': {
251-
statusBar.text = codicon` ${getIcon('vscode-debug-disconnect')} ${title}`
252-
statusBar.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground')
253-
break
254-
}
255-
case 'needsProfile':
256-
case 'notConnected':
257-
statusBar.text = codicon` ${getIcon('vscode-chrome-close')} ${title}`
258-
statusBar.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground')
259-
break
260-
}
261-
262-
statusBar.show()
263-
}
264163
}

0 commit comments

Comments
 (0)