Kotlin Scripting Compiler extension providing code completion and static analysis for IDE integration
—
Configuration system for customizing code completion behavior in Kotlin scripting environments, including filtering options and name matching strategies.
Marker interface defining the configuration keys available for REPL completion customization.
/**
* Marker interface for REPL completion configuration keys
*/
interface ReplCompletionOptionsKeysBuilder class for constructing completion configuration options using a fluent API.
/**
* Builder for configuring REPL completion options
* Extends PropertiesCollection.Builder for type-safe configuration
*/
open class ReplCompletionOptionsBuilder : PropertiesCollection.Builder(), ReplCompletionOptionsKeys {
companion object : ReplCompletionOptionsKeys
}Usage Example:
import org.jetbrains.kotlin.scripting.ide_services.compiler.completion
import org.jetbrains.kotlin.scripting.ide_services.compiler.filterOutShadowedDescriptors
import org.jetbrains.kotlin.scripting.ide_services.compiler.nameFilter
import kotlin.script.experimental.api.ScriptCompilationConfiguration
// Configure completion options
val config = ScriptCompilationConfiguration {
completion {
filterOutShadowedDescriptors(false) // Include shadowed descriptors
nameFilter { name, prefix ->
name.startsWith(prefix, ignoreCase = true) ||
name.contains(prefix, ignoreCase = true)
}
}
}Controls whether to filter out shadowed declarations in completion results.
/**
* Configure whether to filter out shadowed descriptors in completion
* @param value - true to filter out shadowed descriptors (default), false to include them
*/
fun ReplCompletionOptionsBuilder.filterOutShadowedDescriptors(value: Boolean)
/**
* Property key for shadowed descriptor filtering
* Default value: true
*/
val ReplCompletionOptionsKeys.filterOutShadowedDescriptors: BooleanUsage Examples:
// Include shadowed descriptors (may show more results but with duplicates)
completion {
filterOutShadowedDescriptors(false)
}
// Filter out shadowed descriptors (default behavior, cleaner results)
completion {
filterOutShadowedDescriptors(true)
}Customizes how completion candidates are filtered based on the typed prefix.
/**
* Configure the name filtering function for completion
* @param value - Function that determines if a name matches the typed prefix
*/
fun ReplCompletionOptionsBuilder.nameFilter(value: (String, String) -> Boolean)
/**
* Property key for name filtering
* Default value: { name, namePart -> name.startsWith(namePart) }
*/
val ReplCompletionOptionsKeys.nameFilter: (String, String) -> BooleanUsage Examples:
// Default prefix matching
completion {
nameFilter { name, prefix -> name.startsWith(prefix) }
}
// Case-insensitive prefix matching
completion {
nameFilter { name, prefix -> name.startsWith(prefix, ignoreCase = true) }
}
// Fuzzy matching (contains anywhere)
completion {
nameFilter { name, prefix -> name.contains(prefix, ignoreCase = true) }
}
// Custom matching logic
completion {
nameFilter { name, prefix ->
when {
prefix.isEmpty() -> true
name.startsWith(prefix, ignoreCase = true) -> true
name.contains("_${prefix}", ignoreCase = true) -> true // Match snake_case
else -> false
}
}
}Extension property to access completion configuration within script compilation configuration.
/**
* Extension property for accessing completion configuration builder
* Available on ScriptCompilationConfigurationKeys
*/
val ScriptCompilationConfigurationKeys.completion: ReplCompletionOptionsBuilderComplete Configuration Example:
import org.jetbrains.kotlin.scripting.ide_services.compiler.KJvmReplCompilerWithIdeServices
import org.jetbrains.kotlin.scripting.ide_services.compiler.completion
import org.jetbrains.kotlin.scripting.ide_services.compiler.filterOutShadowedDescriptors
import org.jetbrains.kotlin.scripting.ide_services.compiler.nameFilter
import kotlin.script.experimental.api.*
val compiler = KJvmReplCompilerWithIdeServices()
// Configure for relaxed completion (more results, fuzzy matching)
val relaxedConfig = ScriptCompilationConfiguration {
completion {
filterOutShadowedDescriptors(false) // Show all possible completions
nameFilter { name, prefix ->
// Fuzzy matching with multiple strategies
when {
prefix.isEmpty() -> true
name.equals(prefix, ignoreCase = true) -> true
name.startsWith(prefix, ignoreCase = true) -> true
name.contains(prefix, ignoreCase = true) -> true
// Match camelCase abbreviations (e.g., "gCS" matches "getContentSize")
matchesCamelCaseAbbreviation(name, prefix) -> true
else -> false
}
}
}
}
// Configure for strict completion (cleaner results, exact matching)
val strictConfig = ScriptCompilationConfiguration {
completion {
filterOutShadowedDescriptors(true) // Clean results only
nameFilter { name, prefix ->
// Exact prefix matching only
name.startsWith(prefix, ignoreCase = false)
}
}
}
// Use configurations
val sourceCode = "list.".toScriptSource()
val cursor = SourceCode.Position(0, 5)
val relaxedCompletions = compiler.complete(sourceCode, cursor, relaxedConfig)
val strictCompletions = compiler.complete(sourceCode, cursor, strictConfig)
fun matchesCamelCaseAbbreviation(name: String, prefix: String): Boolean {
// Custom logic for camelCase abbreviation matching
// Implementation would check if prefix matches uppercase letters in name
return false // Simplified for example
}The completion system provides sensible defaults:
// Default configuration equivalent
val defaultConfig = ScriptCompilationConfiguration {
completion {
filterOutShadowedDescriptors(true) // Clean completion results
nameFilter { name, namePart ->
name.startsWith(namePart) // Simple prefix matching
}
}
}Completion configuration is automatically used by the REPL compiler during the completion process:
// The compiler automatically applies completion configuration
val result = compiler.complete(sourceCode, cursor, configurationWithCompletionOptions)
// Configuration is accessed internally like this:
val filterShadowed = configuration[ScriptCompilationConfiguration.completion.filterOutShadowedDescriptors]!!
val nameFilterFn = configuration[ScriptCompilationConfiguration.completion.nameFilter]!!Install with Tessl CLI
npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-scripting-ide-services