Skip to content

Commit

Permalink
[maintenance] BuildTargetClassifierExtension uses WithBuildToolId
Browse files Browse the repository at this point in the history
… api now

default impl

default removal

rebase fix

Merge remote-tracking branch 'origin/main' into abrams/target-classifier-ep

# Conflicts:
#	src/main/kotlin/org/jetbrains/plugins/bsp/extension/points/BspBuildTargetClassifierExtension.kt
#	src/main/resources/META-INF/plugin.xml

Merge remote-tracking branch 'origin/main' into abrams/target-classifier-ep

# Conflicts:
#	src/main/kotlin/org/jetbrains/plugins/bsp/config/PersistentProjectProperties.kt
#	src/main/kotlin/org/jetbrains/plugins/bsp/extension/points/WithBuildToolId.kt
#	src/main/kotlin/org/jetbrains/plugins/bsp/ui/widgets/tool/window/components/BuildTargetTree.kt

[maintenance] `BuildTargetClassifierExtension` update

[maintenance] `WithBuildToolId` moved to a better location


Merge-request: BAZEL-MR-672
Merged-by: Marcin Abramowicz <[email protected]>
  • Loading branch information
abrams27 authored and qodana-bot committed Nov 29, 2023
1 parent 6e78a87 commit 38f151b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 100 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.jetbrains.plugins.bsp.extension.points

import com.intellij.openapi.extensions.ExtensionPointName
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId

public interface BuildTargetClassifierExtension : WithBuildToolId {
/**
* Sets a separator for chaining target directories. Example:
* ```
* aaa
* | bbb
* | ccc
* | ddd
* | eee
* | BUILD_TARGET
* ```
* If the separator is set (for example to "+_"), the tree above will be rendered as:
* ```
* aaa
* | bbb
* | ccc+_ddd+_eee
* | BUILD_TARGET
* ```
* This affects only directories with just one child, this child being another directory
*/
public val separator: String?

/**
* @param buildTargetIdentifier a build target
* @return list of directories corresponding to a desired path of the given build target in the tree.
* For example, path `["aaa", "bbb"]` will render as:
* ```
* aaa
* | bbb
* | <buildTarget>
* ```
* If an empty list is returned, the build target will be rendered in the tree's top level
*/
public fun calculateBuildTargetPath(buildTargetIdentifier: BuildTargetId): List<String>

/**
* @param buildTargetIdentifier a build target
* @return the name under which the given build target will be rendered in the tree
*/
public fun calculateBuildTargetName(buildTargetIdentifier: BuildTargetId): String

public companion object {
internal val ep =
ExtensionPointName.create<BuildTargetClassifierExtension>("org.jetbrains.bsp.buildTargetClassifierExtension")
}
}

/**
* Default implementation of the [BuildTargetClassifierExtension] interface.
* It will be used in BSP project and when no other implementation exists.
*/
internal class DefaultBuildTargetClassifierExtension : BuildTargetClassifierExtension {
override val buildToolId: BuildToolId = bspBuildToolId

override val separator: String? = null

override fun calculateBuildTargetPath(buildTargetIdentifier: BuildTargetId): List<String> = emptyList()

override fun calculateBuildTargetName(buildTargetIdentifier: BuildTargetId): String = buildTargetIdentifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import com.intellij.util.PlatformIcons
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetInfo
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.extension.points.BspBuildTargetClassifierExtension
import org.jetbrains.plugins.bsp.extension.points.BuildTargetClassifierExtension
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.actions.CopyTargetIdAction
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.utils.BspBuildTargetClassifierProvider
import java.awt.Component
import java.awt.event.MouseListener
import javax.swing.Icon
Expand Down Expand Up @@ -47,25 +47,25 @@ public class BuildTargetTree(
}

private fun generateTree() {
val bspBuildTargetClassifierProvider =
BspBuildTargetClassifierProvider(buildToolId.id, BspBuildTargetClassifierExtension.extensions())
val bspBuildTargetClassifier = BuildTargetClassifierExtension.ep.withBuildToolIdOrDefault(buildToolId)

generateTreeFromIdentifiers(
targets.map {
BuildTargetTreeIdentifier(
it.id,
it,
bspBuildTargetClassifierProvider.getBuildTargetPath(it.id),
bspBuildTargetClassifierProvider.getBuildTargetName(it.id),
bspBuildTargetClassifier.calculateBuildTargetPath(it.id),
bspBuildTargetClassifier.calculateBuildTargetName(it.id),
)
} + invalidTargets.map {
BuildTargetTreeIdentifier(
it,
null,
bspBuildTargetClassifierProvider.getBuildTargetPath(it),
bspBuildTargetClassifierProvider.getBuildTargetName(it),
bspBuildTargetClassifier.calculateBuildTargetPath(it),
bspBuildTargetClassifier.calculateBuildTargetName(it),
)
},
bspBuildTargetClassifierProvider.getSeparator(),
bspBuildTargetClassifier.separator,
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import com.intellij.openapi.project.Project
import org.jetbrains.magicmetamodel.DefaultModuleNameProvider
import org.jetbrains.magicmetamodel.ModuleNameProvider
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.extension.points.BspBuildTargetClassifierExtension
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.utils.BspBuildTargetClassifierProvider
import org.jetbrains.plugins.bsp.extension.points.BuildTargetClassifierExtension
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault

public fun Project.findModuleNameProvider(): ModuleNameProvider? =
this.buildToolId.takeIf { it.id != "bsp" }?.let { createModuleNameProvider(it.id) }
this.buildToolId.takeIf { it.id != "bsp" }?.let { createModuleNameProvider(it) }

private fun createModuleNameProvider(buildToolId: BuildToolId): ModuleNameProvider {
val bspBuildTargetClassifier = BuildTargetClassifierExtension.ep.withBuildToolIdOrDefault(buildToolId)

private fun createModuleNameProvider(toolName: String): ModuleNameProvider {
val targetClassifier =
BspBuildTargetClassifierProvider(toolName, BspBuildTargetClassifierExtension.extensions())
return {
val sanitizedName = targetClassifier.getBuildTargetName(it).replaceDots()
targetClassifier.getBuildTargetPath(it)
val sanitizedName = bspBuildTargetClassifier.calculateBuildTargetName(it).replaceDots()
bspBuildTargetClassifier.calculateBuildTargetPath(it)
.joinToString(".", postfix = ".$sanitizedName") { pathElement -> pathElement.replaceDots() }
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<extensionPoint interface="org.jetbrains.plugins.bsp.extension.points.BspConnectionDetailsGeneratorExtension"
name="bspConnectionDetailsGeneratorExtension"
dynamic="true"/>
<extensionPoint name="bspBuildTargetClassifierExtension"
interface="org.jetbrains.plugins.bsp.extension.points.BspBuildTargetClassifierExtension"
<extensionPoint name="buildTargetClassifierExtension"
interface="org.jetbrains.plugins.bsp.extension.points.BuildTargetClassifierExtension"
dynamic="true"/>
<extensionPoint name="pythonSdkGetterExtension"
interface="org.jetbrains.plugins.bsp.extension.points.PythonSdkGetterExtension"
Expand All @@ -35,6 +35,9 @@
<extensions defaultExtensionNs="org.jetbrains.bsp">
<buildToolAssetsExtension
implementation="org.jetbrains.plugins.bsp.assets.BspAssetsExtension"/>

<buildTargetClassifierExtension
implementation="org.jetbrains.plugins.bsp.extension.points.DefaultBuildTargetClassifierExtension"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
Expand Down

0 comments on commit 38f151b

Please sign in to comment.