Skip to content

Commit 8b6de32

Browse files
committed
Merge branch 'master' into customer-pricing
2 parents e8a43c8 + f724fe9 commit 8b6de32

File tree

81 files changed

+222
-14787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+222
-14787
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ src.gen/*
3131
**/src/shared/telemetry/clienttelemetry.d.ts
3232
**/src/codewhisperer/client/codewhispererclient.d.ts
3333
**/src/codewhisperer/client/codewhispereruserclient.d.ts
34-
**/src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
3534
**/src/auth/sso/oidcclientpkce.d.ts
3635

3736
# Generated by tests
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": "Faster and more responsive inline completion UX"
4+
}

packages/amazonq/package.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -529,22 +529,17 @@
529529
"command": "aws.amazonq.walkthrough.show",
530530
"group": "1_help@1"
531531
},
532-
{
533-
"command": "aws.amazonq.exploreAgents",
534-
"when": "!aws.isSageMaker",
535-
"group": "1_help@2"
536-
},
537532
{
538533
"command": "aws.amazonq.github",
539-
"group": "1_help@3"
534+
"group": "1_help@2"
540535
},
541536
{
542537
"command": "aws.amazonq.aboutExtension",
543-
"group": "1_help@4"
538+
"group": "1_help@3"
544539
},
545540
{
546541
"command": "aws.amazonq.viewLogs",
547-
"group": "1_help@5"
542+
"group": "1_help@4"
548543
}
549544
],
550545
"aws.amazonq.submenu.securityIssueMoreActions": [
@@ -856,12 +851,6 @@
856851
"title": "%AWS.amazonq.openChat%",
857852
"category": "%AWS.amazonq.title%"
858853
},
859-
{
860-
"command": "aws.amazonq.exploreAgents",
861-
"title": "%AWS.amazonq.exploreAgents%",
862-
"category": "%AWS.amazonq.title%",
863-
"enablement": "aws.codewhisperer.connected && !aws.isSageMaker"
864-
},
865854
{
866855
"command": "aws.amazonq.walkthrough.show",
867856
"title": "%AWS.amazonq.welcomeWalkthrough%"
@@ -985,6 +974,10 @@
985974
"command": "aws.amazonq.showPrev",
986975
"when": "inlineSuggestionVisible && !editorReadonly && aws.codewhisperer.connected"
987976
},
977+
{
978+
"command": "aws.amazonq.checkInlineSuggestionVisibility",
979+
"when": "inlineSuggestionVisible && !editorReadonly && aws.codewhisperer.connected"
980+
},
988981
{
989982
"command": "aws.amazonq.inline.invokeChat",
990983
"win": "ctrl+i",

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
5+
import * as vscode from 'vscode'
66
import {
77
CancellationToken,
88
InlineCompletionContext,
@@ -32,7 +32,6 @@ import {
3232
ImportAdderProvider,
3333
CodeSuggestionsState,
3434
vsCodeState,
35-
inlineCompletionsDebounceDelay,
3635
noInlineSuggestionsMsg,
3736
getDiagnosticsDifferences,
3837
getDiagnosticsOfCurrentFile,
@@ -42,7 +41,7 @@ import { LineTracker } from './stateTracker/lineTracker'
4241
import { InlineTutorialAnnotation } from './tutorials/inlineTutorialAnnotation'
4342
import { TelemetryHelper } from './telemetryHelper'
4443
import { Experiments, getLogger, sleep } from 'aws-core-vscode/shared'
45-
import { debounce, messageUtils } from 'aws-core-vscode/utils'
44+
import { messageUtils } from 'aws-core-vscode/utils'
4645
import { showEdits } from './EditRendering/imageRenderer'
4746
import { ICursorUpdateRecorder } from './cursorUpdateManager'
4847
import { DocumentEventListener } from './documentEventListener'
@@ -214,13 +213,23 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
214213
) {}
215214

216215
private readonly logSessionResultMessageName = 'aws/logInlineCompletionSessionResults'
217-
provideInlineCompletionItems = debounce(
218-
this._provideInlineCompletionItems.bind(this),
219-
inlineCompletionsDebounceDelay,
220-
true
221-
)
222216

223-
private async _provideInlineCompletionItems(
217+
// Ideally use this API handleDidShowCompletionItem
218+
// https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts#L83
219+
// we need this because the returned items of provideInlineCompletionItems may not be actually rendered on screen
220+
// if VS Code believes the user is actively typing then it will not show such item
221+
async checkWhetherInlineCompletionWasShown() {
222+
// this line is to force VS Code to re-render the inline completion
223+
// if it decides the inline completion can be shown
224+
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
225+
// yield event loop to let backend state transition finish plus wait for vsc to render
226+
await sleep(10)
227+
// run the command to detect if inline suggestion is really shown or not
228+
await vscode.commands.executeCommand(`aws.amazonq.checkInlineSuggestionVisibility`)
229+
}
230+
231+
// this method is automatically invoked by VS Code as user types
232+
async provideInlineCompletionItems(
224233
document: TextDocument,
225234
position: Position,
226235
context: InlineCompletionContext,
@@ -307,17 +316,18 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
307316
if (prevItemMatchingPrefix.length > 0) {
308317
logstr += `- not call LSP and reuse previous suggestions that match user typed characters
309318
- duration between trigger to completion suggestion is displayed ${performance.now() - t0}`
319+
void this.checkWhetherInlineCompletionWasShown()
310320
return prevItemMatchingPrefix
311321
}
312-
getLogger().debug(`Auto rejecting suggestions from previous session`)
313-
// if no such suggestions, report the previous suggestion as Reject
322+
323+
// if no such suggestions, report the previous suggestion as Reject or Discarded
314324
const params: LogInlineCompletionSessionResultsParams = {
315325
sessionId: prevSessionId,
316326
completionSessionResult: {
317327
[prevItemId]: {
318-
seen: true,
328+
seen: prevSession.displayed,
319329
accepted: false,
320-
discarded: false,
330+
discarded: !prevSession.displayed,
321331
},
322332
},
323333
totalSessionDisplayTime: performance.now() - prevSession.requestStartTime,
@@ -461,6 +471,7 @@ ${itemLog}
461471
this.sessionManager.updateCodeReferenceAndImports()
462472
// suggestions returned here will be displayed on screen
463473
logstr += `- duration between trigger to completion suggestion is displayed: ${performance.now() - t0}ms`
474+
void this.checkWhetherInlineCompletionWasShown()
464475
return itemsMatchingTypeahead as InlineCompletionItem[]
465476
} catch (e) {
466477
getLogger('amazonqLsp').error('Failed to provide completion items: %O', e)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface CodeWhispererSession {
2424
// partialResultToken for the next trigger if user accepts an EDITS suggestion
2525
editsStreakPartialResultToken?: number | string
2626
triggerOnAcceptance?: boolean
27+
// whether any suggestion in this session was displayed on screen
28+
displayed: boolean
2729
}
2830

2931
export class SessionManager {
@@ -49,6 +51,7 @@ export class SessionManager {
4951
startPosition,
5052
firstCompletionDisplayLatency,
5153
diagnosticsBeforeAccept,
54+
displayed: false,
5255
}
5356
this._currentSuggestionIndex = 0
5457
}
@@ -128,6 +131,12 @@ export class SessionManager {
128131
}
129132
}
130133

134+
public checkInlineSuggestionVisibility() {
135+
if (this.activeSession) {
136+
this.activeSession.displayed = true
137+
}
138+
}
139+
131140
private clearReferenceInlineHintsAndImportHints() {
132141
ReferenceInlineProvider.instance.removeInlineReference()
133142
ImportAdderProvider.instance.clear()

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import {
9999
ViewDiffMessage,
100100
referenceLogText,
101101
} from 'aws-core-vscode/amazonq'
102-
import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
102+
import { telemetry } from 'aws-core-vscode/telemetry'
103103
import { isValidResponseError } from './error'
104104
import { decryptResponse, encryptRequest } from '../encryption'
105105
import { getCursorState } from '../utils'
@@ -146,10 +146,13 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
146146
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
147147
languageClient.onTelemetry((e) => {
148148
const telemetryName: string = e.name
149-
150-
if (telemetryName in telemetry) {
151-
languageClient.info(`[VSCode Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
152-
telemetry[telemetryName as keyof TelemetryBase].emit(e.data)
149+
languageClient.info(`[VSCode Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
150+
try {
151+
// Flare is now the source of truth for metrics instead of depending on each IDE client and toolkit-common
152+
const metric = (telemetry as any).getMetric(telemetryName)
153+
metric?.emit(e.data)
154+
} catch (error) {
155+
languageClient.warn(`[VSCode Telemetry] Failed to emit ${telemetryName}: ${error}`)
153156
}
154157
})
155158
}

packages/amazonq/src/lsp/client.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
getClientId,
4040
extensionVersion,
4141
isSageMaker,
42+
DevSettings,
4243
} from 'aws-core-vscode/shared'
4344
import { processUtils } from 'aws-core-vscode/shared'
4445
import { activate } from './chat/activation'
@@ -129,6 +130,15 @@ export async function startLanguageServer(
129130

130131
await validateNodeExe(executable, resourcePaths.lsp, argv, logger)
131132

133+
const endpointOverride = DevSettings.instance.get('codewhispererService', {}).endpoint ?? undefined
134+
const textDocSection = {
135+
inlineEditSupport: Experiments.instance.get('amazonqLSPNEP', true),
136+
} as any
137+
138+
if (endpointOverride) {
139+
textDocSection.endpointOverride = endpointOverride
140+
}
141+
132142
// Options to control the language client
133143
const clientOptions: LanguageClientOptions = {
134144
// Register the server for json documents
@@ -178,9 +188,7 @@ export async function startLanguageServer(
178188
showLogs: true,
179189
},
180190
textDocument: {
181-
inlineCompletionWithReferences: {
182-
inlineEditSupport: Experiments.instance.get('amazonqLSPNEP', true),
183-
},
191+
inlineCompletionWithReferences: textDocSection,
184192
},
185193
},
186194
contextConfiguration: {
@@ -353,6 +361,10 @@ async function onLanguageServerReady(
353361
await vscode.commands.executeCommand('editor.action.inlineSuggest.showNext')
354362
sessionManager.onNextSuggestion()
355363
}),
364+
// this is a workaround since handleDidShowCompletionItem is not public API
365+
Commands.register('aws.amazonq.checkInlineSuggestionVisibility', async () => {
366+
sessionManager.checkInlineSuggestionVisibility()
367+
}),
356368
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
357369
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
358370
}),

packages/amazonq/test/e2e/amazonq/explore.test.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/amazonq/test/unit/amazonq/apps/inline/completion.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('InlineCompletionManager', () => {
378378
)
379379
await messageShown
380380
})
381-
describe('debounce behavior', function () {
381+
describe.skip('debounce behavior', function () {
382382
let clock: ReturnType<typeof installFakeClock>
383383

384384
beforeEach(function () {
@@ -389,7 +389,7 @@ describe('InlineCompletionManager', () => {
389389
clock.uninstall()
390390
})
391391

392-
it('should only trigger once on rapid events', async () => {
392+
it.skip('should only trigger once on rapid events', async () => {
393393
provider = new AmazonQInlineCompletionItemProvider(
394394
languageClient,
395395
recommendationService,

packages/amazonq/test/unit/amazonqFeatureDev/session/chatSessionStorage.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)