-
Notifications
You must be signed in to change notification settings - Fork 13
[feat] GO support #43
base: main
Are you sure you want to change the base?
Changes from 30 commits
927fe14
dea7e27
22e2e8a
40d76e8
a843252
e53c401
5f47add
e3f49be
1e1d048
f77ae5e
2de6adc
f8bd25b
1e8f812
368bb0c
9f5e27b
369b5f7
f275b76
d43fa4e
cf5f1a1
ca18964
b37a80d
b356780
b082f1d
47089ed
ea83181
1bd89ea
4876112
de6e867
d9efbeb
58e66a3
c24bbda
a9f3869
25c9a70
d0eb941
9fa7c74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
package org.jetbrains.bsp.protocol | ||
|
||
import ch.epfl.scala.bsp4j.BuildTargetIdentifier | ||
import java.net.URI | ||
|
||
public data class LibraryItem( | ||
val id: BuildTargetIdentifier, | ||
val dependencies: List<BuildTargetIdentifier>, | ||
val ijars: List<String>, | ||
val jars: List<String>, | ||
val sourceJars: List<String>, | ||
) | ||
val goImportPath: String? = "", | ||
val goRoot: URI? = URI(""), | ||
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. same here |
||
) | ||
|
||
public data class WorkspaceLibrariesResult( | ||
val libraries: List<LibraryItem>, | ||
|
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() | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. bump (you can check |
||
|
||
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) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jetbrains.plugins.bsp.magicmetamodel.impl.workspacemodel | ||
|
||
import org.jetbrains.bsp.protocol.LibraryItem | ||
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>, | ||
val goLibraries: List<LibraryItem> = emptyList(), | ||
) : 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>, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,9 @@ public data class Library( | |
val iJars: List<String> = listOf(), | ||
val sourceJars: List<String> = listOf(), | ||
val classJars: List<String> = listOf(), | ||
) : WorkspaceModelEntity(), ResourceRootEntity { | ||
val goImportPath: String? = "", | ||
val goRoot: URI? = URI(""), | ||
Comment on lines
+57
to
+58
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. same here - it can be null |
||
) : WorkspaceModelEntity(), ResourceRootEntity { | ||
public companion object { | ||
public fun formatJarString(jar: String): String = | ||
if (jar.endsWith(".jar")) { | ||
|
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, | ||
|
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.
if it's nullable, why default is not null?