Skip to content

Commit 6f43c6f

Browse files
Add a "Declaring compatibility with the K2 Kotlin mode" section to the K1 migration guide
1 parent 34e7c94 commit 6f43c6f

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Writerside/topics/Migrating-from-K1.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Migrating from K1
22

33
For many years, the only practical way to analyze Kotlin code in IntelliJ IDEA and other tools was to use the Kotlin
4-
compiler internals, an unsafe API not designed for external usage.
4+
compiler's internals, an unsafe API not designed for external usage.
55

66
The Analysis API, on the other hand, offers a much cleaner and robust set of utilities. It exposes almost the same set
77
of concepts. Thus, if you already have code that depends on the Kotlin compiler, migrating it to the new API should not
88
be time-consuming. This migration guide outlines the differences between the APIs and explains how to port the
99
descriptor-based resolution logic to the Analysis API.
1010

11+
Once an IntelliJ plugin has been migrated to the Analysis API, it will need to [declare its compatibility with the K2
12+
Kotlin mode](#declaring-compatibility-with-the-k2-kotlin-mode). Otherwise, the plugin will not be loaded when the K2
13+
mode is active.
14+
1115
## The Conceptual Difference
1216

1317
The cornerstone of the old compiler API is a `BindingContext`, a universal dictionary:
@@ -422,4 +426,32 @@ fun hasAnnotation(declaration: KtDeclaration): Boolean {
422426
return SPECIAL_ANNOTATION_CLASS_ID in declaration.symbol.annotations
423427
}
424428
}
425-
```
429+
```
430+
431+
## Declaring compatibility with the K2 Kotlin mode
432+
433+
The Kotlin IntelliJ plugin assumes that a dependent third-party plugin *does not* support K2 Kotlin out of the box. Such
434+
incompatible plugins will not be loaded if the K2 mode is currently enabled.
435+
436+
Once a plugin has been migrated to the Analysis API, a setting should be added to its `plugin.xml` to declare its
437+
compatibility with the K2 mode. Even if the plugin does not use any of the old K1 analysis functions and no migration to
438+
the Analysis API is needed, compatibility with the K2 Kotlin plugin should be declared explicitly nonetheless.
439+
440+
Starting from IntelliJ 2024.2.1 (EAP), the following setting in the `plugin.xml` can be used to declare compatibility
441+
with the K2 mode:
442+
443+
```xml
444+
<extensions defaultExtensionNs="org.jetbrains.kotlin">
445+
<supportsKotlinPluginMode supportsK2="true" />
446+
</extensions>
447+
```
448+
449+
It is also possible to declare compatibility with *only* the K2 mode:
450+
451+
```xml
452+
<extensions defaultExtensionNs="org.jetbrains.kotlin">
453+
<supportsKotlinPluginMode supportsK1="false" supportsK2="true" />
454+
</extensions>
455+
```
456+
457+
Currently, the default setting for `supportsK1` is `true` and for `supportsK2` is `false`.

0 commit comments

Comments
 (0)