fix: do not trigger next edit diff when no change detected

This commit is contained in:
Carl-Robert Linnupuu 2025-03-24 10:21:38 +00:00
parent 55bd3008ff
commit b8b78dd079
3 changed files with 10 additions and 9 deletions

View file

@ -89,7 +89,10 @@ class GrpcClientService(private val project: Project) : Disposable {
) : StreamObserver<NextEditResponse> {
override fun onNext(response: NextEditResponse) {
runInEdt {
if (LookupManager.getActiveLookup(editor) == null) {
val documentText = editor.document.text
if (LookupManager.getActiveLookup(editor) == null
&& documentText != response.nextRevision
&& documentText == response.oldRevision) {
CodeSuggestionDiffViewer.displayInlineDiff(editor, response, isManuallyOpened)
}
}

View file

@ -50,7 +50,7 @@ import kotlin.math.max
class CodeSuggestionDiffViewer(
request: DiffRequest,
private val responseId: UUID,
val nextEditResponse: NextEditResponse,
private val mainEditor: Editor,
private val isManuallyOpened: Boolean
) : UnifiedDiffViewer(MyDiffContext(mainEditor.project), request), Disposable {
@ -125,7 +125,8 @@ class CodeSuggestionDiffViewer(
}
application.executeOnPooledThread {
project?.service<GrpcClientService>()?.acceptEdit(responseId, change.toString())
project?.service<GrpcClientService>()
?.acceptEdit(UUID.fromString(nextEditResponse.id), change.toString())
}
}
@ -315,12 +316,8 @@ class CodeSuggestionDiffViewer(
}
val diffRequest = createSimpleDiffRequest(editor, nextRevision)
val diffViewer = CodeSuggestionDiffViewer(
diffRequest,
UUID.fromString(nextEditResponse.id),
editor,
isManuallyOpened
)
val diffViewer =
CodeSuggestionDiffViewer(diffRequest, nextEditResponse, editor, isManuallyOpened)
editor.putUserData(CodeGPTKeys.EDITOR_PREDICTION_DIFF_VIEWER, diffViewer)
diffViewer.rediff(true)
}

View file

@ -21,6 +21,7 @@ message NextEditRequest {
message NextEditResponse {
string id = 1;
string next_revision = 2;
string old_revision = 3;
}
message AcceptEditRequest {