generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add ToolchainProvider extension point
Add ToolchainProvider extension point for providing toolchain functionality in the core module.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
core/src/main/kotlin/com/phodal/shirecore/provider/ToolchainProvider.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,52 @@ | ||
package com.phodal.shirecore.provider | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread | ||
import kotlin.reflect.KClass | ||
|
||
class ToolchainContextItem( | ||
val clazz: KClass<*>, | ||
var text: String | ||
) | ||
|
||
data class ToolchainPrepareContext( | ||
val sourceFile: PsiFile?, | ||
val extraItems: List<ToolchainContextItem> = emptyList(), | ||
val element: PsiElement? | ||
) | ||
|
||
interface ToolchainProvider { | ||
fun isApplicable(project: Project, creationContext: ToolchainPrepareContext): Boolean | ||
|
||
@RequiresBackgroundThread | ||
suspend fun collect(project: Project, creationContext: ToolchainPrepareContext): List<ToolchainContextItem> | ||
|
||
companion object { | ||
private val EP_NAME = ExtensionPointName<ToolchainProvider>("com.phodal.shireToolchainProvider") | ||
|
||
suspend fun gatherToolchainContextItems( | ||
project: Project, | ||
toolchainPrepareContext: ToolchainPrepareContext, | ||
): List<ToolchainContextItem> { | ||
val elements = mutableListOf<ToolchainContextItem>() | ||
|
||
val chatContextProviders = EP_NAME.extensionList | ||
for (provider in chatContextProviders) { | ||
try { | ||
val applicable = provider.isApplicable(project, toolchainPrepareContext) | ||
if (applicable) { | ||
elements.addAll(provider.collect(project, toolchainPrepareContext)) | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
elements.addAll(toolchainPrepareContext.extraItems) | ||
return elements.distinctBy { it.text } | ||
} | ||
} | ||
} |
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