Skip to content

Commit

Permalink
feat(kotlin): add KotlinVersionProvider
Browse files Browse the repository at this point in the history
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
phodal committed Jan 11, 2024
1 parent e4f319a commit 92c6611
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
@@ -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"))
}
}
1 change: 1 addition & 0 deletions kotlin/src/main/resources/cc.unitmesh.kotlin.xml
Expand Up @@ -29,6 +29,7 @@
<variableContextBuilder language="kotlin"
implementationClass="cc.unitmesh.kotlin.context.KotlinVariableContextBuilder"/>

<chatContextProvider implementation="cc.unitmesh.kotlin.provider.KotlinVersionProvider"/>
<chatContextProvider implementation="cc.unitmesh.kotlin.provider.KotlinTestContextProvider"/>

<contextPrompter
Expand Down

0 comments on commit 92c6611

Please sign in to comment.