-
Notifications
You must be signed in to change notification settings - Fork 746
fix(amazonq): discard/reject edit suggestion if it isn't valid #7848
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
|
@@ -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 | ||
andrewyuq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) { | ||
| vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit') | ||
|
Check failure on line 316 in packages/amazonq/src/app/inline/EditRendering/displayImage.ts
|
||
|
||
| } | ||
| }) | ||
| await decorationManager.displayEditSuggestion( | ||
| editor, | ||
| svgImage, | ||
|
|
@@ -310,6 +340,7 @@ | |
| editor.selection = new vscode.Selection(endPosition, endPosition) | ||
|
|
||
| await decorationManager.clearDecorations(editor) | ||
| documentChangeListener.dispose() | ||
| const params: LogInlineCompletionSessionResultsParams = { | ||
| sessionId: session.sessionId, | ||
| completionSessionResult: { | ||
|
|
@@ -343,6 +374,7 @@ | |
| // Handle reject | ||
| getLogger().info('Edit suggestion rejected') | ||
| await decorationManager.clearDecorations(editor) | ||
| documentChangeListener.dispose() | ||
| const params: LogInlineCompletionSessionResultsParams = { | ||
| sessionId: session.sessionId, | ||
| completionSessionResult: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.