From b46db6ca43a99dd120bc9d248db88c4448eb6f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kondratek?= Date: Wed, 7 Aug 2024 23:27:50 +0200 Subject: [PATCH 1/2] Ensure the rendered autocompletion is not empty (fixes #2003) --- .../com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt index 9580469c7e..eb786898ea 100644 --- a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt +++ b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt @@ -434,6 +434,7 @@ class CodyAutocompleteManager { if (lines.size > 1) { val text = (if (startsInline) lines.drop(1) else lines).dropWhile { it.isBlank() }.joinToString("\n") + if (text.isEmpty()) return val renderer = CodyAutocompleteBlockElementRenderer(text, items, editor) val inlay2 = inlayModel.addBlockElement( From e6d6d28c5ff4153dcc10d061da9216c20ee66942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kondratek?= Date: Thu, 8 Aug 2024 11:18:04 +0200 Subject: [PATCH 2/2] Fixes --- .../autocomplete/CodyAutocompleteManager.kt | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt index eb786898ea..b58115adad 100644 --- a/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt +++ b/src/main/kotlin/com/sourcegraph/cody/autocomplete/CodyAutocompleteManager.kt @@ -424,27 +424,30 @@ class CodyAutocompleteManager { var inlay: Inlay<*>? = null if (startsInline) { - val renderer = - CodyAutocompleteSingleLineRenderer( - completionText.lines().first(), items, editor, AutocompleteRendererType.INLINE) - inlay = - inlayModel.addInlineElement(cursorOffset, /* relatesToPrecedingText = */ true, renderer) + val text = completionText.lines().first() + if (text.isNotEmpty()) { + val renderer = + CodyAutocompleteSingleLineRenderer(text, items, editor, AutocompleteRendererType.INLINE) + inlay = + inlayModel.addInlineElement(cursorOffset, /* relatesToPrecedingText = */ true, renderer) + } } val lines = completionText.lines() if (lines.size > 1) { val text = (if (startsInline) lines.drop(1) else lines).dropWhile { it.isBlank() }.joinToString("\n") - if (text.isEmpty()) return - val renderer = CodyAutocompleteBlockElementRenderer(text, items, editor) - val inlay2 = - inlayModel.addBlockElement( - /* offset = */ cursorOffset, - /* relatesToPrecedingText = */ true, - /* showAbove = */ false, - /* priority = */ Int.MAX_VALUE, - /* renderer = */ renderer) - if (inlay == null) { - inlay = inlay2 + if (text.isNotEmpty()) { + val renderer = CodyAutocompleteBlockElementRenderer(text, items, editor) + val inlay2 = + inlayModel.addBlockElement( + /* offset = */ cursorOffset, + /* relatesToPrecedingText = */ true, + /* showAbove = */ false, + /* priority = */ Int.MAX_VALUE, + /* renderer = */ renderer) + if (inlay == null) { + inlay = inlay2 + } } }