How to configure IntelliJ IDEA for Book extension-script authoring: script symbol resolution, SDK setup, and working with the .bk.kts file 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:

  1. After cloning or importing the project, run a Gradle Sync (File โ†’ Sync Project with Gradle Files or the elephant icon in the toolbar).

  2. Navigate to Preferences โ†’ Languages & Frameworks โ†’ Kotlin โ†’ Kotlin Scripting.

  3. Confirm that us.nineworlds.book.scripts.BookScriptDefinition appears in the "Script Definitions" list.

    • If it is absent, click "+", point to the :infrastructure module source root, and add it manually.

  4. Open any .bk.kts file โ€” tool { }, registerCommand, registerEventHandler, registerInterceptor, and ctx should now resolve without red errors.

  5. If errors persist after sync, use File โ†’ Invalidate Caches / Restart.

How it works: The :infrastructure module JAR contains a META-INF/kotlin/script/templates/us.nineworlds.book.scripts.BookScriptDefinition service-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.