1 Editor Support
nillpoe edited this page 2026-09-29 08:18:50 +00:00

Editor Support

IntelliJ IDEA plugin

idea-plugin in the repository builds kmx-intellij-<version>.zip for IntelliJ IDEA 2026.2 and later, with the bundled Kotlin plugin in K2 mode. Install it with Settings → Plugins → ⚙ → Install Plugin from Disk.

Feature What it does
Highlighting Tags, component names, attributes, values, entities, directives and template comments; Kotlin parts through Kotlin's lexer, so keywords, strings, numbers and comments look as in .kt files
Syntax errors The KMX compiler's errors, at their line and column
Kotlin errors and warnings What kotlinc would report for the template's Kotlin, on the template text
Completion Locals, header values, loop variables, props members, builder and render scope members, imported and extension functions, and members after .
Go to Declaration Into Kotlin sources and libraries, and back into the template for props parameters, header values and loop variables
Editing Brace matching for { } and ( ); Comment with Block Comment writes {/* ... */}

Run the build once after adding a template (see How the plugin analyzes a template).

How the plugin analyzes a template

  1. The plugin compiles the template with kmx-compiler, the same compiler the build uses, into the generated Kotlin and its KmxOutput.mappings: where every piece of the template's Kotlin landed in the generated code.
  2. It reads the file the build generated for the template, under build/generated/kmx/<source set>/kotlin or build/generated/quill/kotlin, to take over the package, the declaration name and the default imports. Frameworks such as Quill choose these, so the template alone does not tell them. Without a generated file, it uses the defaults of the KMX Gradle plugin.
  3. It creates an in-memory Kotlin file from the generated code, renames the declaration with the suffix KmxIde so it does not clash with the build's copy, and has the Kotlin Analysis API analyze it as if it sat next to a Kotlin file of the template's module. The code therefore sees the module's classes and dependencies, and every name resolves as it does in the build.
  4. Each diagnostic is moved back to the template through the mappings. A diagnostic on generated code, such as a type mismatch reported on an insert call, goes to the template Kotlin on the same generated line, or to the template line named by the line's // file.kmx:line comment. Warnings appear only when they point at template text.
  5. Completion and Go to Declaration map the caret into the generated code the same way, and map declarations found in the generated code back into the template.

The template is analyzed as a whole generated file, not as separate fragments, which is why props members, the builder, the render scope and header values are all in scope where they are in the build.

Limits

  • Find Usages and Rename do not include templates yet.
  • Kotlin identifiers are not colored by meaning (calls, properties); only their token kind is.
  • A template that does not parse gets syntax errors only, until it parses again.
  • Kotlin errors need a Kotlin file in the template's module, which every module that uses KMX has once the build has run.

TextMate grammar

editors/textmate holds syntaxes/kmx.tmLanguage.json (scope source.kmx) and is also a VS Code extension folder.

  • IntelliJ-based IDEs without the plugin: Settings → Editor → TextMate Bundles → + → the editors/textmate folder.
  • VS Code: copy the folder to ~/.vscode/extensions/kmx.

It highlights the markup and hands {...}, attribute expressions, directive conditions and header lines to the editor's Kotlin grammar (source.kotlin). It does not report errors. Markup literals inside Kotlin are recognized by the same rule as the compiler's where a line allows, but TextMate grammars match line by line, so some nested cases fall back to Kotlin coloring.