Skip to content

Merge master into feature/LSP-gamma #7850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: feature/LSP-gamma
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
required: false
default: prerelease
push:
branches: [master, feature/*]
branches: [master, feature/*, release/*]
# tags:
# - v[0-9]+.[0-9]+.[0-9]+

Expand Down Expand Up @@ -40,12 +40,16 @@ jobs:
# run: echo 'TAG_NAME=prerelease' >> $GITHUB_ENV
- if: github.event_name == 'workflow_dispatch'
run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
- if: github.ref_name != 'master'
- if: startsWith(github.ref_name, 'feature/')
run: |
TAG_NAME=${{ github.ref_name }}
FEAT_NAME=$(echo $TAG_NAME | sed 's/feature\///')
FEAT_NAME=$(echo ${{ github.ref_name }} | sed 's/feature\///')
echo "FEAT_NAME=$FEAT_NAME" >> $GITHUB_ENV
echo "TAG_NAME=pre-$FEAT_NAME" >> $GITHUB_ENV
- if: startsWith(github.ref_name, 'release/')
run: |
RC_NAME=$(echo ${{ github.ref_name }} | sed 's/release\///')
echo "FEAT_NAME=" >> $GITHUB_ENV
echo "TAG_NAME=rc-$RC_NAME" >> $GITHUB_ENV
- if: github.ref_name == 'master'
run: |
echo "FEAT_NAME=" >> $GITHUB_ENV
Expand Down Expand Up @@ -105,10 +109,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: Delete existing prerelease
# "prerelease" (main branch) or "pre-<feature>"
if: "env.TAG_NAME == 'prerelease' || startsWith(env.TAG_NAME, 'pre-')"
# "prerelease" (main branch), "pre-<feature>", or "rc-<date>"
if: env.TAG_NAME == 'prerelease' || startsWith(env.TAG_NAME, 'pre-') || startsWith(env.TAG_NAME, 'rc-')
run: |
echo "SUBJECT=AWS IDE Extensions: ${FEAT_NAME:-${TAG_NAME}}" >> $GITHUB_ENV
if [[ "$TAG_NAME" == rc-* ]]; then
echo "SUBJECT=AWS IDE Extensions Release Candidate: ${TAG_NAME#rc-}" >> $GITHUB_ENV
else
echo "SUBJECT=AWS IDE Extensions: ${FEAT_NAME:-${TAG_NAME}}" >> $GITHUB_ENV
fi
gh release delete "$TAG_NAME" --cleanup-tag --yes || true
# git push origin :"$TAG_NAME" || true
- name: Publish Prerelease
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/setup-release-candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Setup Release Candidate

on:
workflow_dispatch:
inputs:
versionIncrement:
description: 'Release Version Increment'
default: 'Minor'
required: true
type: choice
options:
- Major
- Minor
- Patch
- Custom
customVersion:
description: "Custom Release Version (only used if release increment is 'Custom') - Format: 3.15.0"
default: ''
required: false
type: string
commitId:
description: 'Commit ID to create RC from'
required: true
type: string

jobs:
setup-rc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.commitId }}
token: ${{ secrets.RELEASE_CANDIDATE_BRANCH_CREATION_PAT }}
persist-credentials: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Calculate Release Versions
id: release-version
run: |
customVersion="${{ inputs.customVersion }}"
versionIncrement="${{ inputs.versionIncrement }}"

increment_version() {
local currentVersion=$1
if [[ "$versionIncrement" == "Custom" && -n "$customVersion" ]]; then
echo "$customVersion"
else
IFS='.' read -r major minor patch <<< "$currentVersion"
case "$versionIncrement" in
"Major")
major=$((major + 1))
minor=0
patch=0
;;
"Minor")
minor=$((minor + 1))
patch=0
;;
"Patch")
patch=$((patch + 1))
;;
esac
echo "$major.$minor.$patch"
fi
}

# Read and increment toolkit version
toolkitCurrentVersion=$(node -e "console.log(require('./packages/toolkit/package.json').version)" | sed 's/-SNAPSHOT//')
toolkitNewVersion=$(increment_version "$toolkitCurrentVersion")

# Read and increment amazonq version
amazonqCurrentVersion=$(node -e "console.log(require('./packages/amazonq/package.json').version)" | sed 's/-SNAPSHOT//')
amazonqNewVersion=$(increment_version "$amazonqCurrentVersion")

echo "TOOLKIT_VERSION=$toolkitNewVersion" >> $GITHUB_OUTPUT
echo "AMAZONQ_VERSION=$amazonqNewVersion" >> $GITHUB_OUTPUT
# Use date-based branch naming instead of version-based because we release
# both extensions (toolkit and amazonq) from the same branch, and they may
# have different version numbers. We can change this in the future
echo "BRANCH_NAME=rc-$(date +%Y%m%d)" >> $GITHUB_OUTPUT

- name: Create RC Branch and Update Versions
env:
TOOLKIT_VERSION: ${{ steps.release-version.outputs.TOOLKIT_VERSION }}
AMAZONQ_VERSION: ${{ steps.release-version.outputs.AMAZONQ_VERSION }}
BRANCH_NAME: ${{ steps.release-version.outputs.BRANCH_NAME }}
run: |
git config user.name "aws-toolkit-automation"
git config user.email "<>"

# Create RC branch using date-based naming
git checkout -b $BRANCH_NAME

# Update package versions individually
npm version --no-git-tag-version $TOOLKIT_VERSION -w packages/toolkit
npm version --no-git-tag-version $AMAZONQ_VERSION -w packages/amazonq

# Commit version changes
git add packages/toolkit/package.json packages/amazonq/package.json package-lock.json
git commit -m "chore: bump versions - toolkit=$TOOLKIT_VERSION, amazonq=$AMAZONQ_VERSION"

# Push RC branch
git push origin $BRANCH_NAME

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
85 changes: 82 additions & 3 deletions packages/amazonq/src/app/inline/EditRendering/displayImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getLogger, setContext } from 'aws-core-vscode/shared'
import { getContext, getLogger, setContext } from 'aws-core-vscode/shared'
import * as vscode from 'vscode'
import { diffLines } from 'diff'
import { applyPatch, diffLines } from 'diff'
import { LanguageClient } from 'vscode-languageclient'
import { CodeWhispererSession } from '../sessionManager'
import { LogInlineCompletionSessionResultsParams } from '@aws/language-server-runtimes/protocol'
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes/protocol'
import path from 'path'
import { imageVerticalOffset } from './svgGenerator'
import { AmazonQInlineCompletionItemProvider } from '../completion'
import { EditSuggestionState } from '../editSuggestionState'
import type { AmazonQInlineCompletionItemProvider } from '../completion'
import { vsCodeState } from 'aws-core-vscode/codewhisperer'

const autoRejectEditCursorDistance = 25

export class EditDecorationManager {
private imageDecorationType: vscode.TextEditorDecorationType
private removedCodeDecorationType: vscode.TextEditorDecorationType
Expand Down Expand Up @@ -136,6 +139,7 @@ export class EditDecorationManager {
await this.clearDecorations(editor)

await setContext('aws.amazonq.editSuggestionActive' as any, true)
EditSuggestionState.setEditSuggestionActive(true)

this.acceptHandler = onAccept
this.rejectHandler = onReject
Expand Down Expand Up @@ -166,6 +170,7 @@ export class EditDecorationManager {
this.acceptHandler = undefined
this.rejectHandler = undefined
await setContext('aws.amazonq.editSuggestionActive' as any, false)
EditSuggestionState.setEditSuggestionActive(false)
}

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

/**
* Helper function to create discard telemetry params
*/
function createDiscardTelemetryParams(
session: CodeWhispererSession,
item: InlineCompletionItemWithReferences
): LogInlineCompletionSessionResultsParams {
return {
sessionId: session.sessionId,
completionSessionResult: {
[item.itemId]: {
seen: false,
accepted: false,
discarded: true,
},
},
totalSessionDisplayTime: Date.now() - session.requestStartTime,
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
isInlineEdit: true,
}
}

/**
* Helper function to display SVG decorations
*/
Expand All @@ -286,6 +313,54 @@ export async function displaySvgDecoration(
) {
const originalCode = editor.document.getText()

// Check if a completion suggestion is currently active - if so, discard edit suggestion
if (inlineCompletionProvider && (await inlineCompletionProvider.isCompletionActive())) {
// Emit DISCARD telemetry for edit suggestion that can't be shown due to active completion
const params = createDiscardTelemetryParams(session, item)
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
getLogger().info('Edit suggestion discarded due to active completion suggestion')
return
}

const isPatchValid = applyPatch(editor.document.getText(), item.insertText as string)
if (!isPatchValid) {
const params = createDiscardTelemetryParams(session, item)
// TODO: this session is closed on flare side hence discarded is not emitted in flare
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
return
}
const documentChangeListener = vscode.workspace.onDidChangeTextDocument((e) => {
if (e.contentChanges.length <= 0) {
return
}
if (e.document !== editor.document) {
return
}
if (vsCodeState.isCodeWhispererEditing) {
return
}
if (getContext('aws.amazonq.editSuggestionActive') === false) {
return
}

const isPatchValid = applyPatch(e.document.getText(), item.insertText as string)
if (!isPatchValid) {
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
}
})
const cursorChangeListener = vscode.window.onDidChangeTextEditorSelection((e) => {
if (!EditSuggestionState.isEditSuggestionActive()) {
return
}
if (e.textEditor !== editor) {
return
}
const currentPosition = e.selections[0].active
const distance = Math.abs(currentPosition.line - startLine)
if (distance > autoRejectEditCursorDistance) {
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
}
})
await decorationManager.displayEditSuggestion(
editor,
svgImage,
Expand All @@ -310,6 +385,8 @@ export async function displaySvgDecoration(
editor.selection = new vscode.Selection(endPosition, endPosition)

await decorationManager.clearDecorations(editor)
documentChangeListener.dispose()
cursorChangeListener.dispose()
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult: {
Expand Down Expand Up @@ -343,6 +420,8 @@ export async function displaySvgDecoration(
// Handle reject
getLogger().info('Edit suggestion rejected')
await decorationManager.clearDecorations(editor)
documentChangeListener.dispose()
cursorChangeListener.dispose()
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getLogger } from 'aws-core-vscode/shared'
import { LanguageClient } from 'vscode-languageclient'
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes/protocol'
import { CodeWhispererSession } from '../sessionManager'
import { AmazonQInlineCompletionItemProvider } from '../completion'
import type { AmazonQInlineCompletionItemProvider } from '../completion'

export async function showEdits(
item: InlineCompletionItemWithReferences,
Expand Down
47 changes: 47 additions & 0 deletions packages/amazonq/src/app/inline/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,53 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
await vscode.commands.executeCommand(`aws.amazonq.checkInlineSuggestionVisibility`)
}

/**
* Check if a completion suggestion is currently active/displayed
*/
public async isCompletionActive(): Promise<boolean> {
const session = this.sessionManager.getActiveSession()
if (session === undefined || !session.displayed || session.suggestions.some((item) => item.isInlineEdit)) {
return false
}

// Use VS Code command to check if inline suggestion is actually visible on screen
// This command only executes when inlineSuggestionVisible context is true
await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility')
const isInlineSuggestionVisible = performance.now() - session.lastVisibleTime < 50
return isInlineSuggestionVisible
}

/**
* Batch discard telemetry for completion suggestions when edit suggestion is active
*/
public batchDiscardTelemetryForEditSuggestion(items: any[], session: any): void {
// Emit DISCARD telemetry for completion suggestions that can't be shown due to active edit
const completionSessionResult: {
[key: string]: { seen: boolean; accepted: boolean; discarded: boolean }
} = {}

for (const item of items) {
if (!item.isInlineEdit && item.itemId) {
completionSessionResult[item.itemId] = {
seen: false,
accepted: false,
discarded: true,
}
}
}

// Send single telemetry event for all discarded items
if (Object.keys(completionSessionResult).length > 0) {
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult,
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
totalSessionDisplayTime: performance.now() - session.requestStartTime,
}
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
}
}

// this method is automatically invoked by VS Code as user types
async provideInlineCompletionItems(
document: TextDocument,
Expand Down
19 changes: 19 additions & 0 deletions packages/amazonq/src/app/inline/editSuggestionState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Manages the state of edit suggestions to avoid circular dependencies
*/
export class EditSuggestionState {
private static isEditSuggestionCurrentlyActive = false

static setEditSuggestionActive(active: boolean): void {
this.isEditSuggestionCurrentlyActive = active
}

static isEditSuggestionActive(): boolean {
return this.isEditSuggestionCurrentlyActive
}
}
3 changes: 2 additions & 1 deletion packages/amazonq/src/app/inline/recommendationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getLogger } from 'aws-core-vscode/shared'
import { DocumentEventListener } from './documentEventListener'
import { getOpenFilesInWindow } from 'aws-core-vscode/utils'
import { asyncCallWithTimeout } from '../../util/timeoutUtil'
import { EditSuggestionState } from './editSuggestionState'

export interface GetAllRecommendationsOptions {
emitTelemetry?: boolean
Expand Down Expand Up @@ -132,7 +133,7 @@ export class RecommendationService {
* Completions use PartialResultToken with single 1 call of [getAllRecommendations].
* Edits leverage partialResultToken to achieve EditStreak such that clients can pull all continuous suggestions generated by the model within 1 EOS block.
*/
if (!isTriggerByDeletion && !request.partialResultToken) {
if (!isTriggerByDeletion && !request.partialResultToken && !EditSuggestionState.isEditSuggestionActive()) {
const completionPromise: Promise<InlineCompletionListWithReferences> = languageClient.sendRequest(
inlineCompletionWithReferencesRequestType.method,
request,
Expand Down
Loading
Loading