Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the rendered autocompletion is not empty (fixes #2003) #2007

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading