IDE Setup for .bk.kts Development
How to configure IntelliJ IDEA for Book extension-script authoring: script symbol resolution, SDK setup, and working with the
.bk.ktsfile type. For the extension API itself see the Extension API Guide.
How the IDE Resolves Script Symbols
Every .bk.kts file is evaluated with a BookScriptReceiver instance as its implicit receiver โ declared via implicitReceivers(BookScriptReceiver::class) in BookScriptCompilationConfiguration. This is why tool, registerCommand, registerEventHandler, registerInterceptor, and ctx are all available at the top level of your script without any qualifier.
For the Kotlin Scripting IDE plugin to discover this definition and provide full content assistance (auto-complete, navigation, type info), a META-INF/kotlin/script/templates/us.nineworlds.book.scripts.BookScriptDefinition service-loader resource is packaged into the :infrastructure module JAR. The IDE Setup section below explains how to activate this in IntelliJ IDEA.
IDE Setup (IntelliJ IDEA)
To get full content assistance (auto-complete, navigation, type info) for .bk.kts files in IntelliJ IDEA, follow these steps:
-
After cloning or importing the project, run a Gradle Sync (
File โ Sync Project with Gradle Filesor the elephant icon in the toolbar). -
Navigate to Preferences โ Languages & Frameworks โ Kotlin โ Kotlin Scripting.
-
Confirm that
us.nineworlds.book.scripts.BookScriptDefinitionappears in the "Script Definitions" list.-
If it is absent, click "+", point to the
:infrastructuremodule source root, and add it manually.
-
-
Open any
.bk.ktsfile โtool { },registerCommand,registerEventHandler,registerInterceptor, andctxshould now resolve without red errors. -
If errors persist after sync, use File โ Invalidate Caches / Restart.
How it works: The
:infrastructuremodule JAR contains aMETA-INF/kotlin/script/templates/us.nineworlds.book.scripts.BookScriptDefinitionservice-loader resource file. The Kotlin Scripting IDE plugin scans JARs on the module classpath for this convention to discover script definitions โ no manual plugin installation required.