Skip to content

Commit

Permalink
feat(go): add golang tool context provider #89
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 14, 2024
1 parent ab09a6f commit 6058a5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.phodal.shirelang.go.variable

import com.goide.GoLanguage
import com.goide.sdk.GoSdkService
import com.goide.sdk.GoTargetSdkVersionProvider
import com.goide.util.GoUtil
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.project.Project
import com.phodal.shirecore.provider.context.LanguageToolchainProvider
import com.phodal.shirecore.provider.context.ToolchainContextItem
import com.phodal.shirecore.provider.context.ToolchainPrepareContext

class GoLanguageProvider : LanguageToolchainProvider {
override fun isApplicable(project: Project, context: ToolchainPrepareContext): Boolean {
return context.sourceFile?.language is GoLanguage
}

override suspend fun collect(project: Project, context: ToolchainPrepareContext): List<ToolchainContextItem> {
val sourceFile = context.sourceFile ?: return emptyList()

return ReadAction.compute<List<ToolchainContextItem>, Throwable> {
val goVersion = GoSdkService.getInstance(project).getSdk(GoUtil.module(sourceFile)).version
val targetVersion = GoTargetSdkVersionProvider.getTargetGoSdkVersion(sourceFile).toString()

val prompt = "Go Version: $goVersion, Target Version: $targetVersion"
val element = ToolchainContextItem(GoLanguageProvider::class, prompt)
listOf(element)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@
implementationClass="com.phodal.shirelang.go.codemodel.GoMethodStructureProvider"/>
<variableStructureProvider language="go"
implementationClass="com.phodal.shirelang.go.codemodel.GoVariableStructureProvider"/>

<shireLanguageToolchainProvider
language="go"
implementationClass="com.phodal.shirelang.go.variable.GoLanguageProvider"/>


<!-- <shirePsiVariableProvider-->
<!-- language="JAVA"-->
<!-- implementationClass="com.phodal.shirelang.java.variable.JavaPsiContextVariableProvider"/>-->
</extensions>
</idea-plugin>

0 comments on commit 6058a5a

Please sign in to comment.