generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kotlin): add KotlinVersionProvider
This commit adds a new KotlinVersionProvider class to the Kotlin project. The KotlinVersionProvider is responsible for collecting the Kotlin API version information and providing it as a context item in the chat.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
kotlin/src/main/kotlin/cc/unitmesh/kotlin/provider/KotlinVersionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cc.unitmesh.kotlin.provider | ||
|
||
import cc.unitmesh.devti.provider.context.ChatContextItem | ||
import cc.unitmesh.devti.provider.context.ChatContextProvider | ||
import cc.unitmesh.devti.provider.context.ChatCreationContext | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.Project | ||
import org.jetbrains.kotlin.idea.KotlinLanguage | ||
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings | ||
import kotlin.coroutines.Continuation | ||
|
||
class KotlinVersionProvider : ChatContextProvider { | ||
override fun isApplicable(project: Project, creationContext: ChatCreationContext): Boolean { | ||
return creationContext.sourceFile?.language is KotlinLanguage | ||
} | ||
|
||
override suspend fun collect(project: Project, creationContext: ChatCreationContext): List<ChatContextItem> { | ||
val languageVersionSettings = runReadAction { | ||
project.languageVersionSettings | ||
} | ||
|
||
val languageVersion = languageVersionSettings.languageVersion.versionString | ||
return listOf(ChatContextItem(KotlinVersionProvider::class, "Kotlin API version: $languageVersion")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters