From f4fd298ec89a01b1a358acf1b44ad9473421cbde Mon Sep 17 00:00:00 2001 From: reymondzzzz Date: Mon, 6 Nov 2023 15:26:09 +0300 Subject: [PATCH] fix mix completions --- build.gradle.kts | 2 +- .../smallcloud/refactai/modes/completion/CompletionMode.kt | 7 +++++-- .../refactai/modes/completion/CompletionState.kt | 2 +- .../refactai/modes/completion/renderer/CompletionLayout.kt | 1 + .../refactai/modes/completion/structs/Completion.kt | 2 +- .../kotlin/com/smallcloud/refactai/struct/SMCPrediction.kt | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5aa7551d..ba33973a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ repositories { // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { version.set("2023.2.1") - type.set("IU") // Target IDE Platform + type.set("PC") // Target IDE Platform plugins.set(listOf( "Git4Idea", diff --git a/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionMode.kt b/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionMode.kt index 8a9a4757..079fbc35 100644 --- a/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionMode.kt +++ b/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionMode.kt @@ -54,6 +54,7 @@ class CompletionMode( } override fun onTextChange(event: DocumentEventExtra) { + if (completionInProgress) return val fileName = getActiveFile(event.editor.document) ?: return if (PrivacyService.getPrivacy(FileDocumentManager.getInstance().getFile(event.editor.document)) == Privacy.DISABLED && !InferenceGlobalContext.isSelfHosted) return @@ -209,11 +210,12 @@ class CompletionMode( if ((!completionInProgress) || (choice.delta.isEmpty() && !choice.finishReason.isNullOrEmpty())) { return@streamedInferenceFetch } - val completion: Completion = if (completionLayout?.lastCompletionData == null) { + val completion: Completion = if (completionLayout?.lastCompletionData == null || + completionLayout?.lastCompletionData?.createdTs != prediction.created) { Completion(request.body.inputs.sources.values.toList().first(), offset = editorState.offset, multiline = request.body.inputs.multiline, - createdTs = prediction.created.toLong(), + createdTs = prediction.created, isFromCache = prediction.cached, snippetTelemetryId = prediction.snippetTelemetryId ) @@ -236,6 +238,7 @@ class CompletionMode( requestFuture = it.get() requestFuture.get() logger.debug("Completion request finished") + completionInProgress = false } catch (e: InterruptedException) { handleInterruptedException(requestFuture, editorState.editor) } catch (e: InterruptedIOException) { diff --git a/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionState.kt b/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionState.kt index fa04799c..2215c182 100644 --- a/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionState.kt +++ b/src/main/kotlin/com/smallcloud/refactai/modes/completion/CompletionState.kt @@ -90,7 +90,7 @@ class CompletionState( offset = startIndex, // firstLineEndIndex = endIndex, // endIndex = maxOf(endIndex, startIndex), - createdTs = System.currentTimeMillis(), +// createdTs = System.currentTimeMillis(), // leftSymbolsToRemove = leftSymbolsToRemove, ) } diff --git a/src/main/kotlin/com/smallcloud/refactai/modes/completion/renderer/CompletionLayout.kt b/src/main/kotlin/com/smallcloud/refactai/modes/completion/renderer/CompletionLayout.kt index ab882dec..ba0adcaf 100644 --- a/src/main/kotlin/com/smallcloud/refactai/modes/completion/renderer/CompletionLayout.kt +++ b/src/main/kotlin/com/smallcloud/refactai/modes/completion/renderer/CompletionLayout.kt @@ -70,6 +70,7 @@ class AsyncCompletionLayout( needToRender: Boolean, animation: Boolean ): Future<*>? { + if (lastCompletionData != null && completionData.createdTs != lastCompletionData?.createdTs) return null if (!isUpdating) return null updateTask = scheduler.submit { lastCompletionData = completionData diff --git a/src/main/kotlin/com/smallcloud/refactai/modes/completion/structs/Completion.kt b/src/main/kotlin/com/smallcloud/refactai/modes/completion/structs/Completion.kt index 5d128517..a04cf68e 100644 --- a/src/main/kotlin/com/smallcloud/refactai/modes/completion/structs/Completion.kt +++ b/src/main/kotlin/com/smallcloud/refactai/modes/completion/structs/Completion.kt @@ -6,7 +6,7 @@ data class Completion( var completion: String = "", val multiline: Boolean, val offset: Int, - val createdTs: Long, + val createdTs: Double = -1.0, val isFromCache: Boolean = false, var snippetTelemetryId: Int? = null ) { diff --git a/src/main/kotlin/com/smallcloud/refactai/struct/SMCPrediction.kt b/src/main/kotlin/com/smallcloud/refactai/struct/SMCPrediction.kt index 5c2266e3..564a93b4 100644 --- a/src/main/kotlin/com/smallcloud/refactai/struct/SMCPrediction.kt +++ b/src/main/kotlin/com/smallcloud/refactai/struct/SMCPrediction.kt @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName data class SMCStreamingPeace( val choices: List, - val created: Float, + val created: Double, val model: String, @SerializedName("snippet_telemetry_id") val snippetTelemetryId: Int? = null, val cached: Boolean = false