generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go): add golang tool context provider #89
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
languages/shire-go/src/main/kotlin/com/phodal/shirelang/go/variable/GoLanguageProvider.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,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) | ||
} | ||
} | ||
} |
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