Skip to content

Commit

Permalink
Ensure the rendered autocompletion is not empty (fixes #2003) (#2007)
Browse files Browse the repository at this point in the history
Fixes CODY-3189

The check was originally there - we lost it at some point:

4f50796#diff-cb6c461805813f1dff589b6e691cded2a165241943810513c716325ad1fe25baR310

If the text to be rendered is empty let's skip the rendering. 

## Test plan
Hard to repro. Probably requires a python project.
  • Loading branch information
mkondratek authored Aug 8, 2024
1 parent 9109f79 commit 0fe8183
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +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")
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
}
}
}

Expand Down

0 comments on commit 0fe8183

Please sign in to comment.