This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
[feat] GO support #43
Draft
maclick
wants to merge
35
commits into
JetBrains:main
Choose a base branch
from
maclick:go-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
927fe14
[feature] create go build target |#BAZEL-784 Done
zortenburger dea7e27
calculateAllGoSdkInfos done
kronosmichall 22e2e8a
added setSdk
kronosmichall 40d76e8
go sdk mock works
kronosmichall a843252
changed home path to /usr/local/go
kronosmichall e53c401
added isGoSupportEnabled = true for each module
kronosmichall 5f47add
extension point for Go SDK - not yet full working
maclick e3f49be
Merge branch 'main' into go-support
maclick 1e1d048
Merge remote-tracking branch 'upstream/main' into go-support
maclick f77ae5e
clenup
maclick 2de6adc
Work in progress, add internal dependencies
edokimok f8bd25b
cos
abrams27 1e8f812
Merge remote-tracking branch 'upstream/main' into go-support
maclick 368bb0c
merge cleanup
maclick 9f5e27b
small style changes
maclick 369b5f7
Fix indentation, cleanup (#4)
edokimok f275b76
GoModule toState (#3)
kronosmichall d43fa4e
Merge remote-tracking branch 'upstream/main' into go-support
maclick cf5f1a1
cleanup after main merge
maclick ca18964
fix detekt
maclick b37a80d
Go support sources (#5)
zortenburger b356780
move go plugin usages to extension point (#6)
maclick b082f1d
Fix go related data in MMM state (#7)
maclick 47089ed
Merge branch 'upstream-main' into go-support
maclick ea83181
WIP, working importpath, empty root
edokimok 1bd89ea
pass target root for Go build targets
maclick 4876112
Green code!
edokimok de6e867
Minor fix
edokimok d9efbeb
Add shouldAddMarker for Go top level functions
edokimok 58e66a3
Set should replace to true
edokimok c24bbda
Merge remote-tracking branch 'refs/remotes/upstream/main' into backup
edokimok a9f3869
Try merge
edokimok 25c9a70
Merge pull request #10 from edokimok/backup
maclick d0eb941
Add tests for Go resources
zortenburger 9fa7c74
Merge pull request #11 from zortenburger/go-support-resources-tests
maclick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,8 @@ | ||
package org.jetbrains.bsp | ||
|
||
import java.net.URI | ||
|
||
public data class GoBuildTarget( | ||
val sdkHomePath: URI?, | ||
val importPath: String, | ||
) |
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
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
85 changes: 85 additions & 0 deletions
85
src/main/kotlin/org/jetbrains/plugins/bsp/extension/points/GoSdkGetterExtension.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,85 @@ | ||
package org.jetbrains.plugins.bsp.extension.points | ||
|
||
import ch.epfl.scala.bsp4j.BuildTarget | ||
import com.goide.project.GoModuleSettings | ||
import com.goide.sdk.GoSdk | ||
import com.goide.sdk.GoSdkService | ||
import com.goide.vgo.project.workspaceModel.VgoWorkspaceModelUpdater | ||
import com.intellij.openapi.application.writeAction | ||
import com.intellij.openapi.extensions.ExtensionPointName | ||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.project.Project | ||
import org.jetbrains.bsp.protocol.utils.extractGoBuildTarget | ||
import org.jetbrains.plugins.bsp.magicmetamodel.ProjectDetails | ||
|
||
public interface GoSdkGetterExtension { | ||
public suspend fun addGoSdks( | ||
project: Project, | ||
) | ||
|
||
public fun calculateAllGoSdkInfos( | ||
projectDetails: ProjectDetails, | ||
) | ||
|
||
public fun enableGoSupportForModule( | ||
module: Module, | ||
) | ||
|
||
public fun restoreGoModulesRegistry( | ||
project: Project, | ||
) | ||
} | ||
|
||
private val ep = ExtensionPointName.create<GoSdkGetterExtension>( | ||
"org.jetbrains.bsp.goSdkGetterExtension", | ||
) | ||
|
||
public fun goSdkExtension(): GoSdkGetterExtension? = ep.extensionList.firstOrNull() | ||
|
||
public fun goSdkExtensionExists(): Boolean = ep.extensionList.isNotEmpty() | ||
|
||
public class GoSdkGetter: GoSdkGetterExtension { | ||
private var goSdks: Set<GoSdk> = emptySet() | ||
|
||
override suspend fun addGoSdks( | ||
project: Project, | ||
) { | ||
val goSdkService = GoSdkService.getInstance(project) | ||
goSdks.forEach { | ||
writeAction { | ||
goSdkService.setSdk(it) | ||
} | ||
} | ||
} | ||
|
||
override fun calculateAllGoSdkInfos( | ||
projectDetails: ProjectDetails, | ||
) { | ||
goSdks = projectDetails.targets | ||
.mapNotNull { | ||
createGoSdk(it) | ||
} | ||
.toSet() | ||
} | ||
|
||
override fun enableGoSupportForModule( | ||
module: Module, | ||
) { | ||
GoModuleSettings.getInstance(module).isGoSupportEnabled = true | ||
} | ||
|
||
override fun restoreGoModulesRegistry( | ||
project: Project, | ||
) { | ||
VgoWorkspaceModelUpdater(project).restoreModulesRegistry() | ||
} | ||
|
||
private fun createGoSdk(target: BuildTarget): GoSdk? = | ||
extractGoBuildTarget(target)?.let { | ||
if (it.sdkHomePath == null) { | ||
GoSdk.NULL | ||
} else { | ||
GoSdk.fromHomePath(it.sdkHomePath?.path) | ||
} | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
.../org/jetbrains/plugins/bsp/magicmetamodel/impl/workspacemodel/GoWorkspaceModelEntities.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,34 @@ | ||
package org.jetbrains.plugins.bsp.magicmetamodel.impl.workspacemodel | ||
|
||
import org.jetbrains.plugins.bsp.magicmetamodel.impl.ModuleState | ||
import org.jetbrains.plugins.bsp.magicmetamodel.impl.toState | ||
import java.nio.file.Path | ||
|
||
public data class GoModuleDependency( | ||
val importPath: String, | ||
val root: Path, | ||
) | ||
|
||
public data class GoModule( | ||
val module: GenericModuleInfo, | ||
val sourceRoots: List<GenericSourceRoot>, | ||
val resourceRoots: List<ResourceRoot>, | ||
val importPath: String, | ||
val root: Path, | ||
val goDependencies: List<GoModuleDependency>, | ||
) : WorkspaceModelEntity(), Module { | ||
override fun toState(): ModuleState = ModuleState( | ||
module = module.toState(), | ||
sourceRoots = sourceRoots.map { it.toState() }, | ||
resourceRoots = resourceRoots.map { it.toState() }, | ||
goAddendum = GoAddendum(importPath, root, goDependencies).toState(), | ||
) | ||
|
||
override fun getModuleName(): String = module.name | ||
} | ||
|
||
public data class GoAddendum( | ||
var importPath: String, | ||
var root: Path, | ||
val goDependencies: List<GoModuleDependency>, | ||
) |
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
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ import org.jetbrains.workspacemodel.entities.AndroidTargetType.TEST | |
import org.jetbrains.workspacemodel.entities.androidAddendumEntity | ||
import org.jetbrains.workspacemodel.entities.jvmBinaryJarsEntity | ||
import java.nio.file.Path | ||
import kotlin.io.path.Path | ||
|
||
public object WorkspaceModelToModulesMapTransformer { | ||
public operator fun invoke( | ||
|
@@ -95,6 +96,7 @@ public object WorkspaceModelToModulesMapTransformer { | |
languageIds = entity.customImlData?.customModuleOptions.orEmpty(), | ||
associates = entity.getKotlinSettings()?.getAssociates().orEmpty(), | ||
) | ||
// TODO: add support for GoModule | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump |
||
val module = if (genericModuleInfo.languageIds.includesPython()) { | ||
PythonModule( | ||
module = genericModuleInfo, | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension points shouldnt have state, so i'd be better to keep it in a service with state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump (you can check
DefaultConnectionDetailsProviderExtension
for an inspiration)