org.jetbrains.kotlinx.jupyter.repl.CompletionResult.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-kernel Show documentation
Show all versions of kotlin-jupyter-kernel Show documentation
Kotlin Jupyter kernel published as artifact
package org.jetbrains.kotlinx.jupyter.repl
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlinx.jupyter.CompleteReply
import org.jetbrains.kotlinx.jupyter.ErrorReply
import org.jetbrains.kotlinx.jupyter.MessageContent
import org.jetbrains.kotlinx.jupyter.Paragraph
import org.jetbrains.kotlinx.jupyter.compiler.util.CodeInterval
import kotlin.script.experimental.api.SourceCodeCompletionVariant
abstract class CompletionResult {
abstract val message: MessageContent
open class Success(
private val matches: List,
private val bounds: CodeInterval,
private val metadata: List,
private val text: String,
private val cursor: Int
) : CompletionResult() {
init {
assert(matches.size == metadata.size)
}
override val message: MessageContent
get() = CompleteReply(
matches,
bounds.from,
bounds.to,
Paragraph(cursor, text),
CompleteReply.Metadata(
metadata.map {
CompleteReply.ExperimentalType(
it.text,
it.tail,
bounds.from,
bounds.to
)
},
metadata.map {
CompleteReply.ExtendedMetadataEntry(
it.text,
it.displayText,
it.icon,
it.tail,
it.deprecationLevel?.name,
)
}
)
)
@TestOnly
fun sortedMatches(): List = matches.sorted()
@TestOnly
fun sortedRaw(): List = metadata.sortedBy { it.text }
}
class Empty(
text: String,
cursor: Int
) : Success(emptyList(), CodeInterval(cursor, cursor), emptyList(), text, cursor)
class Error(
private val errorName: String,
private val errorValue: String,
private val traceBack: List
) : CompletionResult() {
override val message: MessageContent
get() = ErrorReply(errorName, errorValue, traceBack)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy