Skip to content

Commit 0810501

Browse files
authored
Support multiple projects simultaneously (#789)
* fix: sourceplusplus/sourceplusplus#475 * refactor: use intellij logging * remove plugin debug console * gracefully handle config with removed settings * fix: reload compiled live plugins on project reset * fix: already disposed IncorrectOperationException * refactor: get live services from project refactor: get service discovery backend from project * fix: npe * refactor: get live status manager from project * fix check * unused
1 parent 7cd752b commit 0810501

File tree

73 files changed

+456
-686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+456
-686
lines changed

detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml
33

44
build:
5-
maxIssues: 26 #todo: zero out
5+
maxIssues: 38 #todo: zero out
66

77
formatting:
88
Indentation:

marker/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ dependencies {
3333
compileOnly("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
3434
compileOnly("com.google.guava:guava:31.1-jre")
3535
compileOnly("org.jetbrains:annotations:23.0.0")
36-
compileOnly("org.slf4j:slf4j-api:$slf4jVersion")
3736
compileOnly("org.jetbrains.intellij.deps.jcef:jcef:97.2.22-g6779618-chromium-97.0.4692.45-api-1.6")
3837
compileOnly("com.jetbrains.intellij.platform:ide:$intellijVersion")
3938
compileOnly("com.jetbrains.intellij.platform:ide-impl:$intellijVersion")

marker/jvm-marker/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ dependencies {
3232
compileOnly("io.vertx:vertx-core:$vertxVersion")
3333
compileOnly("io.vertx:vertx-lang-kotlin:$vertxVersion")
3434
compileOnly("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
35-
compileOnly("org.slf4j:slf4j-api:$slf4jVersion")
3635
compileOnly("org.jooq:joor:$joorVersion")
3736
compileOnly("org.apache.commons:commons-lang3:3.12.0")
3837
compileOnly("com.android.tools.external.org-jetbrains:uast:30.2.2")

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactNavigator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package spp.jetbrains.marker.jvm
1818

1919
import com.intellij.ide.util.PsiNavigationSupport
2020
import com.intellij.openapi.application.ApplicationManager
21+
import com.intellij.openapi.diagnostic.logger
2122
import com.intellij.openapi.editor.Document
2223
import com.intellij.openapi.project.Project
2324
import com.intellij.psi.JavaPsiFacade
@@ -29,7 +30,6 @@ import io.vertx.core.*
2930
import io.vertx.kotlin.coroutines.await
3031
import org.jetbrains.uast.UMethod
3132
import org.jetbrains.uast.toUElement
32-
import org.slf4j.LoggerFactory
3333
import spp.jetbrains.marker.source.JVMMarkerUtils
3434
import spp.protocol.artifact.ArtifactQualifiedName
3535
import spp.protocol.artifact.exception.LiveStackTraceElement
@@ -44,7 +44,7 @@ import spp.protocol.artifact.exception.sourceAsLineNumber
4444
*/
4545
object ArtifactNavigator {
4646

47-
private val log = LoggerFactory.getLogger(ArtifactNavigator::class.java)
47+
private val log = logger<ArtifactNavigator>()
4848

4949
//todo: remove method from method names and support navigating to classes?
5050

@@ -77,7 +77,7 @@ object ArtifactNavigator {
7777
handler.handle(Future.succeededFuture(true))
7878
}
7979
} else {
80-
log.warn("Could not find artifact: {}", artifactQualifiedName)
80+
log.warn("Could not find artifact: $artifactQualifiedName")
8181
handler.handle(Future.succeededFuture(false))
8282
}
8383
}

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactSearch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ object ArtifactSearch {
109109
@Suppress("UnstableApiUsage")
110110
suspend fun findArtifact(vertx: Vertx, artifact: ArtifactQualifiedName): PsiElement? {
111111
val promise = Promise.promise<Optional<PsiElement>>()
112-
val project = ProjectManager.getInstance().openProjects[0]
112+
val project = ProjectManager.getInstance().openProjects[0] //todo: support multiple projects
113113

114114
ApplicationManager.getApplication().runReadAction {
115115
if (artifact.type == ArtifactType.CLASS) {

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package spp.jetbrains.marker.jvm
1818

1919
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
2020
import com.intellij.codeInsight.daemon.LineMarkerInfo
21+
import com.intellij.openapi.diagnostic.logger
2122
import com.intellij.openapi.editor.markup.GutterIconRenderer
2223
import com.intellij.psi.PsiClass
2324
import com.intellij.psi.PsiElement
@@ -29,7 +30,6 @@ import org.jetbrains.uast.UClass
2930
import org.jetbrains.uast.UMethod
3031
import org.jetbrains.uast.toUElement
3132
import org.jetbrains.uast.toUElementOfType
32-
import org.slf4j.LoggerFactory
3333
import spp.jetbrains.marker.SourceMarker
3434
import spp.jetbrains.marker.impl.ArtifactCreationService
3535
import spp.jetbrains.marker.plugin.SourceLineMarkerProvider
@@ -50,7 +50,7 @@ import spp.jetbrains.marker.source.mark.gutter.MethodGutterMark
5050
abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() {
5151

5252
companion object {
53-
private val log = LoggerFactory.getLogger(JVMLineMarkerProvider::class.java)
53+
private val log = logger<JVMLineMarkerProvider>()
5454
}
5555

5656
override fun getLineMarkerInfo(
@@ -65,9 +65,9 @@ abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() {
6565
}
6666

6767
private fun getClassGutterMark(element: PsiIdentifier): LineMarkerInfo<PsiElement>? {
68-
val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile) ?: return null
68+
val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) ?: return null
6969
val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(element.parent.toUElement() as UClass)
70-
if (!SourceMarker.configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null
70+
if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null
7171

7272
//check by artifact name first due to user can erroneously name same class twice
7373
var gutterMark = fileMarker.getSourceMark(artifactQualifiedName, SourceMark.Type.GUTTER) as ClassGutterMark?
@@ -95,14 +95,14 @@ abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() {
9595
}
9696

9797
private fun getMethodGutterMark(element: PsiElement): LineMarkerInfo<PsiElement>? {
98-
val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile) ?: return null
98+
val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) ?: return null
9999
val uMethod = element.parent.toUElementOfType<UMethod>()
100100
if (uMethod == null) {
101-
log.warn("Unable to transform to UMethod: {}", element.parent)
101+
log.warn("Unable to transform to UMethod: ${element.parent}")
102102
return null
103103
}
104104
val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(uMethod)
105-
if (!SourceMarker.configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null
105+
if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null
106106

107107
//check by artifact name first due to user can erroneously name same method twice
108108
var gutterMark = fileMarker.getSourceMark(

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ class JVMSourceInlayHintProvider : SourceInlayHintProvider() {
4444
if ((parent is PsiMethod && element === parent.nameIdentifier)
4545
|| (JVMMarkerUtils.getNameIdentifier(parent) === element)
4646
) {
47-
val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile)!!
47+
val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile)!!
4848
val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(parent.toUElement() as UMethod)
49-
return if (!SourceMarker.configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else {
49+
return if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else {
5050
JVMMarkerUtils.getOrCreateMethodInlayMark(fileMarker, element)
5151
}
5252
} else if (element is PsiStatement) {
53-
val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile)!!
53+
val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile)!!
5454
val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(
5555
JVMMarkerUtils.getUniversalExpression(element).toUElement() as UExpression
5656
)
57-
return if (!SourceMarker.configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else {
57+
return if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else {
5858
JVMMarkerUtils.getOrCreateExpressionInlayMark(fileMarker, element)
5959
}
6060
}

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/LoggerDetector.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package spp.jetbrains.marker.jvm.psi
1818

1919
import com.intellij.openapi.application.ApplicationManager
20+
import com.intellij.openapi.diagnostic.logger
2021
import com.intellij.openapi.editor.Editor
2122
import com.intellij.openapi.editor.LogicalPosition
2223
import com.intellij.openapi.util.TextRange
@@ -33,7 +34,6 @@ import kotlinx.coroutines.launch
3334
import kotlinx.coroutines.runBlocking
3435
import org.jetbrains.uast.UMethod
3536
import org.jetbrains.uast.toUElementOfType
36-
import org.slf4j.LoggerFactory
3737
import spp.jetbrains.marker.source.SourceFileMarker
3838
import spp.jetbrains.marker.source.mark.api.MethodSourceMark
3939
import spp.jetbrains.marker.source.mark.api.key.SourceKey
@@ -48,7 +48,7 @@ import spp.jetbrains.marker.source.mark.inlay.InlayMark
4848
class LoggerDetector(val vertx: Vertx) {
4949

5050
companion object {
51-
private val log = LoggerFactory.getLogger(LoggerDetector::class.java)
51+
private val log = logger<LoggerDetector>()
5252
val LOGGER_STATEMENTS = SourceKey<List<DetectedLogger>>("LOGGER_STATEMENTS")
5353

5454
private val LOGGER_CLASSES = setOf(

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/source/JVMMarkerUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
*/
1717
package spp.jetbrains.marker.source
1818

19+
import com.intellij.openapi.diagnostic.logger
1920
import com.intellij.psi.*
2021
import com.intellij.psi.util.PsiUtil
2122
import org.jetbrains.uast.*
2223
import org.joor.Reflect
23-
import org.slf4j.LoggerFactory
2424
import spp.jetbrains.marker.SourceMarkerUtils
2525
import spp.jetbrains.marker.source.mark.api.SourceMark
2626
import spp.jetbrains.marker.source.mark.api.key.SourceKey
@@ -42,7 +42,7 @@ import java.util.*
4242
@Suppress("TooManyFunctions")
4343
object JVMMarkerUtils {
4444

45-
private val log = LoggerFactory.getLogger(JVMMarkerUtils::class.java)
45+
private val log = logger<JVMMarkerUtils>()
4646

4747
/**
4848
* todo: description.
@@ -445,7 +445,7 @@ object JVMMarkerUtils {
445445
if (gutterMark == null) {
446446
val uClass = element.parent.toUElement() as UClass
447447
if (uClass.qualifiedName == null) {
448-
log.warn("Could not determine qualified name of class: {}", uClass)
448+
log.warn("Could not determine qualified name of class: $uClass")
449449
return null
450450
}
451451
gutterMark = fileMarker.createClassSourceMark(
@@ -611,7 +611,7 @@ object JVMMarkerUtils {
611611
it.type.canonicalText
612612
}
613613
} else {
614-
log.warn("Unable to detect element type: {}", it)
614+
log.warn("Unable to detect element type: $it")
615615
}
616616
}
617617
return "$methodName($methodParams)"

0 commit comments

Comments
 (0)