From decd04eddd4965b9f76c7a9a3abd276d8d2e1692 Mon Sep 17 00:00:00 2001 From: liuk Date: Wed, 25 Dec 2024 23:03:53 +0800 Subject: [PATCH] fix: Skip duplicate checks at document end or blank text Prevent autocomplete from truncating when the cursor is at the end of the document or when the text after the cursor is blank. --- .../autocomplete/AutocompleteService.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt index 6279e03f74..2dc6ba021d 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt @@ -120,6 +120,10 @@ class AutocompleteService(private val project: Project) { return ApplicationManager.getApplication().runReadAction { val document = editor.document val caretOffset = editor.caretModel.offset + + // Don't care about it if it's at the end of the document + if (caretOffset == document.textLength) return@runReadAction completion + val N = 10 var textAfterCursor = if (caretOffset + N <= document.textLength) { document.getText(com.intellij.openapi.util.TextRange(caretOffset, caretOffset + N)) @@ -127,6 +131,9 @@ class AutocompleteService(private val project: Project) { document.getText(com.intellij.openapi.util.TextRange(caretOffset, document.textLength)) } + // Avoid truncating the completion text when the text after the cursor is blank + if (textAfterCursor.isBlank()) return@runReadAction completion + // Determine the index of a newline character within the text following the cursor. val newlineIndex = textAfterCursor.indexOf("\r\n").takeIf { it >= 0 } ?: textAfterCursor.indexOf('\n') // If a newline character is found and the current line is not empty, truncate the text at that point.