Skip to content
Merged
Changes from 2 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
36 changes: 34 additions & 2 deletions packages/amazonq/src/app/inline/EditRendering/displayImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* 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'
Expand Down Expand Up @@ -286,6 +286,36 @@
) {
const originalCode = editor.document.getText()

const isPatchValid = applyPatch(editor.document.getText(), item.insertText as string)
if (!isPatchValid) {
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult: {
[item.itemId]: {
seen: false,
accepted: false,
discarded: true,
},
},
totalSessionDisplayTime: Date.now() - session.requestStartTime,
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
isInlineEdit: true,
}
// 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

Check failure on line 309 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Expected { after 'if' condition
if (e.document !== editor.document) return

Check failure on line 310 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Expected { after 'if' condition
if (vsCodeState.isCodeWhispererEditing) return

Check failure on line 311 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Expected { after 'if' condition
if (getContext('aws.amazonq.editSuggestionActive') === false) return

Check failure on line 312 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Expected { after 'if' condition

const isPatchValid = applyPatch(e.document.getText(), item.insertText as string)
if (!isPatchValid) {
vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')

Check failure on line 316 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoudl add an await

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly didn't add an await since this is in documentChangeListener we want this to be fast

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

}
})
await decorationManager.displayEditSuggestion(
editor,
svgImage,
Expand All @@ -310,6 +340,7 @@
editor.selection = new vscode.Selection(endPosition, endPosition)

await decorationManager.clearDecorations(editor)
documentChangeListener.dispose()
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult: {
Expand Down Expand Up @@ -343,6 +374,7 @@
// Handle reject
getLogger().info('Edit suggestion rejected')
await decorationManager.clearDecorations(editor)
documentChangeListener.dispose()
const params: LogInlineCompletionSessionResultsParams = {
sessionId: session.sessionId,
completionSessionResult: {
Expand Down
Loading