Skip to content

Commit 8492fd3

Browse files
Merge master into feature/auto-debug
2 parents 7a5708a + 9a88c41 commit 8492fd3

File tree

21 files changed

+1459
-789
lines changed

21 files changed

+1459
-789
lines changed

.github/workflows/release.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
required: false
1313
default: prerelease
1414
push:
15-
branches: [master, feature/*]
15+
branches: [master, feature/*, release/*]
1616
# tags:
1717
# - v[0-9]+.[0-9]+.[0-9]+
1818

@@ -40,12 +40,16 @@ jobs:
4040
# run: echo 'TAG_NAME=prerelease' >> $GITHUB_ENV
4141
- if: github.event_name == 'workflow_dispatch'
4242
run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
43-
- if: github.ref_name != 'master'
43+
- if: startsWith(github.ref_name, 'feature/')
4444
run: |
45-
TAG_NAME=${{ github.ref_name }}
46-
FEAT_NAME=$(echo $TAG_NAME | sed 's/feature\///')
45+
FEAT_NAME=$(echo ${{ github.ref_name }} | sed 's/feature\///')
4746
echo "FEAT_NAME=$FEAT_NAME" >> $GITHUB_ENV
4847
echo "TAG_NAME=pre-$FEAT_NAME" >> $GITHUB_ENV
48+
- if: startsWith(github.ref_name, 'release/')
49+
run: |
50+
RC_NAME=$(echo ${{ github.ref_name }} | sed 's/release\///')
51+
echo "FEAT_NAME=" >> $GITHUB_ENV
52+
echo "TAG_NAME=rc-$RC_NAME" >> $GITHUB_ENV
4953
- if: github.ref_name == 'master'
5054
run: |
5155
echo "FEAT_NAME=" >> $GITHUB_ENV
@@ -105,10 +109,14 @@ jobs:
105109
- uses: actions/checkout@v4
106110
- uses: actions/download-artifact@v4
107111
- name: Delete existing prerelease
108-
# "prerelease" (main branch) or "pre-<feature>"
109-
if: "env.TAG_NAME == 'prerelease' || startsWith(env.TAG_NAME, 'pre-')"
112+
# "prerelease" (main branch), "pre-<feature>", or "rc-<date>"
113+
if: env.TAG_NAME == 'prerelease' || startsWith(env.TAG_NAME, 'pre-') || startsWith(env.TAG_NAME, 'rc-')
110114
run: |
111-
echo "SUBJECT=AWS IDE Extensions: ${FEAT_NAME:-${TAG_NAME}}" >> $GITHUB_ENV
115+
if [[ "$TAG_NAME" == rc-* ]]; then
116+
echo "SUBJECT=AWS IDE Extensions Release Candidate: ${TAG_NAME#rc-}" >> $GITHUB_ENV
117+
else
118+
echo "SUBJECT=AWS IDE Extensions: ${FEAT_NAME:-${TAG_NAME}}" >> $GITHUB_ENV
119+
fi
112120
gh release delete "$TAG_NAME" --cleanup-tag --yes || true
113121
# git push origin :"$TAG_NAME" || true
114122
- name: Publish Prerelease
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Setup Release Candidate
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionIncrement:
7+
description: 'Release Version Increment'
8+
default: 'Minor'
9+
required: true
10+
type: choice
11+
options:
12+
- Major
13+
- Minor
14+
- Patch
15+
- Custom
16+
customVersion:
17+
description: "Custom Release Version (only used if release increment is 'Custom') - Format: 3.15.0"
18+
default: ''
19+
required: false
20+
type: string
21+
commitId:
22+
description: 'Commit ID to create RC from'
23+
required: true
24+
type: string
25+
26+
jobs:
27+
setup-rc:
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
ref: ${{ inputs.commitId }}
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
persist-credentials: true
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: '18'
42+
cache: 'npm'
43+
44+
- name: Calculate Release Versions
45+
id: release-version
46+
run: |
47+
customVersion="${{ inputs.customVersion }}"
48+
versionIncrement="${{ inputs.versionIncrement }}"
49+
50+
increment_version() {
51+
local currentVersion=$1
52+
if [[ "$versionIncrement" == "Custom" && -n "$customVersion" ]]; then
53+
echo "$customVersion"
54+
else
55+
IFS='.' read -r major minor patch <<< "$currentVersion"
56+
case "$versionIncrement" in
57+
"Major")
58+
major=$((major + 1))
59+
minor=0
60+
patch=0
61+
;;
62+
"Minor")
63+
minor=$((minor + 1))
64+
patch=0
65+
;;
66+
"Patch")
67+
patch=$((patch + 1))
68+
;;
69+
esac
70+
echo "$major.$minor.$patch"
71+
fi
72+
}
73+
74+
# Read and increment toolkit version
75+
toolkitCurrentVersion=$(node -e "console.log(require('./packages/toolkit/package.json').version)" | sed 's/-SNAPSHOT//')
76+
toolkitNewVersion=$(increment_version "$toolkitCurrentVersion")
77+
78+
# Read and increment amazonq version
79+
amazonqCurrentVersion=$(node -e "console.log(require('./packages/amazonq/package.json').version)" | sed 's/-SNAPSHOT//')
80+
amazonqNewVersion=$(increment_version "$amazonqCurrentVersion")
81+
82+
echo "TOOLKIT_VERSION=$toolkitNewVersion" >> $GITHUB_OUTPUT
83+
echo "AMAZONQ_VERSION=$amazonqNewVersion" >> $GITHUB_OUTPUT
84+
# Use date-based branch naming instead of version-based because we release
85+
# both extensions (toolkit and amazonq) from the same branch, and they may
86+
# have different version numbers. We can change this in the future
87+
echo "BRANCH_NAME=rc-$(date +%Y%m%d)" >> $GITHUB_OUTPUT
88+
89+
- name: Create RC Branch and Update Versions
90+
env:
91+
TOOLKIT_VERSION: ${{ steps.release-version.outputs.TOOLKIT_VERSION }}
92+
AMAZONQ_VERSION: ${{ steps.release-version.outputs.AMAZONQ_VERSION }}
93+
BRANCH_NAME: ${{ steps.release-version.outputs.BRANCH_NAME }}
94+
run: |
95+
git config user.name "aws-toolkit-automation"
96+
git config user.email "<>"
97+
98+
# Create RC branch using date-based naming
99+
git checkout -b $BRANCH_NAME
100+
101+
# Update package versions individually
102+
npm version --no-git-tag-version $TOOLKIT_VERSION -w packages/toolkit
103+
npm version --no-git-tag-version $AMAZONQ_VERSION -w packages/amazonq
104+
105+
# Commit version changes
106+
git add packages/toolkit/package.json packages/amazonq/package.json package-lock.json
107+
git commit -m "chore: bump versions - toolkit=$TOOLKIT_VERSION, amazonq=$AMAZONQ_VERSION"
108+
109+
# Push RC branch
110+
git push origin $BRANCH_NAME

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { getLogger, setContext } from 'aws-core-vscode/shared'
6+
import { getContext, getLogger, setContext } from 'aws-core-vscode/shared'
77
import * as vscode from 'vscode'
8-
import { diffLines } from 'diff'
8+
import { applyPatch, diffLines } from 'diff'
99
import { LanguageClient } from 'vscode-languageclient'
1010
import { CodeWhispererSession } from '../sessionManager'
1111
import { LogInlineCompletionSessionResultsParams } from '@aws/language-server-runtimes/protocol'
1212
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes/protocol'
1313
import path from 'path'
1414
import { imageVerticalOffset } from './svgGenerator'
15-
import { AmazonQInlineCompletionItemProvider } from '../completion'
15+
import { EditSuggestionState } from '../editSuggestionState'
16+
import type { AmazonQInlineCompletionItemProvider } from '../completion'
1617
import { vsCodeState } from 'aws-core-vscode/codewhisperer'
1718

19+
const autoRejectEditCursorDistance = 25
20+
1821
export class EditDecorationManager {
1922
private imageDecorationType: vscode.TextEditorDecorationType
2023
private removedCodeDecorationType: vscode.TextEditorDecorationType
@@ -136,6 +139,7 @@ export class EditDecorationManager {
136139
await this.clearDecorations(editor)
137140

138141
await setContext('aws.amazonq.editSuggestionActive' as any, true)
142+
EditSuggestionState.setEditSuggestionActive(true)
139143

140144
this.acceptHandler = onAccept
141145
this.rejectHandler = onReject
@@ -166,6 +170,7 @@ export class EditDecorationManager {
166170
this.acceptHandler = undefined
167171
this.rejectHandler = undefined
168172
await setContext('aws.amazonq.editSuggestionActive' as any, false)
173+
EditSuggestionState.setEditSuggestionActive(false)
169174
}
170175

171176
/**
@@ -270,6 +275,28 @@ function getEndOfEditPosition(originalCode: string, newCode: string): vscode.Pos
270275
return editor ? editor.selection.active : new vscode.Position(0, 0)
271276
}
272277

278+
/**
279+
* Helper function to create discard telemetry params
280+
*/
281+
function createDiscardTelemetryParams(
282+
session: CodeWhispererSession,
283+
item: InlineCompletionItemWithReferences
284+
): LogInlineCompletionSessionResultsParams {
285+
return {
286+
sessionId: session.sessionId,
287+
completionSessionResult: {
288+
[item.itemId]: {
289+
seen: false,
290+
accepted: false,
291+
discarded: true,
292+
},
293+
},
294+
totalSessionDisplayTime: Date.now() - session.requestStartTime,
295+
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
296+
isInlineEdit: true,
297+
}
298+
}
299+
273300
/**
274301
* Helper function to display SVG decorations
275302
*/
@@ -286,6 +313,54 @@ export async function displaySvgDecoration(
286313
) {
287314
const originalCode = editor.document.getText()
288315

316+
// Check if a completion suggestion is currently active - if so, discard edit suggestion
317+
if (inlineCompletionProvider && (await inlineCompletionProvider.isCompletionActive())) {
318+
// Emit DISCARD telemetry for edit suggestion that can't be shown due to active completion
319+
const params = createDiscardTelemetryParams(session, item)
320+
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
321+
getLogger().info('Edit suggestion discarded due to active completion suggestion')
322+
return
323+
}
324+
325+
const isPatchValid = applyPatch(editor.document.getText(), item.insertText as string)
326+
if (!isPatchValid) {
327+
const params = createDiscardTelemetryParams(session, item)
328+
// TODO: this session is closed on flare side hence discarded is not emitted in flare
329+
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
330+
return
331+
}
332+
const documentChangeListener = vscode.workspace.onDidChangeTextDocument((e) => {
333+
if (e.contentChanges.length <= 0) {
334+
return
335+
}
336+
if (e.document !== editor.document) {
337+
return
338+
}
339+
if (vsCodeState.isCodeWhispererEditing) {
340+
return
341+
}
342+
if (getContext('aws.amazonq.editSuggestionActive') === false) {
343+
return
344+
}
345+
346+
const isPatchValid = applyPatch(e.document.getText(), item.insertText as string)
347+
if (!isPatchValid) {
348+
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
349+
}
350+
})
351+
const cursorChangeListener = vscode.window.onDidChangeTextEditorSelection((e) => {
352+
if (!EditSuggestionState.isEditSuggestionActive()) {
353+
return
354+
}
355+
if (e.textEditor !== editor) {
356+
return
357+
}
358+
const currentPosition = e.selections[0].active
359+
const distance = Math.abs(currentPosition.line - startLine)
360+
if (distance > autoRejectEditCursorDistance) {
361+
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
362+
}
363+
})
289364
await decorationManager.displayEditSuggestion(
290365
editor,
291366
svgImage,
@@ -310,6 +385,8 @@ export async function displaySvgDecoration(
310385
editor.selection = new vscode.Selection(endPosition, endPosition)
311386

312387
await decorationManager.clearDecorations(editor)
388+
documentChangeListener.dispose()
389+
cursorChangeListener.dispose()
313390
const params: LogInlineCompletionSessionResultsParams = {
314391
sessionId: session.sessionId,
315392
completionSessionResult: {
@@ -343,6 +420,8 @@ export async function displaySvgDecoration(
343420
// Handle reject
344421
getLogger().info('Edit suggestion rejected')
345422
await decorationManager.clearDecorations(editor)
423+
documentChangeListener.dispose()
424+
cursorChangeListener.dispose()
346425
const params: LogInlineCompletionSessionResultsParams = {
347426
sessionId: session.sessionId,
348427
completionSessionResult: {

packages/amazonq/src/app/inline/EditRendering/imageRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getLogger } from 'aws-core-vscode/shared'
1010
import { LanguageClient } from 'vscode-languageclient'
1111
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes/protocol'
1212
import { CodeWhispererSession } from '../sessionManager'
13-
import { AmazonQInlineCompletionItemProvider } from '../completion'
13+
import type { AmazonQInlineCompletionItemProvider } from '../completion'
1414

1515
export async function showEdits(
1616
item: InlineCompletionItemWithReferences,

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,53 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
237237
await vscode.commands.executeCommand(`aws.amazonq.checkInlineSuggestionVisibility`)
238238
}
239239

240+
/**
241+
* Check if a completion suggestion is currently active/displayed
242+
*/
243+
public async isCompletionActive(): Promise<boolean> {
244+
const session = this.sessionManager.getActiveSession()
245+
if (session === undefined || !session.displayed || session.suggestions.some((item) => item.isInlineEdit)) {
246+
return false
247+
}
248+
249+
// Use VS Code command to check if inline suggestion is actually visible on screen
250+
// This command only executes when inlineSuggestionVisible context is true
251+
await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility')
252+
const isInlineSuggestionVisible = performance.now() - session.lastVisibleTime < 50
253+
return isInlineSuggestionVisible
254+
}
255+
256+
/**
257+
* Batch discard telemetry for completion suggestions when edit suggestion is active
258+
*/
259+
public batchDiscardTelemetryForEditSuggestion(items: any[], session: any): void {
260+
// Emit DISCARD telemetry for completion suggestions that can't be shown due to active edit
261+
const completionSessionResult: {
262+
[key: string]: { seen: boolean; accepted: boolean; discarded: boolean }
263+
} = {}
264+
265+
for (const item of items) {
266+
if (!item.isInlineEdit && item.itemId) {
267+
completionSessionResult[item.itemId] = {
268+
seen: false,
269+
accepted: false,
270+
discarded: true,
271+
}
272+
}
273+
}
274+
275+
// Send single telemetry event for all discarded items
276+
if (Object.keys(completionSessionResult).length > 0) {
277+
const params: LogInlineCompletionSessionResultsParams = {
278+
sessionId: session.sessionId,
279+
completionSessionResult,
280+
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
281+
totalSessionDisplayTime: performance.now() - session.requestStartTime,
282+
}
283+
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
284+
}
285+
}
286+
240287
// this method is automatically invoked by VS Code as user types
241288
async provideInlineCompletionItems(
242289
document: TextDocument,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* Manages the state of edit suggestions to avoid circular dependencies
8+
*/
9+
export class EditSuggestionState {
10+
private static isEditSuggestionCurrentlyActive = false
11+
12+
static setEditSuggestionActive(active: boolean): void {
13+
this.isEditSuggestionCurrentlyActive = active
14+
}
15+
16+
static isEditSuggestionActive(): boolean {
17+
return this.isEditSuggestionCurrentlyActive
18+
}
19+
}

0 commit comments

Comments
 (0)