From 37e5edcca1cbcb74f3808d05d103cb42f8630b5e Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 30 Sep 2022 13:25:17 +0400 Subject: [PATCH 01/28] fix: Kotlin logger detection --- .../marker/jvm/JVMArtifactScopeService.kt | 4 ++ .../marker/jvm/psi/JVMLoggerDetector.kt | 29 ++++++++------ .../marker/jvm/psi/JVMLoggerDetectorTest.kt | 39 ++++++++++++++++++- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt index 10520bf28..a69cef25d 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt @@ -21,6 +21,7 @@ import com.intellij.psi.scope.processor.VariablesProcessor import com.intellij.psi.scope.util.PsiScopesUtil import com.intellij.psi.util.parentOfTypes import com.siyeh.ig.psiutils.ControlFlowUtils +import org.jetbrains.kotlin.psi.KtNamedFunction import spp.jetbrains.marker.IArtifactScopeService import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.source.SourceFileMarker @@ -60,6 +61,9 @@ class JVMArtifactScopeService : IArtifactScopeService { } override fun isInsideFunction(element: PsiElement): Boolean { + if (element.language.id == "kotlin") { + return element.parentOfTypes(KtNamedFunction::class) != null + } return element.parentOfTypes(PsiMethod::class) != null } diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt index fe9d9e8cb..8333d3490 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt @@ -20,11 +20,15 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.openapi.util.Computable -import com.intellij.psi.* +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiElement import com.intellij.refactoring.suggested.endOffset import com.intellij.refactoring.suggested.startOffset +import org.jetbrains.uast.UCallExpression +import org.jetbrains.uast.ULiteralExpression import org.jetbrains.uast.UMethod import org.jetbrains.uast.toUElementOfType +import org.jetbrains.uast.visitor.AbstractUastVisitor import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.info.LoggerDetector import spp.jetbrains.marker.source.info.LoggerDetector.Companion.DETECTED_LOGGER @@ -66,15 +70,17 @@ class JVMLoggerDetector(val project: Project) : LoggerDetector { fun determineLoggerStatements(uMethod: UMethod, fileMarker: SourceFileMarker): List { val loggerStatements = mutableListOf() ApplicationManager.getApplication().runReadAction { - uMethod.javaPsi.accept(object : JavaRecursiveElementVisitor() { - override fun visitMethodCallExpression(expression: PsiMethodCallExpression) { - val methodName = expression.methodExpression.referenceName - if (methodName != null && LOGGER_METHODS.contains(methodName)) { - val resolvedMethod = expression.resolveMethod() ?: return - if (LOGGER_CLASSES.contains(resolvedMethod.containingClass?.qualifiedName.orEmpty())) { - val logTemplate = (expression.argumentList.expressions.firstOrNull()?.run { - (this as? PsiLiteral)?.value as? String - }) + uMethod.accept(object : AbstractUastVisitor() { + override fun visitCallExpression(node: UCallExpression): Boolean { + val expression = node.sourcePsi ?: return super.visitCallExpression(node) + val loggerClass = node.resolve()?.containingClass?.qualifiedName + if (loggerClass != null && LOGGER_CLASSES.contains(loggerClass)) { + val methodName = node.methodIdentifier?.name + if (methodName != null && LOGGER_METHODS.contains(methodName)) { + val logTemplate = node.valueArguments.firstOrNull()?.run { + (this as? ULiteralExpression)?.value as? String + } + if (logTemplate != null) { log.debug("Found log statement: $logTemplate") val detectedLogger = DetectedLogger( @@ -84,7 +90,7 @@ class JVMLoggerDetector(val project: Project) : LoggerDetector { //create expression guide mark for the log statement val guideMark = fileMarker.createExpressionSourceMark( - expression, SourceMark.Type.GUIDE + expression.parent, SourceMark.Type.GUIDE ) if (!fileMarker.containsSourceMark(guideMark)) { guideMark.putUserData(DETECTED_LOGGER, detectedLogger) @@ -98,6 +104,7 @@ class JVMLoggerDetector(val project: Project) : LoggerDetector { } } } + return super.visitCallExpression(node) } }) } diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt index a4d1cf7a2..28f8bd147 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt @@ -32,6 +32,7 @@ import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import io.vertx.core.Vertx import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.idea.core.util.toPsiFile +import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.UserData @@ -120,7 +121,7 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { TestApplicationManager.getInstance().setDataProvider(null) } - fun testLogbackLogger() { + fun testJavaLogbackLogger() { @Language("Java") val code = """ import ch.qos.logback.classic.Logger; public class TestLogback { @@ -155,4 +156,40 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") } } + + fun testKotlinLogbackLogger() { + @Language("kotlin") val code = """ + import ch.qos.logback.classic.Logger + class TestLogback { + val log: Logger = Logger() + fun loggers() { + log.trace("trace {}", "trace") + log.debug("debug {}", "debug") + log.info("info {}", "info") + log.warn("warn {}", "warn") + log.error("error {}", "error") + } + } + """.trimIndent() + + ApplicationManager.getApplication().runReadAction { + val sourceFile = myFixture.createFile("TestLogback.kt", code).toPsiFile(project) + assertNotNull(sourceFile) + + val uFile = sourceFile.toUElement() as UFile + assertEquals(1, uFile.classes.size) + assertEquals(3, uFile.classes[0].methods.size) + + JVMMarker.setup() + SourceFileMarker.SUPPORTED_FILE_TYPES.add(KtFile::class.java) + val fileMarker = SourceMarker.getInstance(project).getSourceFileMarker(sourceFile!!) + assertNotNull(fileMarker) + + val result = JVMLoggerDetector(project.apply { UserData.vertx(this, Vertx.vertx()) }) + .determineLoggerStatements(uFile.classes[0].methods[1], fileMarker!!) + .map { it.logPattern } + assertEquals(5, result.size) + assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") + } + } } From 39df2935362777fa461243f4032d15aedbfda947 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 30 Sep 2022 21:28:35 +0400 Subject: [PATCH 02/28] wip: groovy logger detector --- .../marker/jvm/psi/JVMLoggerDetector.kt | 66 +++++++++++++++++-- .../marker/jvm/psi/JVMLoggerDetectorTest.kt | 38 +++++++++++ 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt index 8333d3490..157e95502 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt @@ -22,8 +22,12 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.Computable import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement +import com.intellij.psi.PsiRecursiveElementVisitor import com.intellij.refactoring.suggested.endOffset import com.intellij.refactoring.suggested.startOffset +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.uast.UCallExpression import org.jetbrains.uast.ULiteralExpression import org.jetbrains.uast.UMethod @@ -58,11 +62,15 @@ class JVMLoggerDetector(val project: Project) : LoggerDetector { } override fun determineLoggerStatements(guideMark: MethodGuideMark): List { - val uMethod = ApplicationManager.getApplication().runReadAction(Computable { - guideMark.getPsiMethod().toUElementOfType() - }) - if (uMethod != null) { - determineLoggerStatements(uMethod, guideMark.sourceFileMarker) + if (guideMark.language.id == "Groovy") { + determineLoggerStatements(guideMark.getPsiMethod() as GrMethod, guideMark.sourceFileMarker) + } else { + val uMethod = ApplicationManager.getApplication().runReadAction(Computable { + guideMark.getPsiMethod().toUElementOfType() + }) + if (uMethod != null) { + determineLoggerStatements(uMethod, guideMark.sourceFileMarker) + } } return guideMark.getChildren().mapNotNull { it.getUserData(DETECTED_LOGGER) } } @@ -111,6 +119,54 @@ class JVMLoggerDetector(val project: Project) : LoggerDetector { return loggerStatements } + /** + * Unsure why, but Groovy UAST visitors don't work here. Have to use Groovy PSI. + */ + fun determineLoggerStatements(grMethod: GrMethod, fileMarker: SourceFileMarker): List { + val loggerStatements = mutableListOf() + ApplicationManager.getApplication().runReadAction { + grMethod.acceptChildren(object : PsiRecursiveElementVisitor() { + override fun visitElement(element: PsiElement) { + if (element is GrMethodCallExpression) { + val loggerClass = element.resolveMethod()?.containingClass?.qualifiedName + if (loggerClass != null && LOGGER_CLASSES.contains(loggerClass)) { + val methodName = element.resolveMethod()?.name + if (methodName != null && LOGGER_METHODS.contains(methodName)) { + val logTemplate = element.argumentList.expressionArguments.firstOrNull()?.run { + (this as? GrLiteral)?.value as? String + } + + if (logTemplate != null) { + log.debug("Found log statement: $logTemplate") + val detectedLogger = DetectedLogger( + logTemplate, methodName, getLineNumber(element) + 1 + ) + loggerStatements.add(detectedLogger) + + //create expression guide mark for the log statement + val guideMark = fileMarker.createExpressionSourceMark( + element, SourceMark.Type.GUIDE + ) + if (!fileMarker.containsSourceMark(guideMark)) { + guideMark.putUserData(DETECTED_LOGGER, detectedLogger) + guideMark.apply(true) + } else { + fileMarker.getSourceMark(guideMark.artifactQualifiedName, SourceMark.Type.GUIDE) + ?.putUserData(DETECTED_LOGGER, detectedLogger) + } + } else { + log.warn("No log template argument available for expression: $element") + } + } + } + } + super.visitElement(element) + } + }) + } + return loggerStatements + } + private fun getLineNumber(element: PsiElement, start: Boolean = true): Int { val document = element.containingFile.viewProvider.document ?: PsiDocumentManager.getInstance(element.project).getDocument(element.containingFile) diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt index 28f8bd147..6f6e72ee3 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt @@ -33,6 +33,8 @@ import io.vertx.core.Vertx import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.idea.core.util.toPsiFile import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.UserData @@ -192,4 +194,40 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") } } + + fun testGroovyLogbackLogger() { + @Language("Groovy") val code = """ + import ch.qos.logback.classic.Logger + class TestLogback { + var log = new Logger() + void loggers() { + log.trace("trace {}", "trace") + log.debug("debug {}", "debug") + log.info("info {}", "info") + log.warn("warn {}", "warn") + log.error("error {}", "error") + } + } + """.trimIndent() + + ApplicationManager.getApplication().runReadAction { + val sourceFile = myFixture.createFile("TestLogback.groovy", code).toPsiFile(project) + assertNotNull(sourceFile) + + val uFile = sourceFile.toUElement() as UFile + assertEquals(1, uFile.classes.size) + assertEquals(1, uFile.classes[0].methods.size) + + JVMMarker.setup() + SourceFileMarker.SUPPORTED_FILE_TYPES.add(GroovyFile::class.java) + val fileMarker = SourceMarker.getInstance(project).getSourceFileMarker(sourceFile!!) + assertNotNull(fileMarker) + + val result = JVMLoggerDetector(project.apply { UserData.vertx(this, Vertx.vertx()) }) + .determineLoggerStatements(uFile.classes[0].methods[0].sourcePsi as GrMethod, fileMarker!!) + .map { it.logPattern } + assertEquals(5, result.size) + assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") + } + } } From 78f05a5822a16fc85fe855aa3e965800689dbe1f Mon Sep 17 00:00:00 2001 From: UltraDev Date: Fri, 30 Sep 2022 18:43:56 +0200 Subject: [PATCH 03/28] Navigate to line on stack frame changes (#857) * Navigate to line on stack frame changes * Check for non-null line number * fix: show execution point regression * fix: check for non-null line number Co-authored-by: Brandon Fergerson --- .../status/BreakpointStatusBar.java | 2 +- .../breakpoint/ExecutionPointManager.kt | 26 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/plugin/src/main/java/spp/jetbrains/sourcemarker/status/BreakpointStatusBar.java b/plugin/src/main/java/spp/jetbrains/sourcemarker/status/BreakpointStatusBar.java index cd8ece1ec..cb9cfa931 100644 --- a/plugin/src/main/java/spp/jetbrains/sourcemarker/status/BreakpointStatusBar.java +++ b/plugin/src/main/java/spp/jetbrains/sourcemarker/status/BreakpointStatusBar.java @@ -277,7 +277,7 @@ public void mouseClicked(MouseEvent e) { BreakpointHitWindowService.Companion.getInstance(inlayMark.getProject()) .clearContent(); BreakpointHitWindowService.Companion.getInstance(inlayMark.getProject()) - .showBreakpointHit(shownBreakpointHit.get(), false); + .showBreakpointHit(shownBreakpointHit.get(), true); }); } })); diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/ExecutionPointManager.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/ExecutionPointManager.kt index 32eb2a0a3..22118f148 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/ExecutionPointManager.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/ExecutionPointManager.kt @@ -25,12 +25,11 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor import com.intellij.openapi.project.Project import com.intellij.xdebugger.XDebuggerUtil import com.intellij.xdebugger.impl.ui.ExecutionPointHighlighter -import spp.jetbrains.marker.SourceMarker -import spp.protocol.artifact.exception.qualifiedClassName +import spp.jetbrains.marker.impl.ArtifactNamingService import spp.protocol.artifact.exception.sourceAsLineNumber /** - * todo: probably don't need this as the breakpoint bar serves as the execution point indicator + * Shows the execution point in the editor for the selected stack frame. * * @since 0.3.0 * @author [Brandon Fergerson](mailto:bfergerson@apache.org) @@ -47,18 +46,15 @@ class ExecutionPointManager( override fun onChanged(stackFrameManager: StackFrameManager) { if (!showExecutionPoint) return - val currentFrame = stackFrameManager.currentFrame - var fromClass = currentFrame!!.qualifiedClassName() - - //check for inner class - val indexOfDollarSign = fromClass.indexOf("$") - if (indexOfDollarSign >= 0) { - fromClass = fromClass.substring(0, indexOfDollarSign) - } - val fileMarker = SourceMarker.getInstance(project).getSourceFileMarker(fromClass) ?: return - val virtualFile = fileMarker.psiFile.containingFile.virtualFile ?: return + val currentFrame = stackFrameManager.currentFrame ?: return + val psiFile = stackFrameManager.stackTrace.language?.let { + ArtifactNamingService.getService(it).findPsiFile(it, project, currentFrame) + } ?: return + val virtualFile = psiFile.containingFile.virtualFile ?: return val document = FileDocumentManager.getInstance().getDocument(virtualFile) ?: return - val lineStartOffset = document.getLineStartOffset(currentFrame.sourceAsLineNumber()!!) - 1 + val lineStartOffset = currentFrame.sourceAsLineNumber()?.let { + document.getLineStartOffset(it) - 1 + } ?: return ApplicationManager.getApplication().invokeLater { try { @@ -69,7 +65,7 @@ class ExecutionPointManager( executionPointHighlighter.show( XDebuggerUtil.getInstance().createPositionByOffset( virtualFile, lineStartOffset - )!!, false, null + )!!, true, null ) } catch (e: Throwable) { log.error("Failed to set execution point", e) From 466f718b6df1799728c9137854240c1d67b3119c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 30 Sep 2022 18:32:04 +0000 Subject: [PATCH 04/28] fix(deps): update vertxversion to v4.3.4 (#856) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 25911beef..afa936e4f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ platformPlugins = java kotlin.stdlib.default.dependency = true apolloVersion=3.6.0 -vertxVersion=4.3.3 +vertxVersion=4.3.4 slf4jVersion=1.7.33 jacksonVersion=2.13.4 joorVersion=0.9.14 From 992e90c1f318eda1a45f6490a061e1f8dfc37c25 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 30 Sep 2022 22:38:41 +0400 Subject: [PATCH 05/28] refactor: remove unused --- .../jetbrains/marker/jvm/ArtifactNavigator.kt | 105 ------------- .../jetbrains/marker/jvm/ArtifactSearch.kt | 147 ------------------ 2 files changed, 252 deletions(-) delete mode 100644 marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactNavigator.kt delete mode 100644 marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactSearch.kt diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactNavigator.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactNavigator.kt deleted file mode 100644 index d47b95d46..000000000 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactNavigator.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spp.jetbrains.marker.jvm - -import com.intellij.ide.util.PsiNavigationSupport -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.diagnostic.logger -import com.intellij.openapi.editor.Document -import com.intellij.openapi.project.Project -import com.intellij.psi.JavaPsiFacade -import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.search.FilenameIndex.getFilesByName -import com.intellij.psi.search.GlobalSearchScope.allScope -import com.intellij.util.PsiNavigateUtil -import io.vertx.core.* -import io.vertx.kotlin.coroutines.await -import org.jetbrains.uast.UMethod -import org.jetbrains.uast.toUElement -import spp.jetbrains.marker.source.JVMMarkerUtils -import spp.protocol.artifact.ArtifactQualifiedName -import spp.protocol.artifact.exception.LiveStackTraceElement -import spp.protocol.artifact.exception.sourceAsFilename -import spp.protocol.artifact.exception.sourceAsLineNumber - -/** - * todo: description. - * - * @since 0.1.0 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -object ArtifactNavigator { - - private val log = logger() - - //todo: remove method from method names and support navigating to classes? - - fun navigateTo(project: Project, element: LiveStackTraceElement) { - ApplicationManager.getApplication().runReadAction { - val foundFiles = getFilesByName(project, element.sourceAsFilename()!!, allScope(project)) - if (foundFiles.isNotEmpty()) { - val file = foundFiles[0] - val document: Document = PsiDocumentManager.getInstance(file.project).getDocument(file)!! - val offset = document.getLineStartOffset(element.sourceAsLineNumber()!! - 1) - - ApplicationManager.getApplication().invokeLater { - PsiNavigationSupport.getInstance().createNavigatable(project, file.virtualFile, offset) - .navigate(true) - } - } - } - } - - suspend fun navigateTo( - vertx: Vertx, - artifactQualifiedName: ArtifactQualifiedName, - handler: Handler> - ) { - val artifactPsi = ArtifactSearch.findArtifact(vertx, artifactQualifiedName) - if (artifactPsi != null) { - ApplicationManager.getApplication().invokeLater { - PsiNavigateUtil.navigate(artifactPsi) - log.info("Navigated to artifact: $artifactQualifiedName") - handler.handle(Future.succeededFuture(true)) - } - } else { - log.warn("Could not find artifact: $artifactQualifiedName") - handler.handle(Future.succeededFuture(false)) - } - } - - suspend fun canNavigateTo(project: Project, artifactQualifiedName: ArtifactQualifiedName): Boolean { - val promise = Promise.promise() - ApplicationManager.getApplication().invokeLater { - promise.complete(canNavigateToMethod(project, artifactQualifiedName)) - } - return promise.future().await() - } - - fun canNavigateToMethod(project: Project, artifactQualifiedName: ArtifactQualifiedName): Boolean { - val classQualifiedName = JVMMarkerUtils.getQualifiedClassName(artifactQualifiedName) - val psiClass = JavaPsiFacade.getInstance(project).findClass(classQualifiedName.identifier, allScope(project)) - for (theMethod in psiClass!!.methods) { - val uMethod = theMethod.toUElement() as UMethod - val qualifiedName = JVMMarkerUtils.getFullyQualifiedName(uMethod) - if (qualifiedName == artifactQualifiedName) { - return true - } - } - return false - } -} diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactSearch.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactSearch.kt deleted file mode 100644 index a3b382754..000000000 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/ArtifactSearch.kt +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spp.jetbrains.marker.jvm - -import com.intellij.ide.highlighter.JavaFileType -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.project.ProjectManager -import com.intellij.psi.* -import com.intellij.psi.search.FileTypeIndex -import com.intellij.psi.search.GlobalSearchScope -import io.vertx.core.Promise -import io.vertx.core.Vertx -import io.vertx.kotlin.coroutines.await -import org.jetbrains.uast.UMethod -import org.jetbrains.uast.toUElement -import org.jetbrains.uast.toUElementOfType -import spp.jetbrains.ScopeExtensions.safeRunBlocking -import spp.jetbrains.marker.source.JVMMarkerUtils -import spp.protocol.artifact.ArtifactNameUtils -import spp.protocol.artifact.ArtifactQualifiedName -import spp.protocol.artifact.ArtifactType -import java.util.* - -/** - * todo: description. - * - * @since 0.1.0 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -object ArtifactSearch { - - @Suppress("UnstableApiUsage") - suspend fun findArtifact(vertx: Vertx, artifact: ArtifactQualifiedName): PsiElement? { - val promise = Promise.promise>() - val project = ProjectManager.getInstance().openProjects[0] //todo: support multiple projects - - ApplicationManager.getApplication().runReadAction { - if (artifact.type == ArtifactType.CLASS) { - val psiClass = JavaPsiFacade.getInstance(project).findClass( - artifact.identifier, GlobalSearchScope.allScope(project) - ) - promise.complete(Optional.ofNullable(psiClass)) - } else if (artifact.type == ArtifactType.METHOD) { - val psiClass = JavaPsiFacade.getInstance(project).findClass( - ArtifactNameUtils.getQualifiedClassName(artifact.identifier)!!, - GlobalSearchScope.allScope(project) - ) - for (theMethod in psiClass!!.methods) { - val uMethod = theMethod.toUElement() as UMethod - val qualifiedName = JVMMarkerUtils.getFullyQualifiedName(uMethod) - if (qualifiedName == artifact) { - promise.complete(Optional.of(theMethod)) - } - } - promise.tryComplete(Optional.empty()) - } else { - //todo: should be saving endpoints somewhere so don't always have to scan entire application -// val groovySourceFiles = FileTypeIndex.getFiles( -// GroovyFileType.GROOVY_FILE_TYPE, GlobalSearchScope.projectScope(project) -// ) - //todo: can't search here, need language specific search then combine - val javaSourceFiles = FileTypeIndex.getFiles( - JavaFileType.INSTANCE, GlobalSearchScope.projectScope(project) - ) -// val kotlinSourceFiles = FileTypeIndex.getFiles( -// KotlinFileType.INSTANCE, GlobalSearchScope.projectScope(project) -// ) - - val endpointDetector = JVMEndpointDetector(project) //todo: python - var keepSearching = true -// for (virtualFile in groovySourceFiles.union(javaSourceFiles).union(kotlinSourceFiles)) { - for (virtualFile in javaSourceFiles) { - val file = PsiManager.getInstance(project).findFile(virtualFile)!! - file.accept(object : PsiRecursiveElementVisitor(true) { - override fun visitElement(element: PsiElement) { - if (element is PsiMethod) { - safeRunBlocking { - val endpointName = - endpointDetector.determineEndpointName(element.toUElementOfType()!!).await() - if (endpointName.isPresent && endpointName.get().name == artifact.identifier) { - promise.complete(Optional.of(element)) - keepSearching = false - } else { - super.visitElement(element) - } - } - } else { - super.visitElement(element) - } - } - }) - - if (!keepSearching) break - } - promise.tryComplete(Optional.empty()) - } - } - return promise.future().await().orElse(null) - } - - //taken from: https://rosettacode.org/wiki/Longest_common_suffix#Kotlin - private fun commonSuffix(a: List): String { - val le = a.size - if (le == 0) { - return "" - } - if (le == 1) { - return a[0] - } - val le0 = a[0].length - var minLen = le0 - for (i in 1 until le) { - if (a[i].length < minLen) { - minLen = a[i].length - } - } - if (minLen == 0) { - return "" - } - var res = "" - val a1 = a.subList(1, a.size) - for (i in 1..minLen) { - val suffix = a[0].substring(le0 - i) - for (e in a1) { - if (!e.endsWith(suffix)) { - return res - } - } - res = suffix - } - return "" - } -} From e481b5be37e2343a7e7c1f75318223fa10223092 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 30 Sep 2022 16:25:08 -0300 Subject: [PATCH 06/28] refactor: improved packaging (#858) --- .../spp/jetbrains/marker/js/JavascriptMarker.kt | 1 + .../js/{ => detect}/JavascriptEndpointDetector.kt | 4 ++-- .../js/{ => detect}/JavascriptLoggerDetector.kt | 2 +- .../js/{psi => detect}/endpoint/ExpressEndpoint.kt | 2 +- .../{ => presentation}/JavascriptVariableRootNode.kt | 2 +- .../JavascriptVariableSimpleNode.kt | 2 +- .../JavascriptArtifactConditionService.kt | 2 +- .../JavascriptArtifactCreationService.kt | 2 +- .../{ => service}/JavascriptArtifactNamingService.kt | 2 +- .../{ => service}/JavascriptArtifactScopeService.kt | 2 +- .../{ => service}/JavascriptArtifactTypeService.kt | 2 +- .../jetbrains/marker/jvm/JVMLineMarkerProvider.kt | 2 +- .../kotlin/spp/jetbrains/marker/jvm/JVMMarker.kt | 1 + .../marker/jvm/JVMSourceInlayHintProvider.kt | 2 +- .../marker/jvm/{ => detect}/JVMEndpointDetector.kt | 8 ++++---- .../marker/jvm/{psi => detect}/JVMLoggerDetector.kt | 2 +- .../endpoint/SkywalkingTraceEndpoint.kt | 4 ++-- .../{psi => detect}/endpoint/SpringMVCEndpoint.kt | 5 ++--- .../jvm/{ => presentation}/JVMVariableSimpleNode.kt | 2 +- .../jvm/{ => service}/JVMArtifactConditionService.kt | 2 +- .../jvm/{ => service}/JVMArtifactCreationService.kt | 4 ++-- .../jvm/{ => service}/JVMArtifactNamingService.kt | 4 ++-- .../jvm/{ => service}/JVMArtifactScopeService.kt | 2 +- .../jvm/{ => service}/JVMArtifactTypeService.kt | 2 +- .../{source => jvm/service/utils}/JVMMarkerUtils.kt | 3 ++- .../marker/jvm/JVMArtifactNamingServiceTest.kt | 1 + .../jetbrains/marker/jvm/JVMConditionParserTest.kt | 1 + .../jvm/{psi => detect}/JVMLoggerDetectorTest.kt | 2 +- .../endpoint/AbstractEndpointDetectorTest.kt | 2 +- .../endpoint/GroovyEndpointDetectorTest.kt | 4 ++-- .../endpoint/JavaEndpointDetectorTest.kt | 4 ++-- .../endpoint/KotlinEndpointDetectorTest.kt | 4 ++-- .../endpoint/ScalaEndpointNameDetectorTest.kt | 4 ++-- .../kotlin/spp/jetbrains/marker/py/PythonMarker.kt | 1 + .../marker/py/{ => detect}/PythonEndpointDetector.kt | 4 ++-- .../marker/py/{ => detect}/PythonLoggerDetector.kt | 2 +- .../py/{psi => detect}/endpoint/FlaskEndpoint.kt | 2 +- .../py/{ => presentation}/PythonVariableRootNode.kt | 2 +- .../{ => presentation}/PythonVariableSimpleNode.kt | 2 +- .../{ => service}/PythonArtifactConditionService.kt | 2 +- .../{ => service}/PythonArtifactCreationService.kt | 2 +- .../py/{ => service}/PythonArtifactNamingService.kt | 2 +- .../py/{ => service}/PythonArtifactScopeService.kt | 2 +- .../py/{ => service}/PythonArtifactTypeService.kt | 2 +- .../marker/{jvm => py}/PythonGuideProviderTest.kt | 3 +-- .../marker/source/mark/api/ExpressionSourceMark.kt | 1 - .../mark/PluginSourceMarkEventListener.kt | 12 ++++++------ .../breakpoint/tree/VariableRootSimpleNode.kt | 6 +++--- 48 files changed, 68 insertions(+), 65 deletions(-) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => detect}/JavascriptEndpointDetector.kt (91%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => detect}/JavascriptLoggerDetector.kt (96%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{psi => detect}/endpoint/ExpressEndpoint.kt (99%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => presentation}/JavascriptVariableRootNode.kt (97%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => presentation}/JavascriptVariableSimpleNode.kt (98%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => service}/JavascriptArtifactConditionService.kt (96%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => service}/JavascriptArtifactCreationService.kt (99%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => service}/JavascriptArtifactNamingService.kt (99%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => service}/JavascriptArtifactScopeService.kt (97%) rename marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/{ => service}/JavascriptArtifactTypeService.kt (97%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => detect}/JVMEndpointDetector.kt (88%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/JVMLoggerDetector.kt (99%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/SkywalkingTraceEndpoint.kt (95%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/SpringMVCEndpoint.kt (98%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => presentation}/JVMVariableSimpleNode.kt (99%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => service}/JVMArtifactConditionService.kt (98%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => service}/JVMArtifactCreationService.kt (98%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => service}/JVMArtifactNamingService.kt (97%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => service}/JVMArtifactScopeService.kt (98%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/{ => service}/JVMArtifactTypeService.kt (97%) rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/{source => jvm/service/utils}/JVMMarkerUtils.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/JVMLoggerDetectorTest.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/AbstractEndpointDetectorTest.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/GroovyEndpointDetectorTest.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/JavaEndpointDetectorTest.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/KotlinEndpointDetectorTest.kt (99%) rename marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/{psi => detect}/endpoint/ScalaEndpointNameDetectorTest.kt (98%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => detect}/PythonEndpointDetector.kt (91%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => detect}/PythonLoggerDetector.kt (96%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{psi => detect}/endpoint/FlaskEndpoint.kt (98%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => presentation}/PythonVariableRootNode.kt (97%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => presentation}/PythonVariableSimpleNode.kt (98%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => service}/PythonArtifactConditionService.kt (96%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => service}/PythonArtifactCreationService.kt (99%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => service}/PythonArtifactNamingService.kt (99%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => service}/PythonArtifactScopeService.kt (98%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/{ => service}/PythonArtifactTypeService.kt (96%) rename marker/py-marker/src/test/kotlin/spp/jetbrains/marker/{jvm => py}/PythonGuideProviderTest.kt (96%) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt index 00fa80245..9ef89bb73 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt @@ -17,6 +17,7 @@ package spp.jetbrains.marker.js import spp.jetbrains.marker.impl.* +import spp.jetbrains.marker.js.service.* /** * Provides JavaScript support for the Marker API. diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptEndpointDetector.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptEndpointDetector.kt similarity index 91% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptEndpointDetector.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptEndpointDetector.kt index 1ad5d60ef..86686dce4 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptEndpointDetector.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptEndpointDetector.kt @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.detect import com.intellij.openapi.project.Project -import spp.jetbrains.marker.js.psi.endpoint.ExpressEndpoint +import spp.jetbrains.marker.js.detect.endpoint.ExpressEndpoint import spp.jetbrains.marker.source.info.EndpointDetector import spp.jetbrains.marker.source.info.EndpointDetector.EndpointNameDeterminer diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLoggerDetector.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptLoggerDetector.kt similarity index 96% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLoggerDetector.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptLoggerDetector.kt index 024e0bbe6..b1e4b39eb 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLoggerDetector.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/JavascriptLoggerDetector.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.detect import com.intellij.openapi.project.Project import spp.jetbrains.marker.source.info.LoggerDetector diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/psi/endpoint/ExpressEndpoint.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt similarity index 99% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/psi/endpoint/ExpressEndpoint.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt index 41a271948..f231977ef 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/psi/endpoint/ExpressEndpoint.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js.psi.endpoint +package spp.jetbrains.marker.js.detect.endpoint import com.intellij.lang.javascript.psi.* import com.intellij.openapi.application.ApplicationManager diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableRootNode.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt similarity index 97% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableRootNode.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt index c44ca03a2..328bf4acc 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableRootNode.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.presentation import com.intellij.ide.projectView.PresentationData import com.intellij.openapi.editor.DefaultLanguageHighlighterColors diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableSimpleNode.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt similarity index 98% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableSimpleNode.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt index f85bbd8ec..324d151ae 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptVariableSimpleNode.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.presentation import com.intellij.icons.AllIcons import com.intellij.ide.projectView.PresentationData diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactConditionService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactConditionService.kt similarity index 96% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactConditionService.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactConditionService.kt index 850b4d90d..af5f030ad 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactConditionService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactConditionService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.service import com.intellij.psi.PsiElement import spp.jetbrains.marker.IArtifactConditionService diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactCreationService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt similarity index 99% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactCreationService.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt index b551edc8a..cf25ba58e 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactCreationService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.service import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactNamingService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt similarity index 99% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactNamingService.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt index f4929a2a7..9ec4d65fe 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactNamingService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.service import com.intellij.lang.javascript.psi.* import com.intellij.lang.javascript.psi.ecmal4.JSClass diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactScopeService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactScopeService.kt similarity index 97% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactScopeService.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactScopeService.kt index 7edf671fb..ffb8c3acf 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactScopeService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactScopeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.service import com.intellij.lang.javascript.psi.JSFunction import com.intellij.lang.javascript.psi.JSVariable diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactTypeService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactTypeService.kt similarity index 97% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactTypeService.kt rename to marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactTypeService.kt index df0181d0c..6b81cc7a8 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptArtifactTypeService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactTypeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js +package spp.jetbrains.marker.js.service import com.intellij.lang.javascript.psi.JSExpression import com.intellij.lang.javascript.psi.JSFunction diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt index efad5ee9c..d15838001 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt @@ -33,7 +33,7 @@ import org.jetbrains.uast.toUElementOfType import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.impl.ArtifactCreationService import spp.jetbrains.marker.plugin.SourceLineMarkerProvider -import spp.jetbrains.marker.source.JVMMarkerUtils +import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils import spp.jetbrains.marker.source.SourceFileMarker.Companion.SUPPORTED_FILE_TYPES import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.key.SourceKey diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMMarker.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMMarker.kt index 2d18a5f06..f2183ab35 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMMarker.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMMarker.kt @@ -18,6 +18,7 @@ package spp.jetbrains.marker.jvm import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.impl.* +import spp.jetbrains.marker.jvm.service.* /** * todo: description. diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt index 349213970..a6127405c 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt @@ -27,7 +27,7 @@ import org.jetbrains.uast.UMethod import org.jetbrains.uast.toUElement import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.plugin.SourceInlayHintProvider -import spp.jetbrains.marker.source.JVMMarkerUtils +import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils import spp.jetbrains.marker.source.mark.inlay.InlayMark import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkVirtualText diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMEndpointDetector.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMEndpointDetector.kt similarity index 88% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMEndpointDetector.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMEndpointDetector.kt index 4e4249a91..fa1429877 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMEndpointDetector.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMEndpointDetector.kt @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.detect import com.intellij.openapi.project.Project import io.vertx.core.CompositeFuture import io.vertx.core.Future import io.vertx.core.Promise import org.jetbrains.uast.UMethod -import spp.jetbrains.marker.jvm.JVMEndpointDetector.JVMEndpointNameDeterminer -import spp.jetbrains.marker.jvm.psi.endpoint.SkywalkingTraceEndpoint -import spp.jetbrains.marker.jvm.psi.endpoint.SpringMVCEndpoint +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector.JVMEndpointNameDeterminer +import spp.jetbrains.marker.jvm.detect.endpoint.SkywalkingTraceEndpoint +import spp.jetbrains.marker.jvm.detect.endpoint.SpringMVCEndpoint import spp.jetbrains.marker.source.info.EndpointDetector import java.util.* diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt similarity index 99% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt index 157e95502..87080bd35 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetector.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi +package spp.jetbrains.marker.jvm.detect import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.logger diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SkywalkingTraceEndpoint.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SkywalkingTraceEndpoint.kt similarity index 95% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SkywalkingTraceEndpoint.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SkywalkingTraceEndpoint.kt index 9aa58f605..8113a82e2 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SkywalkingTraceEndpoint.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SkywalkingTraceEndpoint.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.Computable @@ -23,7 +23,7 @@ import io.vertx.core.Promise import org.jetbrains.uast.UMethod import org.jetbrains.uast.expressions.UInjectionHost import org.jetbrains.uast.toUElementOfType -import spp.jetbrains.marker.jvm.JVMEndpointDetector.JVMEndpointNameDeterminer +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector.JVMEndpointNameDeterminer import spp.jetbrains.marker.source.info.EndpointDetector.DetectedEndpoint import spp.jetbrains.marker.source.mark.guide.GuideMark import java.util.* diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SpringMVCEndpoint.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SpringMVCEndpoint.kt similarity index 98% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SpringMVCEndpoint.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SpringMVCEndpoint.kt index a00c06faa..9dce53ba5 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/SpringMVCEndpoint.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/SpringMVCEndpoint.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.lang.Language import com.intellij.openapi.application.ApplicationManager @@ -29,10 +29,9 @@ import org.jetbrains.uast.kotlin.KotlinStringULiteralExpression import org.jetbrains.uast.kotlin.KotlinUQualifiedReferenceExpression import org.jetbrains.uast.kotlin.KotlinUSimpleReferenceExpression import org.joor.Reflect -import spp.jetbrains.marker.jvm.JVMEndpointDetector.JVMEndpointNameDeterminer +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector.JVMEndpointNameDeterminer import spp.jetbrains.marker.source.info.EndpointDetector.DetectedEndpoint import spp.jetbrains.marker.source.mark.guide.GuideMark -import spp.jetbrains.marker.source.mark.guide.MethodGuideMark import java.util.* /** diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMVariableSimpleNode.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt similarity index 99% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMVariableSimpleNode.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt index 62c7cbd00..b626f1c16 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMVariableSimpleNode.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.presentation import com.intellij.icons.AllIcons import com.intellij.ide.projectView.PresentationData diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactConditionService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactConditionService.kt similarity index 98% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactConditionService.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactConditionService.kt index 784f66bc7..af466f4df 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactConditionService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactConditionService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.service import com.intellij.debugger.engine.evaluation.TextWithImportsImpl import com.intellij.debugger.impl.DebuggerUtilsEx diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactCreationService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt similarity index 98% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactCreationService.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt index 26affe31e..8f077e47e 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactCreationService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.service import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner import com.intellij.psi.PsiStatement import spp.jetbrains.marker.IArtifactCreationService import spp.jetbrains.marker.SourceMarkerUtils -import spp.jetbrains.marker.source.JVMMarkerUtils +import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.key.SourceKey diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt similarity index 97% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingService.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt index 302e09323..e97b77d97 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.service import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project @@ -23,7 +23,7 @@ import com.intellij.psi.util.ClassUtil import org.jetbrains.uast.* import spp.jetbrains.marker.IArtifactNamingService import spp.jetbrains.marker.SourceMarker -import spp.jetbrains.marker.source.JVMMarkerUtils +import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils import spp.jetbrains.marker.source.mark.api.SourceMark import spp.protocol.artifact.ArtifactLanguage import spp.protocol.artifact.ArtifactNameUtils diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt similarity index 98% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt index a69cef25d..647e6a508 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactScopeService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.service import com.intellij.psi.* import com.intellij.psi.scope.processor.VariablesProcessor diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactTypeService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactTypeService.kt similarity index 97% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactTypeService.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactTypeService.kt index c160269db..ef9cc5d69 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMArtifactTypeService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactTypeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.jvm.service import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/source/JVMMarkerUtils.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt similarity index 99% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/source/JVMMarkerUtils.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt index 0de8807fd..d3cb750ba 100755 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/source/JVMMarkerUtils.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.source +package spp.jetbrains.marker.jvm.service.utils import com.intellij.lang.jvm.util.JvmClassUtil import com.intellij.openapi.diagnostic.logger @@ -23,6 +23,7 @@ import com.intellij.psi.util.PsiUtil import org.jetbrains.uast.* import org.joor.Reflect import spp.jetbrains.marker.SourceMarkerUtils +import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.key.SourceKey import spp.jetbrains.marker.source.mark.gutter.ClassGutterMark diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt index 5188afa3e..e68469df3 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.plugins.groovy.lang.psi.GroovyFile import spp.jetbrains.marker.SourceMarker +import spp.jetbrains.marker.jvm.service.JVMArtifactNamingService import spp.jetbrains.marker.source.SourceFileMarker import spp.protocol.artifact.ArtifactType diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMConditionParserTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMConditionParserTest.kt index 4829dedc9..fa838b47f 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMConditionParserTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMConditionParserTest.kt @@ -28,6 +28,7 @@ import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl import org.intellij.lang.annotations.Language import spp.jetbrains.marker.impl.ArtifactConditionService +import spp.jetbrains.marker.jvm.service.JVMArtifactConditionService class JVMConditionParserTest : LightJavaCodeInsightFixtureTestCase() { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt similarity index 99% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt index 6f6e72ee3..34010f5da 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/JVMLoggerDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi +package spp.jetbrains.marker.jvm.detect import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.module.Module diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/AbstractEndpointDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/AbstractEndpointDetectorTest.kt similarity index 99% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/AbstractEndpointDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/AbstractEndpointDetectorTest.kt index cdec5de5c..82963b871 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/AbstractEndpointDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/AbstractEndpointDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.testFramework.TestApplicationManager import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/GroovyEndpointDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/GroovyEndpointDetectorTest.kt similarity index 99% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/GroovyEndpointDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/GroovyEndpointDetectorTest.kt index 52baef85b..dc505ba95 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/GroovyEndpointDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/GroovyEndpointDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.openapi.application.ApplicationManager import io.vertx.kotlin.coroutines.await @@ -22,7 +22,7 @@ import org.intellij.lang.annotations.Language import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.ScopeExtensions.safeRunBlocking -import spp.jetbrains.marker.jvm.JVMEndpointDetector +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector class GroovyEndpointDetectorTest : AbstractEndpointDetectorTest() { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/JavaEndpointDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/JavaEndpointDetectorTest.kt similarity index 99% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/JavaEndpointDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/JavaEndpointDetectorTest.kt index 505d437e8..5ea1d7fb5 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/JavaEndpointDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/JavaEndpointDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.openapi.application.ApplicationManager import io.vertx.kotlin.coroutines.await @@ -22,7 +22,7 @@ import org.intellij.lang.annotations.Language import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.ScopeExtensions.safeRunBlocking -import spp.jetbrains.marker.jvm.JVMEndpointDetector +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector class JavaEndpointDetectorTest : AbstractEndpointDetectorTest() { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/KotlinEndpointDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/KotlinEndpointDetectorTest.kt similarity index 99% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/KotlinEndpointDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/KotlinEndpointDetectorTest.kt index c84789099..bc1fd2f97 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/KotlinEndpointDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/KotlinEndpointDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.openapi.application.ApplicationManager import io.vertx.kotlin.coroutines.await @@ -22,7 +22,7 @@ import org.intellij.lang.annotations.Language import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.ScopeExtensions.safeRunBlocking -import spp.jetbrains.marker.jvm.JVMEndpointDetector +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector class KotlinEndpointDetectorTest : AbstractEndpointDetectorTest() { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/ScalaEndpointNameDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/ScalaEndpointNameDetectorTest.kt similarity index 98% rename from marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/ScalaEndpointNameDetectorTest.kt rename to marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/ScalaEndpointNameDetectorTest.kt index 578f626f0..6cb38f0e0 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/psi/endpoint/ScalaEndpointNameDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/endpoint/ScalaEndpointNameDetectorTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm.psi.endpoint +package spp.jetbrains.marker.jvm.detect.endpoint import com.intellij.openapi.application.ApplicationManager import io.vertx.kotlin.coroutines.await @@ -22,7 +22,7 @@ import org.intellij.lang.annotations.Language import org.jetbrains.uast.UFile import org.jetbrains.uast.toUElement import spp.jetbrains.ScopeExtensions.safeRunBlocking -import spp.jetbrains.marker.jvm.JVMEndpointDetector +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector class ScalaEndpointNameDetectorTest : AbstractEndpointDetectorTest() { diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonMarker.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonMarker.kt index 854de9be8..dd5908ed5 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonMarker.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonMarker.kt @@ -17,6 +17,7 @@ package spp.jetbrains.marker.py import spp.jetbrains.marker.impl.* +import spp.jetbrains.marker.py.service.* /** * todo: description. diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonEndpointDetector.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonEndpointDetector.kt similarity index 91% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonEndpointDetector.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonEndpointDetector.kt index dece32305..52ae916bd 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonEndpointDetector.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonEndpointDetector.kt @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.detect import com.intellij.openapi.project.Project -import spp.jetbrains.marker.py.psi.endpoint.FlaskEndpoint +import spp.jetbrains.marker.py.detect.endpoint.FlaskEndpoint import spp.jetbrains.marker.source.info.EndpointDetector import spp.jetbrains.marker.source.info.EndpointDetector.EndpointNameDeterminer diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLoggerDetector.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonLoggerDetector.kt similarity index 96% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLoggerDetector.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonLoggerDetector.kt index e050e1614..fa7fc6c91 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLoggerDetector.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/PythonLoggerDetector.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.detect import com.intellij.openapi.project.Project import spp.jetbrains.marker.source.info.LoggerDetector diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/psi/endpoint/FlaskEndpoint.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/endpoint/FlaskEndpoint.kt similarity index 98% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/psi/endpoint/FlaskEndpoint.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/endpoint/FlaskEndpoint.kt index 9d1c1f4b5..a3d8b061d 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/psi/endpoint/FlaskEndpoint.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/detect/endpoint/FlaskEndpoint.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py.psi.endpoint +package spp.jetbrains.marker.py.detect.endpoint import com.intellij.openapi.application.ApplicationManager import com.jetbrains.python.psi.PyFunction diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableRootNode.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt similarity index 97% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableRootNode.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt index 92afbe6a8..212250ea7 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableRootNode.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.presentation import com.intellij.ide.projectView.PresentationData import com.intellij.openapi.editor.DefaultLanguageHighlighterColors diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableSimpleNode.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt similarity index 98% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableSimpleNode.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt index 38488928b..312ebe73e 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonVariableSimpleNode.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.presentation import com.intellij.ide.projectView.PresentationData import com.intellij.openapi.editor.DefaultLanguageHighlighterColors diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactConditionService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactConditionService.kt similarity index 96% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactConditionService.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactConditionService.kt index 42cbe0c16..7757fb119 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactConditionService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactConditionService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.service import com.intellij.psi.PsiElement import spp.jetbrains.marker.IArtifactConditionService diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactCreationService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt similarity index 99% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactCreationService.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt index 131df5578..1f1a09ad2 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactCreationService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.service import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactNamingService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt similarity index 99% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactNamingService.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt index 0ce0c9193..6b64b42f7 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactNamingService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.service import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactScopeService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactScopeService.kt similarity index 98% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactScopeService.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactScopeService.kt index 19c0d170b..5dc4d1091 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactScopeService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactScopeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.service import com.intellij.psi.PsiElement import com.intellij.psi.PsiNamedElement diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactTypeService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactTypeService.kt similarity index 96% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactTypeService.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactTypeService.kt index 0b68bb84b..1474aa9a3 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonArtifactTypeService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactTypeService.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.py +package spp.jetbrains.marker.py.service import com.intellij.psi.PsiElement import com.jetbrains.python.psi.PyClass diff --git a/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/jvm/PythonGuideProviderTest.kt b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt similarity index 96% rename from marker/py-marker/src/test/kotlin/spp/jetbrains/marker/jvm/PythonGuideProviderTest.kt rename to marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt index d0789518f..190f9c375 100644 --- a/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/jvm/PythonGuideProviderTest.kt +++ b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.jvm +package spp.jetbrains.marker.py import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.Computable @@ -24,7 +24,6 @@ import com.jetbrains.python.psi.PyFile import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import spp.jetbrains.marker.SourceMarker -import spp.jetbrains.marker.py.PythonMarker import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.guide.MethodGuideMark diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt index 9786e0160..3bace614d 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt @@ -19,7 +19,6 @@ package spp.jetbrains.marker.source.mark.api import com.intellij.openapi.Disposable import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiElement -import com.intellij.psi.PsiInvalidElementAccessException import spp.jetbrains.marker.impl.ArtifactNamingService import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponent diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt index 86e6a15be..cbf5fda89 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt @@ -25,12 +25,12 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiManager import io.vertx.core.Vertx import spp.jetbrains.marker.SourceMarker -import spp.jetbrains.marker.js.JavascriptEndpointDetector -import spp.jetbrains.marker.js.JavascriptLoggerDetector -import spp.jetbrains.marker.jvm.JVMEndpointDetector -import spp.jetbrains.marker.jvm.psi.JVMLoggerDetector -import spp.jetbrains.marker.py.PythonEndpointDetector -import spp.jetbrains.marker.py.PythonLoggerDetector +import spp.jetbrains.marker.js.detect.JavascriptEndpointDetector +import spp.jetbrains.marker.js.detect.JavascriptLoggerDetector +import spp.jetbrains.marker.jvm.detect.JVMEndpointDetector +import spp.jetbrains.marker.jvm.detect.JVMLoggerDetector +import spp.jetbrains.marker.py.detect.PythonEndpointDetector +import spp.jetbrains.marker.py.detect.PythonLoggerDetector import spp.jetbrains.marker.source.info.EndpointDetector import spp.jetbrains.marker.source.info.LoggerDetector import spp.jetbrains.marker.source.mark.api.event.SourceMarkEvent diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt index 5cd746322..090cf3a2b 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt @@ -18,9 +18,9 @@ package spp.jetbrains.sourcemarker.service.instrument.breakpoint.tree import com.intellij.ui.treeStructure.SimpleNode import com.intellij.util.containers.hash.LinkedHashMap -import spp.jetbrains.marker.js.JavascriptVariableRootNode -import spp.jetbrains.marker.jvm.JVMVariableSimpleNode -import spp.jetbrains.marker.py.PythonVariableRootNode +import spp.jetbrains.marker.js.presentation.JavascriptVariableRootNode +import spp.jetbrains.marker.jvm.presentation.JVMVariableSimpleNode +import spp.jetbrains.marker.py.presentation.PythonVariableRootNode import spp.jetbrains.sourcemarker.service.instrument.breakpoint.StackFrameManager import spp.protocol.artifact.ArtifactLanguage import spp.protocol.instrument.variable.LiveVariableScope From 8ee9a01cc8ff408451845ee498e06f709f36708a Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 1 Oct 2022 12:57:36 -0300 Subject: [PATCH 07/28] fix: variable reference presentations differ from referenced variables (#859) * wip: LiveVariableNode super class * fix: variable reference presentations differ from referenced variables --- .../js/presentation/JavascriptVariableNode.kt | 63 +++++++++++++++++++ .../JavascriptVariableRootNode.kt | 2 +- ...riableSimpleNode.kt => JVMVariableNode.kt} | 62 +++--------------- ...bleSimpleNode.kt => PythonVariableNode.kt} | 19 ++++-- .../py/presentation/PythonVariableRootNode.kt | 2 +- .../marker/presentation/LiveVariableNode.kt} | 45 +++++-------- .../breakpoint/tree/VariableRootSimpleNode.kt | 7 ++- 7 files changed, 106 insertions(+), 94 deletions(-) create mode 100644 marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableNode.kt rename marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/{JVMVariableSimpleNode.kt => JVMVariableNode.kt} (73%) rename marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/{PythonVariableSimpleNode.kt => PythonVariableNode.kt} (88%) rename marker/{js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt => src/main/kotlin/spp/jetbrains/marker/presentation/LiveVariableNode.kt} (65%) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableNode.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableNode.kt new file mode 100644 index 000000000..1812a8c35 --- /dev/null +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableNode.kt @@ -0,0 +1,63 @@ +/* + * Source++, the open-source live coding platform. + * Copyright (C) 2022 CodeBrig, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spp.jetbrains.marker.js.presentation + +import com.intellij.icons.AllIcons +import com.intellij.ide.projectView.PresentationData +import com.intellij.ui.SimpleTextAttributes +import com.intellij.ui.treeStructure.SimpleNode +import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants +import spp.jetbrains.marker.presentation.LiveVariableNode +import spp.protocol.instrument.variable.LiveVariable +import spp.protocol.instrument.variable.LiveVariableScope + +/** + * todo: description. + * + * @since 0.7.0 + * @author [Brandon Fergerson](mailto:bfergerson@apache.org) + */ +@Suppress("MagicNumber") +class JavascriptVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> +) : LiveVariableNode(variable, nodeMap) { + + override fun createVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> + ): SimpleNode { + return JavascriptVariableNode(variable, nodeMap) + } + + override fun update(presentation: PresentationData) { + if (variable.scope == LiveVariableScope.GENERATED_METHOD) { + presentation.addText(variable.name + " = ", SimpleTextAttributes.GRAYED_ATTRIBUTES) + presentation.setIcon(AllIcons.Nodes.Method) + } else { + presentation.addText(variable.name + " = ", XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES) + } + + if (childCount > 0) { + presentation.setIcon(AllIcons.Nodes.Variable) + presentation.addText("todo", SimpleTextAttributes.REGULAR_ATTRIBUTES) + } else { + presentation.setIcon(AllIcons.Nodes.Field) + presentation.addText(variable.value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES) + } + } +} diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt index 328bf4acc..37ece90c8 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableRootNode.kt @@ -38,7 +38,7 @@ class JavascriptVariableRootNode( private val scheme = DebuggerUIUtil.getColorScheme(null) override fun getChildren(): Array { - return variables.map { JavascriptVariableSimpleNode(it, mutableMapOf()) }.toTypedArray() + return variables.map { JavascriptVariableNode(it, mutableMapOf()) }.toTypedArray() } override fun update(presentation: PresentationData) { diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableNode.kt similarity index 73% rename from marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt rename to marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableNode.kt index b626f1c16..57f237940 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableSimpleNode.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/presentation/JVMVariableNode.kt @@ -22,12 +22,10 @@ import com.intellij.openapi.editor.DefaultLanguageHighlighterColors.NUMBER import com.intellij.openapi.editor.DefaultLanguageHighlighterColors.STRING import com.intellij.ui.SimpleTextAttributes.* import com.intellij.ui.treeStructure.SimpleNode -import com.intellij.xdebugger.impl.ui.DebuggerUIUtil import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject -import org.apache.commons.lang3.EnumUtils -import spp.jetbrains.marker.ErrorVariableSimpleNode +import spp.jetbrains.marker.presentation.LiveVariableNode import spp.protocol.instrument.variable.LiveVariable import spp.protocol.instrument.variable.LiveVariableScope @@ -38,10 +36,10 @@ import spp.protocol.instrument.variable.LiveVariableScope * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ @Suppress("MagicNumber") -class JVMVariableSimpleNode( - val variable: LiveVariable, - private val nodeMap: MutableMap> -) : SimpleNode() { +class JVMVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> +) : LiveVariableNode(variable, nodeMap) { private val primitives = setOf( "java.lang.String", @@ -62,50 +60,12 @@ class JVMVariableSimpleNode( "java.lang.Float", "java.lang.Double" ) - private val scheme = DebuggerUIUtil.getColorScheme(null) - override fun getChildren(): Array { - if (variable.value == null && variable.liveIdentity != null) { - //found reference, use children of referenced node - return nodeMap[variable.liveIdentity!!] ?: arrayOf() - } - - val children = if (variable.value is JsonArray) { - (variable.value as JsonArray).map { JsonObject.mapFrom(it) }.map { - if (it.getString("@skip") != null) { - ErrorVariableSimpleNode(JsonObject.mapFrom(it).map) - } else { - JVMVariableSimpleNode(toLiveVariable(it), nodeMap) - } - }.toList().toTypedArray() - } else if (variable.value is LiveVariable) { - arrayOf(JVMVariableSimpleNode(variable.value as LiveVariable, nodeMap) as SimpleNode) - } else { - emptyArray() - } - - //add children to nodeMap for reference lookup - if (variable.liveIdentity != null) { - nodeMap[variable.liveIdentity!!] = children - } - return children - } - - private fun toLiveVariable(it: JsonObject): LiveVariable { - var varValue = it.getValue("value") - if (varValue is JsonArray && varValue.size() == 1 && - (varValue.first() as JsonObject).containsKey("liveClazz") - ) { - varValue = toLiveVariable(varValue.first() as JsonObject) - } - return LiveVariable( - name = it.getString("name"), - value = varValue, - lineNumber = it.getInteger("lineNumber") ?: -1, - scope = EnumUtils.getEnum(LiveVariableScope::class.java, it.getString("scope")), - liveClazz = it.getString("liveClazz"), - liveIdentity = it.getString("liveIdentity") - ) + override fun createVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> + ): SimpleNode { + return JVMVariableNode(variable, nodeMap) } override fun update(presentation: PresentationData) { @@ -188,6 +148,4 @@ class JVMVariableSimpleNode( } } } - - override fun getEqualityObjects(): Array = arrayOf(variable) } diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt similarity index 88% rename from marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt rename to marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt index 312ebe73e..ee7af8067 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableSimpleNode.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt @@ -20,9 +20,9 @@ import com.intellij.ide.projectView.PresentationData import com.intellij.openapi.editor.DefaultLanguageHighlighterColors import com.intellij.ui.SimpleTextAttributes import com.intellij.ui.treeStructure.SimpleNode -import com.intellij.xdebugger.impl.ui.DebuggerUIUtil import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants import io.vertx.core.json.JsonObject +import spp.jetbrains.marker.presentation.LiveVariableNode import spp.protocol.instrument.variable.LiveVariable /** @@ -32,9 +32,16 @@ import spp.protocol.instrument.variable.LiveVariable * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ @Suppress("MagicNumber") -class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode() { +class PythonVariableNode( + variable: LiveVariable +) : LiveVariableNode(variable, mutableMapOf()) { - private val scheme = DebuggerUIUtil.getColorScheme(null) + override fun createVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> + ): SimpleNode { + return PythonVariableNode(variable) + } override fun getChildren(): Array { if (variable.liveClazz == "") { @@ -44,7 +51,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode( ) val children = mutableListOf() dict.map.forEach { - children.add(PythonVariableSimpleNode(LiveVariable("'" + it.key + "'", it.value))) + children.add(PythonVariableNode(LiveVariable("'" + it.key + "'", it.value))) } return children.toTypedArray() } @@ -74,6 +81,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode( ) ) } + variable.liveClazz == "" -> { presentation.addText( "\"" + variable.value + "\"", @@ -82,6 +90,7 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode( ) ) } + else -> { presentation.addText( variable.value.toString(), @@ -92,6 +101,4 @@ class PythonVariableSimpleNode(private val variable: LiveVariable) : SimpleNode( } } } - - override fun getEqualityObjects(): Array = arrayOf(variable) } diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt index 212250ea7..4ce01173f 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableRootNode.kt @@ -35,7 +35,7 @@ class PythonVariableRootNode(val variables: List, val scope: LiveV private val scheme = DebuggerUIUtil.getColorScheme(null) override fun getChildren(): Array { - return variables.map { PythonVariableSimpleNode(it) }.toTypedArray() + return variables.map { PythonVariableNode(it) }.toTypedArray() } override fun update(presentation: PresentationData) { diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt b/marker/src/main/kotlin/spp/jetbrains/marker/presentation/LiveVariableNode.kt similarity index 65% rename from marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt rename to marker/src/main/kotlin/spp/jetbrains/marker/presentation/LiveVariableNode.kt index 324d151ae..fb6c33469 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/presentation/JavascriptVariableSimpleNode.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/presentation/LiveVariableNode.kt @@ -14,14 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spp.jetbrains.marker.js.presentation +package spp.jetbrains.marker.presentation -import com.intellij.icons.AllIcons -import com.intellij.ide.projectView.PresentationData -import com.intellij.ui.SimpleTextAttributes import com.intellij.ui.treeStructure.SimpleNode import com.intellij.xdebugger.impl.ui.DebuggerUIUtil -import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject import org.apache.commons.lang3.EnumUtils @@ -35,17 +31,20 @@ import spp.protocol.instrument.variable.LiveVariableScope * @since 0.7.0 * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ -@Suppress("MagicNumber") -class JavascriptVariableSimpleNode( - private val variable: LiveVariable, +abstract class LiveVariableNode( + val variable: LiveVariable, private val nodeMap: MutableMap> ) : SimpleNode() { - private val scheme = DebuggerUIUtil.getColorScheme(null) + val scheme = DebuggerUIUtil.getColorScheme(null) + + abstract fun createVariableNode( + variable: LiveVariable, + nodeMap: MutableMap> + ): SimpleNode - //todo: LiveSimpleNode super class override fun getChildren(): Array { - if (variable.value == null && variable.liveIdentity != null) { + if (variable.liveIdentity != null && nodeMap.containsKey(variable.liveIdentity)) { //found reference, use children of referenced node return nodeMap[variable.liveIdentity!!] ?: arrayOf() } @@ -55,17 +54,17 @@ class JavascriptVariableSimpleNode( if (it.getString("@skip") != null) { ErrorVariableSimpleNode(JsonObject.mapFrom(it).map) } else { - JavascriptVariableSimpleNode(toLiveVariable(it), nodeMap) + createVariableNode(toLiveVariable(it), nodeMap) } }.toList().toTypedArray() } else if (variable.value is LiveVariable) { - arrayOf(JavascriptVariableSimpleNode(variable.value as LiveVariable, nodeMap) as SimpleNode) + arrayOf(createVariableNode(variable.value as LiveVariable, nodeMap)) } else { emptyArray() } //add children to nodeMap for reference lookup - if (variable.liveIdentity != null) { + if (variable.liveIdentity != null && children.isNotEmpty()) { nodeMap[variable.liveIdentity!!] = children } return children @@ -88,22 +87,6 @@ class JavascriptVariableSimpleNode( ) } - override fun update(presentation: PresentationData) { - if (variable.scope == LiveVariableScope.GENERATED_METHOD) { - presentation.addText(variable.name + " = ", SimpleTextAttributes.GRAYED_ATTRIBUTES) - presentation.setIcon(AllIcons.Nodes.Method) - } else { - presentation.addText(variable.name + " = ", XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES) - } - - if (childCount > 0) { - presentation.setIcon(AllIcons.Nodes.Variable) - presentation.addText("todo", SimpleTextAttributes.REGULAR_ATTRIBUTES) - } else { - presentation.setIcon(AllIcons.Nodes.Field) - presentation.addText(variable.value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES) - } - } - override fun getEqualityObjects(): Array = arrayOf(variable) + override fun toString(): String = variable.name } diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt index 090cf3a2b..346e69d39 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/tree/VariableRootSimpleNode.kt @@ -19,7 +19,7 @@ package spp.jetbrains.sourcemarker.service.instrument.breakpoint.tree import com.intellij.ui.treeStructure.SimpleNode import com.intellij.util.containers.hash.LinkedHashMap import spp.jetbrains.marker.js.presentation.JavascriptVariableRootNode -import spp.jetbrains.marker.jvm.presentation.JVMVariableSimpleNode +import spp.jetbrains.marker.jvm.presentation.JVMVariableNode import spp.jetbrains.marker.py.presentation.PythonVariableRootNode import spp.jetbrains.sourcemarker.service.instrument.breakpoint.StackFrameManager import spp.protocol.artifact.ArtifactLanguage @@ -76,10 +76,11 @@ class VariableRootSimpleNode : SimpleNode() { } else -> { - val simpleNodeMap: MutableMap = LinkedHashMap() + val simpleNodeMap: MutableMap = LinkedHashMap() + val nodeReferenceMap = mutableMapOf>() vars.forEach { if (it.name.isNotEmpty()) { - simpleNodeMap[it.name] = JVMVariableSimpleNode(it, mutableMapOf()) + simpleNodeMap[it.name] = JVMVariableNode(it, nodeReferenceMap) } } simpleNodeMap.values.sortedWith { p0, p1 -> From 846faf4628142fcb8762067ee47783ffb29d5a3f Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 2 Oct 2022 01:30:40 +0400 Subject: [PATCH 08/28] fix: fix relative path on windows --- .../marker/js/service/JavascriptArtifactNamingService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt index 9ec4d65fe..b071eb241 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt @@ -51,7 +51,7 @@ class JavascriptArtifactNamingService : IArtifactNamingService { val projectBasePath = sourceMark.project.basePath if (projectBasePath != null) { val relativePath = sourceMark.sourceFileMarker.psiFile.virtualFile.path.substringAfter(projectBasePath) - locationSource = if (relativePath.startsWith(File.separator)) { + locationSource = if (relativePath.startsWith("/")) { relativePath.substring(1) } else { relativePath From 387c8004291e27b8f4e65778baa3d2076fccc082 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 1 Oct 2022 23:04:53 +0000 Subject: [PATCH 09/28] Bump version to 0.7.2-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index afa936e4f..e5f971d1e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official pluginGroup = spp.jetbrains pluginName = Source++ -projectVersion=0.7.1-SNAPSHOT +projectVersion=0.7.2-SNAPSHOT pluginSinceBuild = 221.5080.210 platformType = IU From 406709f5df46c9a105642b21b37c85d5717ddf72 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 2 Oct 2022 22:17:58 +0400 Subject: [PATCH 10/28] fix: npe --- .../spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt index f231977ef..ccb816a41 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt @@ -57,7 +57,7 @@ class ExpressEndpoint : EndpointDetector.EndpointNameDeterminer { return@runReadAction } val router = method.firstChild as JSReferenceExpression - val routerVariable = router.resolve() as JSVariable + val routerVariable = router.resolve() as JSVariable? ?: return@runReadAction if (method.children.size < 3) { promise.complete(Optional.empty()) From 5a088dcf93b2ed91af09ab4494f90abf8aa72067 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:48:13 +0000 Subject: [PATCH 11/28] chore(deps): update actions/cache action to v3.0.10 (#860) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04eb066f2..6036fdbae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -96,7 +96,7 @@ jobs: # Cache Plugin Verifier IDEs - name: Setup Plugin Verifier IDEs Cache - uses: actions/cache@v3.0.9 + uses: actions/cache@v3.0.10 with: path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides key: plugin-verifier-${{ hashFiles('plugin/build/listProductsReleases.txt') }} From c9e671f97c42728de6c2085bd27f238063694405 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Mon, 3 Oct 2022 16:20:06 +0400 Subject: [PATCH 12/28] fix: npe when control palette is on method line --- .../jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt index d3cb750ba..45210267f 100755 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt @@ -409,10 +409,12 @@ object JVMMarkerUtils { element.putUserData(SourceKey.GutterMark, null) null } + gutterMark.configuration.icon != null -> { gutterMark.setVisible(true) gutterMark } + else -> { gutterMark.setVisible(false) gutterMark @@ -461,7 +463,7 @@ object JVMMarkerUtils { Base64.getEncoder().encodeToString(expression.toString().toByteArray()) }""", type = ArtifactType.EXPRESSION, - lineNumber = SourceMarkerUtils.getLineNumber(expression.sourcePsi!!) + lineNumber = expression.sourcePsi?.let { SourceMarkerUtils.getLineNumber(it) } ) } @@ -511,7 +513,8 @@ object JVMMarkerUtils { } return ArtifactQualifiedName( "$classQualifiedName.${getQualifiedName(method)}", - type = ArtifactType.METHOD + type = ArtifactType.METHOD, + lineNumber = method.sourcePsi?.let { SourceMarkerUtils.getLineNumber(it) } ) } From 0d90f7e9e79ba45b0ffd48758ac7612772eb941c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 13:12:14 +0400 Subject: [PATCH 13/28] fix(deps): update apollo graphql packages to v3.6.1 (#861) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle.properties | 2 +- settings.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index e5f971d1e..36dd3a3e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ platformPlugins = java # See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details. kotlin.stdlib.default.dependency = true -apolloVersion=3.6.0 +apolloVersion=3.6.1 vertxVersion=4.3.4 slf4jVersion=1.7.33 jacksonVersion=2.13.4 diff --git a/settings.gradle b/settings.gradle index aca71093d..4beb3c902 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,7 @@ pluginManagement { id 'org.jetbrains.kotlin.plugin.serialization' version kotlinVersion apply false id 'com.avast.gradle.docker-compose' version "0.16.9" apply false id 'io.gitlab.arturbosch.detekt' version "1.21.0" apply false - id 'com.apollographql.apollo3' version "3.6.0" apply false + id 'com.apollographql.apollo3' version "3.6.1" apply false id 'com.diffplug.spotless' version '6.11.0' apply false } } From 21d5a4ea3756a95073843afdb4d93f05ef9a1a36 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 4 Oct 2022 13:24:04 +0400 Subject: [PATCH 14/28] refactor: remove deprecated --- .../instrument/breakpoint/painter/VariableEditorLinePainter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/painter/VariableEditorLinePainter.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/painter/VariableEditorLinePainter.kt index 093bcb314..a4ef78e6f 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/painter/VariableEditorLinePainter.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/service/instrument/breakpoint/painter/VariableEditorLinePainter.kt @@ -62,7 +62,7 @@ class VariableEditorLinePainter : EditorLinePainter() { val attributes = EditorColorsManager.getInstance().globalScheme.getAttributes(DebuggerColors.INLINED_VALUES) return if (attributes == null || attributes.foregroundColor == null) { - TextAttributes(JBColor { + TextAttributes(JBColor.lazy { if (EditorColorsManager.getInstance().isDarkEditor ) Color(0x3d8065) else Gray._135 }, null, null, null, Font.ITALIC) From 58c4b8a1d86b1a3a9e5eb4107410a220ff2ecb6d Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 4 Oct 2022 16:58:01 +0400 Subject: [PATCH 15/28] fix: npe when fetching line number for command autocompletion --- .../py/service/PythonArtifactNamingService.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt index 6b64b42f7..018418a3a 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt @@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile import com.intellij.psi.util.parentOfType import com.jetbrains.python.psi.* import spp.jetbrains.marker.IArtifactNamingService +import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.source.mark.api.SourceMark import spp.protocol.artifact.ArtifactLanguage import spp.protocol.artifact.ArtifactQualifiedName @@ -57,14 +58,24 @@ class PythonArtifactNamingService : IArtifactNamingService { override fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName { return when (element) { is PyClass -> { - ArtifactQualifiedName(element.qualifiedName!!, null, ArtifactType.CLASS) + ArtifactQualifiedName( + element.qualifiedName!!, + null, + ArtifactType.CLASS, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) } is PyFunction -> { val parentQualifiedName = PyPsiFacade.getInstance(element.project) .findShortestImportableName(element.containingFile.virtualFile, element) val qualifiedName = element.qualifiedName ?: "$parentQualifiedName.${element.name}" - ArtifactQualifiedName("$qualifiedName()", null, ArtifactType.METHOD) + ArtifactQualifiedName( + "$qualifiedName()", + null, + ArtifactType.METHOD, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) } is PyStatement, is PyStatementList -> getStatementOrExpressionQualifiedName(element, ArtifactType.STATEMENT) @@ -78,11 +89,21 @@ class PythonArtifactNamingService : IArtifactNamingService { val parentQualifiedName = PyPsiFacade.getInstance(element.project) .findShortestImportableName(element.containingFile.virtualFile, element) val qualifiedName = parentFunction.qualifiedName ?: "$parentQualifiedName.${parentFunction.name!!}" - ArtifactQualifiedName("$qualifiedName()", null, type) + ArtifactQualifiedName( + "$qualifiedName()", + null, + type, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) } else { val qName = PyPsiFacade.getInstance(element.project) .findShortestImportableName(element.containingFile.virtualFile, element) - ArtifactQualifiedName("$qName", null, type) + ArtifactQualifiedName( + "$qName", + null, + type, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) } } From 15363672c79833aaed42eece322b6a00d94e3eb5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 14:17:54 +0000 Subject: [PATCH 16/28] chore(deps): update actions/checkout action to v3.1.0 (#863) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 4 ++-- .github/workflows/release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6036fdbae..66afe09fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 with: submodules: true @@ -148,7 +148,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 # Remove old release drafts by using the curl request for the available releases with draft flag - name: Remove Old Release Drafts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c21b7353f..bf732c771 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 with: ref: ${{ github.event.release.tag_name }} submodules: true From aa118966b34981b302dd13c0881c640dd7e58693 Mon Sep 17 00:00:00 2001 From: UltraDev Date: Wed, 5 Oct 2022 14:06:27 +0200 Subject: [PATCH 17/28] fix: sourceplusplus/sourceplusplus#720 (#862) Co-authored-by: Brandon Fergerson --- .../jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt index ccb816a41..73cb97c7d 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/detect/endpoint/ExpressEndpoint.kt @@ -57,7 +57,10 @@ class ExpressEndpoint : EndpointDetector.EndpointNameDeterminer { return@runReadAction } val router = method.firstChild as JSReferenceExpression - val routerVariable = router.resolve() as JSVariable? ?: return@runReadAction + val routerVariable = router.resolve() as JSInitializerOwner? ?: run { + promise.complete(Optional.empty()) + return@runReadAction + } if (method.children.size < 3) { promise.complete(Optional.empty()) @@ -97,7 +100,7 @@ class ExpressEndpoint : EndpointDetector.EndpointNameDeterminer { return promise.future() } - private fun locateRouter(routerVariable: JSVariable): String? { + private fun locateRouter(routerVariable: JSInitializerOwner): String? { if (isExpressApp(routerVariable)) { return "" } From fbee2f179bb0b4121253500ea2b2811aed29179f Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Wed, 5 Oct 2022 23:49:24 +0400 Subject: [PATCH 18/28] refactor: support all languages with base lang javascript (#866) --- .../jetbrains/marker/js/JavascriptMarker.kt | 13 +++++++------ .../service/JavascriptArtifactNamingService.kt | 3 ++- .../jvm/service/JVMArtifactNamingService.kt | 3 ++- .../py/service/PythonArtifactNamingService.kt | 3 ++- .../marker/AbstractSourceMarkerService.kt | 7 ++++++- .../jetbrains/marker/IArtifactNamingService.kt | 3 ++- .../spp/jetbrains/marker/SourceMarkerUtils.kt | 4 ++++ .../marker/impl/ArtifactConditionService.kt | 2 +- .../marker/impl/ArtifactCreationService.kt | 14 +++++++------- .../marker/impl/ArtifactNamingService.kt | 11 ++++++----- .../marker/impl/ArtifactScopeService.kt | 8 ++++---- .../marker/impl/ArtifactTypeService.kt | 2 +- .../marker/impl/SourceGuideProvider.kt | 18 +++++++++++++++--- .../spp/jetbrains/sourcemarker/ControlBar.java | 2 +- 14 files changed, 60 insertions(+), 33 deletions(-) diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt index 9ef89bb73..3cb1ac212 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptMarker.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker.js +import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.impl.* import spp.jetbrains.marker.js.service.* @@ -37,11 +38,11 @@ object JavascriptMarker { } fun setup() { - ArtifactCreationService.addService(JavascriptArtifactCreationService(), "JavaScript", "ECMAScript 6") - ArtifactNamingService.addService(JavascriptArtifactNamingService(), "JavaScript", "ECMAScript 6") - ArtifactScopeService.addService(JavascriptArtifactScopeService(), "JavaScript", "ECMAScript 6") - ArtifactConditionService.addService(JavascriptArtifactConditionService(), "JavaScript", "ECMAScript 6") - ArtifactTypeService.addService(JavascriptArtifactTypeService(), "JavaScript", "ECMAScript 6") - SourceGuideProvider.addProvider(JavascriptGuideProvider(), "JavaScript", "ECMAScript 6") + ArtifactCreationService.addService(JavascriptArtifactCreationService(), SourceMarkerUtils.getJavaScriptLanguages()) + ArtifactNamingService.addService(JavascriptArtifactNamingService(), SourceMarkerUtils.getJavaScriptLanguages()) + ArtifactScopeService.addService(JavascriptArtifactScopeService(), SourceMarkerUtils.getJavaScriptLanguages()) + ArtifactConditionService.addService(JavascriptArtifactConditionService(), SourceMarkerUtils.getJavaScriptLanguages()) + ArtifactTypeService.addService(JavascriptArtifactTypeService(), SourceMarkerUtils.getJavaScriptLanguages()) + SourceGuideProvider.addProvider(JavascriptGuideProvider(), SourceMarkerUtils.getJavaScriptLanguages()) } } diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt index b071eb241..643aa5fe5 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker.js.service +import com.intellij.lang.Language import com.intellij.lang.javascript.psi.* import com.intellij.lang.javascript.psi.ecmal4.JSClass import com.intellij.openapi.project.Project @@ -60,7 +61,7 @@ class JavascriptArtifactNamingService : IArtifactNamingService { return LiveSourceLocation(locationSource, lineNumber, service = serviceName) } - override fun getLocation(language: String, artifactQualifiedName: ArtifactQualifiedName): String { + override fun getLocation(language: Language, artifactQualifiedName: ArtifactQualifiedName): String { return if (artifactQualifiedName.identifier.contains("(")) { artifactQualifiedName.identifier } else { diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt index e97b77d97..9c3be7736 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker.jvm.service +import com.intellij.lang.Language import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.psi.* @@ -57,7 +58,7 @@ class JVMArtifactNamingService : IArtifactNamingService { return LiveSourceLocation(locationSource, lineNumber, service = serviceName) } - override fun getLocation(language: String, artifactQualifiedName: ArtifactQualifiedName): String { + override fun getLocation(language: Language, artifactQualifiedName: ArtifactQualifiedName): String { var fullyQualified = artifactQualifiedName.identifier if (fullyQualified.contains("#")) { fullyQualified = fullyQualified.substring(0, fullyQualified.indexOf("#")) diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt index 018418a3a..a4b7fc02f 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactNamingService.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker.py.service +import com.intellij.lang.Language import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile @@ -47,7 +48,7 @@ class PythonArtifactNamingService : IArtifactNamingService { return LiveSourceLocation(locationSource, lineNumber, service = serviceName) } - override fun getLocation(language: String, artifactQualifiedName: ArtifactQualifiedName): String { + override fun getLocation(language: Language, artifactQualifiedName: ArtifactQualifiedName): String { return artifactQualifiedName.identifier } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/AbstractSourceMarkerService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/AbstractSourceMarkerService.kt index 4cc91f07c..e1eb94adc 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/AbstractSourceMarkerService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/AbstractSourceMarkerService.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker +import com.intellij.lang.Language import spp.protocol.artifact.ArtifactLanguage abstract class AbstractSourceMarkerService { @@ -31,10 +32,14 @@ abstract class AbstractSourceMarkerService { languages.forEach { services[it] = service } } - internal fun getService(language: String): T { + private fun getService(language: String): T { return services[language] ?: throw IllegalArgumentException("No service for language $language") } + internal fun getService(language: Language): T { + return getService(language.baseLanguage?.id ?: language.id) + } + fun getService(language: ArtifactLanguage): T { return when (language) { ArtifactLanguage.JVM -> getService("JAVA") diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactNamingService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactNamingService.kt index 7e87f74f6..b08453f03 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactNamingService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactNamingService.kt @@ -16,6 +16,7 @@ */ package spp.jetbrains.marker +import com.intellij.lang.Language import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile @@ -39,7 +40,7 @@ interface IArtifactNamingService : ISourceMarkerService { serviceName: String? ): LiveSourceLocation? - fun getLocation(language: String, artifactQualifiedName: ArtifactQualifiedName): String + fun getLocation(language: Language, artifactQualifiedName: ArtifactQualifiedName): String fun getVariableName(element: PsiElement): String? fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName fun getQualifiedClassNames(psiFile: PsiFile): List diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt index cdd03f454..30cb120d3 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt @@ -87,4 +87,8 @@ object SourceMarkerUtils { fun getJvmLanguages(): List { return listOf("JAVA", "kotlin", "Groovy", "Scala") } + + fun getJavaScriptLanguages(): List { + return listOf("JavaScript", "ECMAScript 6") + } } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactConditionService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactConditionService.kt index 990d8822b..ad2a90951 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactConditionService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactConditionService.kt @@ -48,6 +48,6 @@ object ArtifactConditionService : AbstractSourceMarkerService { - return getService(fileMarker.psiFile.language.id) + return getService(fileMarker.psiFile.language) .getOrCreateExpressionGutterMark(fileMarker, lineNumber, autoApply) } @@ -50,7 +50,7 @@ object ArtifactCreationService : AbstractSourceMarkerService { - return getService(fileMarker.psiFile.language.id) + return getService(fileMarker.psiFile.language) .getOrCreateExpressionInlayMark(fileMarker, lineNumber, autoApply) } @@ -75,7 +75,7 @@ object ArtifactCreationService : AbstractSourceMarkerService { - return getService(psiFile.language.id).getQualifiedClassNames(psiFile) + return getService(psiFile.language).getQualifiedClassNames(psiFile) } override fun findPsiFile(language: ArtifactLanguage, project: Project, frame: LiveStackTraceElement): PsiFile? { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt index ad27ca319..e94da413a 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt @@ -30,18 +30,18 @@ import spp.jetbrains.marker.source.SourceFileMarker object ArtifactScopeService : AbstractSourceMarkerService(), IArtifactScopeService { override fun getScopeVariables(fileMarker: SourceFileMarker, lineNumber: Int): List { - return getService(fileMarker.psiFile.language.id).getScopeVariables(fileMarker, lineNumber) + return getService(fileMarker.psiFile.language).getScopeVariables(fileMarker, lineNumber) } override fun isInsideFunction(element: PsiElement): Boolean { - return getService(element.language.id).isInsideFunction(element) + return getService(element.language).isInsideFunction(element) } override fun isInsideEndlessLoop(element: PsiElement): Boolean { - return getService(element.language.id).isInsideEndlessLoop(element) + return getService(element.language).isInsideEndlessLoop(element) } override fun isJVM(element: PsiElement): Boolean { - return getService(element.language.id).isJVM(element) + return getService(element.language).isJVM(element) } } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactTypeService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactTypeService.kt index 40cd22f9f..d290c0d69 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactTypeService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactTypeService.kt @@ -24,6 +24,6 @@ import spp.protocol.artifact.ArtifactType object ArtifactTypeService : AbstractSourceMarkerService(), IArtifactTypeService { override fun getType(element: PsiElement): ArtifactType? { - return getService(element.language.id).getType(element) + return getService(element.language).getType(element) } } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/impl/SourceGuideProvider.kt b/marker/src/main/kotlin/spp/jetbrains/marker/impl/SourceGuideProvider.kt index 12ad0c66d..4c1a90970 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/impl/SourceGuideProvider.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/impl/SourceGuideProvider.kt @@ -16,7 +16,9 @@ */ package spp.jetbrains.marker.impl +import com.intellij.lang.Language import com.intellij.openapi.application.ReadAction +import com.intellij.openapi.diagnostic.logger import spp.jetbrains.marker.AbstractSourceGuideProvider import spp.jetbrains.marker.source.SourceFileMarker @@ -28,6 +30,7 @@ import spp.jetbrains.marker.source.SourceFileMarker */ object SourceGuideProvider : AbstractSourceGuideProvider { + private val log = logger() private val providers = mutableMapOf>() fun addProvider(guideProvider: AbstractSourceGuideProvider, language: String, vararg languages: String) { @@ -39,19 +42,28 @@ object SourceGuideProvider : AbstractSourceGuideProvider { languages.forEach { providers.computeIfAbsent(it) { mutableListOf() }.add(guideProvider) } } - private fun getProvider(language: String): AbstractSourceGuideProvider { + private fun getProvider(language: String): AbstractSourceGuideProvider? { return providers[language]?.let { object : AbstractSourceGuideProvider { override fun determineGuideMarks(fileMarker: SourceFileMarker) { it.forEach { provider -> provider.determineGuideMarks(fileMarker) } } } - } ?: throw IllegalArgumentException("No provider for language $language") + } + } + + private fun getProvider(language: Language): AbstractSourceGuideProvider? { + return getProvider(language.baseLanguage?.id ?: language.id) } override fun determineGuideMarks(fileMarker: SourceFileMarker) { ReadAction.run { - getProvider(fileMarker.psiFile.language.id).determineGuideMarks(fileMarker) + val guideProvider = getProvider(fileMarker.psiFile.language) + if (guideProvider != null) { + guideProvider.determineGuideMarks(fileMarker) + } else { + log.warn("No guide provider found for language: ${fileMarker.psiFile.language}") + } } } } diff --git a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java index e55f80fe1..7a0424036 100644 --- a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java +++ b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java @@ -219,7 +219,7 @@ private void initComponents() { setBackground(getBackgroundColor()); label1 = new JLabel(); String location = ArtifactNamingService.INSTANCE.getLocation( - inlayMark.getLanguage().getID(), + inlayMark.getLanguage(), inlayMark.getArtifactQualifiedName() ); textField1 = new AutocompleteField( From 9a9d788cad79a9868d8aed682f3490b0f77e459b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:17:54 +0000 Subject: [PATCH 19/28] fix(deps): update apollo graphql packages to v3.6.2 (#865) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle.properties | 2 +- settings.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 36dd3a3e2..e350a848b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ platformPlugins = java # See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details. kotlin.stdlib.default.dependency = true -apolloVersion=3.6.1 +apolloVersion=3.6.2 vertxVersion=4.3.4 slf4jVersion=1.7.33 jacksonVersion=2.13.4 diff --git a/settings.gradle b/settings.gradle index 4beb3c902..95e49cb0d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,7 @@ pluginManagement { id 'org.jetbrains.kotlin.plugin.serialization' version kotlinVersion apply false id 'com.avast.gradle.docker-compose' version "0.16.9" apply false id 'io.gitlab.arturbosch.detekt' version "1.21.0" apply false - id 'com.apollographql.apollo3' version "3.6.1" apply false + id 'com.apollographql.apollo3' version "3.6.2" apply false id 'com.diffplug.spotless' version '6.11.0' apply false } } From 53ad2e9b8554d5d4f2a6a478b39100310c3c115b Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Thu, 6 Oct 2022 08:52:05 +0400 Subject: [PATCH 20/28] fix: live variable decoding error on Python dicts (#864) --- marker/py-marker/build.gradle.kts | 1 + .../py/presentation/PythonVariableNode.kt | 57 +++++- .../py/presentation/LiveVariableParseTest.kt | 39 ++++ .../resources/breakpointHit/dictParse.json | 167 ++++++++++++++++++ 4 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/presentation/LiveVariableParseTest.kt create mode 100644 marker/py-marker/src/test/resources/breakpointHit/dictParse.json diff --git a/marker/py-marker/build.gradle.kts b/marker/py-marker/build.gradle.kts index 90e4be5db..36d758f16 100644 --- a/marker/py-marker/build.gradle.kts +++ b/marker/py-marker/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { compileOnly("org.jetbrains:annotations:23.0.0") compileOnly("io.vertx:vertx-core:$vertxVersion") + testImplementation("io.vertx:vertx-core:$vertxVersion") testImplementation(projectDependency(":common")) testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion") } diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt index ee7af8067..7e4770583 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/presentation/PythonVariableNode.kt @@ -45,10 +45,7 @@ class PythonVariableNode( override fun getChildren(): Array { if (variable.liveClazz == "") { - val dict = JsonObject( - (variable.value as String).replace("'", "\"") - .replace(": True", ": true").replace(": False", ": false") - ) + val dict = JsonObject(parseDict(variable.value as String)) val children = mutableListOf() dict.map.forEach { children.add(PythonVariableNode(LiveVariable("'" + it.key + "'", it.value))) @@ -101,4 +98,56 @@ class PythonVariableNode( } } } + + companion object { + fun parseDict(value: String): Map { + var dictVar = value + + //remove outer braces + if (dictVar.startsWith("{")) { + dictVar = dictVar.substring(1) + } + if (dictVar.endsWith("}")) { + dictVar = dictVar.substring(0, dictVar.length - 1) + } + + //split by , but not inside quotes + val tokens = dictVar.split(Regex(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")) + + //each token should contain ":", for those that don't we need to merge them with the previous token + val mergedTokens = mutableListOf() + for (i in tokens.indices) { + if (tokens[i].contains(":")) { + mergedTokens.add(tokens[i]) + } else { + mergedTokens[mergedTokens.size - 1] += "," + tokens[i] + } + } + + //now we can split each token into key and value + val dict = mutableMapOf() + for (token in mergedTokens) { + var key = token.substringBefore(":").trim() + var value = token.substringAfter(":").trim() + + //remove quotes + if (key.startsWith("\"")) { + key = key.substring(1) + } + if (key.endsWith("\"")) { + key = key.substring(0, key.length - 1) + } + if (value.startsWith("\"")) { + value = value.substring(1) + } + if (value.endsWith("\"")) { + value = value.substring(0, value.length - 1) + } + + dict[key] = value + } + + return dict + } + } } diff --git a/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/presentation/LiveVariableParseTest.kt b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/presentation/LiveVariableParseTest.kt new file mode 100644 index 000000000..824748ba8 --- /dev/null +++ b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/presentation/LiveVariableParseTest.kt @@ -0,0 +1,39 @@ +/* + * Source++, the open-source live coding platform. + * Copyright (C) 2022 CodeBrig, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spp.jetbrains.marker.py.presentation + +import com.google.common.io.Resources +import io.vertx.core.json.JsonObject +import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import spp.protocol.instrument.event.LiveBreakpointHit + +class LiveVariableParseTest { + + @Test + fun testDictParse() { + val bpHitJson = Resources.getResource("breakpointHit/dictParse.json").readText() + val bpHit = LiveBreakpointHit(JsonObject(bpHitJson)) + val builtInsVar = bpHit.stackTrace.elements.first().variables.find { it.name == "__builtins__" } + assertNotNull(builtInsVar) + + val parsedDict = PythonVariableNode.parseDict(builtInsVar!!.value as String) + assertNotNull(parsedDict) + assertEquals(152, parsedDict.size) + } +} diff --git a/marker/py-marker/src/test/resources/breakpointHit/dictParse.json b/marker/py-marker/src/test/resources/breakpointHit/dictParse.json new file mode 100644 index 000000000..3d9c47d22 --- /dev/null +++ b/marker/py-marker/src/test/resources/breakpointHit/dictParse.json @@ -0,0 +1,167 @@ +{ + "breakpointId": "914439a3-863b-40b5-8911-2519ba697413", + "traceId": "cdb70afe43e411ed94590242c0a8900b", + "occurredAt": "2022-10-04T13:02:30.128Z", + "serviceInstance": "9f7f48ec43dd11ed94410242c0a8900b", + "service": "demo-python", + "stackTrace": { + "exceptionType": "n/a", + "message": "n/a", + "elements": [ + { + "method": "simple_breakpoint", + "source": "/demo-python/src/command/AddBreakpoint.py:30", + "column": null, + "variables": [ + { + "name": "__name__", + "value": "command.AddBreakpoint", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259926832512", + "presentation": null + }, + { + "name": "__doc__", + "value": "None", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259935552032", + "presentation": null + }, + { + "name": "__package__", + "value": "command", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259851025840", + "presentation": null + }, + { + "name": "__loader__", + "value": "<_frozen_importlib_external.SourceFileLoader object at 0x7f90ca97e340>", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259850969920", + "presentation": null + }, + { + "name": "__spec__", + "value": "ModuleSpec(name='command.AddBreakpoint', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f90ca97e340>, origin='/demo-python/src/command/AddBreakpoint.py')", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259850971552", + "presentation": null + }, + { + "name": "__file__", + "value": "/demo-python/src/command/AddBreakpoint.py", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259850966096", + "presentation": null + }, + { + "name": "__cached__", + "value": "/demo-python/src/command/__pycache__/AddBreakpoint.cpython-38.pyc", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259927272240", + "presentation": null + }, + { + "name": "__builtins__", + "value": "{'__name__': 'builtins', '__doc__': \"Built-in functions, exceptions, and other objects.\\n\\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.\", '__package__': '', '__loader__': , '__spec__': ModuleSpec(name='builtins', loader=), '__build_class__': , '__import__': , 'abs': , 'all': , 'any': , 'ascii': , 'bin': , 'breakpoint': , 'callable': , 'chr': , 'compile': , 'delattr': , 'dir': , 'divmod': , 'eval': , 'exec': , 'format': , 'getattr': , 'globals': , 'hasattr': , 'hash': , 'hex': , 'id': , 'input': , 'isinstance': , 'issubclass': , 'iter': , 'len': , 'locals': , 'max': , 'min': , 'next': , 'oct': , 'ord': , 'pow': , 'print': , 'repr': , 'round': , 'setattr': , 'sorted': , 'sum': , 'vars': , 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': , 'memoryview': , 'bytearray': , 'bytes': , 'classmethod': , 'complex': , 'dict': , 'enumerate': , 'filter': , 'float': , 'frozenset': , 'property': , 'int': , 'list': , 'map': , 'object': , 'range': , 'reversed': , 'set': , 'slice': , 'staticmethod': , 'str': , 'super': , 'tuple': , 'type': , 'zip': , '__debug__': True, 'BaseException': , 'Exception': , 'TypeError': , 'StopAsyncIteration': , 'StopIteration': , 'GeneratorExit': , 'SystemExit': , 'KeyboardInterrupt': , 'ImportError': , 'ModuleNotFoundError': , 'OSError': , 'EnvironmentError': , 'IOError': , 'EOFError': , 'RuntimeError': , 'RecursionError': , 'NotImplementedError': , 'NameError': , 'UnboundLocalError': , 'AttributeError': , 'SyntaxError': , 'IndentationError': , 'TabError': , 'LookupError': , 'IndexError': , 'KeyError': , 'ValueError': , 'UnicodeError': , 'UnicodeEncodeError': , 'UnicodeDecodeError': , 'UnicodeTranslateError': , 'AssertionError': , 'ArithmeticError': , 'FloatingPointError': , 'OverflowError': , 'ZeroDivisionError': , 'SystemError': , 'ReferenceError': , 'MemoryError': , 'BufferError': , 'Warning': , 'UserWarning': , 'DeprecationWarning': , 'PendingDeprecationWarning': , 'SyntaxWarning': , 'RuntimeWarning': , 'FutureWarning': , 'ImportWarning': , 'UnicodeWarning': , 'BytesWarning': , 'ResourceWarning': , 'ConnectionError': , 'BlockingIOError': , 'BrokenPipeError': , 'ChildProcessError': , 'ConnectionAbortedError': , 'ConnectionRefusedError': , 'ConnectionResetError': , 'FileExistsError': , 'FileNotFoundError': , 'IsADirectoryError': , 'NotADirectoryError': , 'InterruptedError': , 'PermissionError': , 'ProcessLookupError': , 'TimeoutError': , 'open': , 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2022 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved., 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands\n for supporting Python development. See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object.}", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259928018176", + "presentation": null + }, + { + "name": "AddBreakpoint", + "value": "", + "lineNumber": -1, + "scope": "GLOBAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140258331079168", + "presentation": null + }, + { + "name": "random", + "value": "", + "lineNumber": -1, + "scope": "LOCAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259914813504", + "presentation": null + }, + { + "name": "random_number", + "value": "49.90006897806545", + "lineNumber": -1, + "scope": "LOCAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259851605296", + "presentation": null + }, + { + "name": "is_even", + "value": "False", + "lineNumber": -1, + "scope": "LOCAL_VARIABLE", + "liveClazz": "", + "liveIdentity": "140259935470944", + "presentation": null + } + ], + "sourceCode": "print(f\"{random_number} and is \" + (\"even\" if is_even else \"odd\"))" + }, + { + "method": "trigger_add_breakpoint", + "source": "src/main.py:10", + "column": null, + "variables": [], + "sourceCode": "command.AddBreakpoint.AddBreakpoint.simple_breakpoint()" + }, + { + "method": "execute_demos", + "source": "src/main.py:15", + "column": null, + "variables": [], + "sourceCode": "trigger_add_breakpoint()" + }, + { + "method": "run", + "source": "/usr/local/lib/python3.8/threading.py:870", + "column": null, + "variables": [], + "sourceCode": "self._target(*self._args, **self._kwargs)" + }, + { + "method": "_bootstrap_inner", + "source": "/usr/local/lib/python3.8/threading.py:932", + "column": null, + "variables": [], + "sourceCode": "self.run()" + }, + { + "method": "_bootstrap", + "source": "/usr/local/lib/python3.8/threading.py:890", + "column": null, + "variables": [], + "sourceCode": "self._bootstrap_inner()" + } + ], + "causedBy": null, + "language": "PYTHON" + }, + "eventType": "BREAKPOINT_HIT" +} \ No newline at end of file From f05d493c9122e119076ca085875becb1e1e63f7d Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Thu, 6 Oct 2022 18:43:28 +0400 Subject: [PATCH 21/28] refactor: remove duplicates --- .../marker/source/mark/api/ClassSourceMark.kt | 24 ----------- .../source/mark/api/ExpressionSourceMark.kt | 24 ----------- .../source/mark/api/MethodSourceMark.kt | 24 ----------- .../marker/source/mark/api/SourceMark.kt | 43 ++++++++++++------- 4 files changed, 27 insertions(+), 88 deletions(-) diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ClassSourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ClassSourceMark.kt index 7ccaf15e0..06b2223e1 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ClassSourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ClassSourceMark.kt @@ -28,10 +28,6 @@ import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEvent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener -import spp.jetbrains.marker.source.mark.api.key.SourceKey -import spp.jetbrains.marker.source.mark.guide.GuideMark -import spp.jetbrains.marker.source.mark.gutter.GutterMark -import spp.jetbrains.marker.source.mark.inlay.InlayMark import java.util.* /** @@ -80,26 +76,6 @@ abstract class ClassSourceMark( apply(configuration.componentProvider.getComponent(this), addToMarker, editor) } - override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> psiClass.nameIdentifier?.putUserData(SourceKey.GutterMark, null) - is InlayMark -> psiClass.nameIdentifier?.putUserData(SourceKey.InlayMark, null) - is GuideMark -> psiClass.nameIdentifier?.putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.dispose(removeFromMarker, assertRemoval) - } - - override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> psiClass.nameIdentifier?.putUserData(SourceKey.GutterMark, null) - is InlayMark -> psiClass.nameIdentifier?.putUserData(SourceKey.InlayMark, null) - is GuideMark -> psiClass.nameIdentifier?.putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.disposeSuspend(removeFromMarker, assertRemoval) - } - override val userData = HashMap() override fun getPsiElement(): PsiNameIdentifierOwner { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt index 3bace614d..61beb30ae 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/ExpressionSourceMark.kt @@ -25,10 +25,6 @@ import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEvent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener -import spp.jetbrains.marker.source.mark.api.key.SourceKey -import spp.jetbrains.marker.source.mark.guide.GuideMark -import spp.jetbrains.marker.source.mark.gutter.GutterMark -import spp.jetbrains.marker.source.mark.inlay.InlayMark import spp.protocol.artifact.ArtifactQualifiedName import java.util.* @@ -71,26 +67,6 @@ abstract class ExpressionSourceMark( apply(configuration.componentProvider.getComponent(this), addToMarker, editor) } - override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> getPsiElement().putUserData(SourceKey.GutterMark, null) - is InlayMark -> getPsiElement().putUserData(SourceKey.InlayMark, null) - is GuideMark -> getPsiElement().putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.dispose(removeFromMarker, assertRemoval) - } - - override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> getPsiElement().putUserData(SourceKey.GutterMark, null) - is InlayMark -> getPsiElement().putUserData(SourceKey.InlayMark, null) - is GuideMark -> getPsiElement().putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.disposeSuspend(removeFromMarker, assertRemoval) - } - override val userData = HashMap() fun getPsiExpression(): PsiElement { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/MethodSourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/MethodSourceMark.kt index fcb58848a..d589a0ed2 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/MethodSourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/MethodSourceMark.kt @@ -28,10 +28,6 @@ import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEvent import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener -import spp.jetbrains.marker.source.mark.api.key.SourceKey -import spp.jetbrains.marker.source.mark.guide.GuideMark -import spp.jetbrains.marker.source.mark.gutter.GutterMark -import spp.jetbrains.marker.source.mark.inlay.InlayMark import java.util.* /** @@ -81,26 +77,6 @@ abstract class MethodSourceMark( apply(configuration.componentProvider.getComponent(this), addToMarker, editor) } - override fun dispose(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.GutterMark, null) - is InlayMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.InlayMark, null) - is GuideMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.dispose(removeFromMarker, assertRemoval) - } - - override suspend fun disposeSuspend(removeFromMarker: Boolean, assertRemoval: Boolean) { - when (this) { - is GutterMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.GutterMark, null) - is InlayMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.InlayMark, null) - is GuideMark -> psiMethod.nameIdentifier?.putUserData(SourceKey.GuideMark, null) - else -> error("Unsupported source mark type: $this") - } - super.disposeSuspend(removeFromMarker, assertRemoval) - } - override val userData = HashMap() fun getPsiMethod(): PsiNameIdentifierOwner { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt index 18e6d6654..32d612c2d 100755 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt @@ -20,6 +20,7 @@ import com.intellij.codeInsight.hints.InlayHintsPassFactory import com.intellij.lang.Language import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.ReadAction import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.event.VisibleAreaEvent @@ -33,6 +34,7 @@ import com.intellij.openapi.ui.popup.JBPopupListener import com.intellij.openapi.ui.popup.LightweightWindowEvent import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Ref +import com.intellij.openapi.util.ThrowableComputable import com.intellij.psi.PsiElement import com.intellij.psi.PsiInvalidElementAccessException import com.intellij.ui.BalloonImpl @@ -238,27 +240,23 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener } fun dispose(removeFromMarker: Boolean = true, assertRemoval: Boolean = true) { - if (this is InlayMark) { - ApplicationManager.getApplication().invokeAndWait { - configuration.inlayRef?.get()?.dispose() - configuration.inlayRef = null - } - } - closePopup() + doDispose(removeFromMarker, assertRemoval) - if (removeFromMarker) { - if (assertRemoval) { - check(sourceFileMarker.removeSourceMark(this, autoRefresh = true, autoDispose = false)) - } else { - sourceFileMarker.removeSourceMark(this, autoRefresh = true, autoDispose = false) - } - } triggerEvent(SourceMarkEvent(this, SourceMarkEventCode.MARK_REMOVED)) { clearEventListeners() } } suspend fun disposeSuspend(removeFromMarker: Boolean = true, assertRemoval: Boolean = true) { + doDispose(removeFromMarker, assertRemoval) + + triggerEventSuspend(SourceMarkEvent(this, SourceMarkEventCode.MARK_REMOVED)) + clearEventListeners() + } + + private fun doDispose(removeFromMarker: Boolean, assertRemoval: Boolean) { + removeMarkFromUserData() + if (this is InlayMark) { ApplicationManager.getApplication().invokeAndWait { configuration.inlayRef?.get()?.dispose() @@ -274,8 +272,21 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener sourceFileMarker.removeSourceMark(this, autoRefresh = true, autoDispose = false) } } - triggerEventSuspend(SourceMarkEvent(this, SourceMarkEventCode.MARK_REMOVED)) - clearEventListeners() + } + + private fun removeMarkFromUserData() { + when (this) { + is ExpressionSourceMark -> removeMarkFromUserData(psiExpression) + is MethodSourceMark -> removeMarkFromUserData(ReadAction.compute(ThrowableComputable { getNameIdentifier() })) + is ClassSourceMark -> removeMarkFromUserData(ReadAction.compute(ThrowableComputable { getNameIdentifier() })) + else -> error("Unsupported source mark type: $this") + } + } + + private fun removeMarkFromUserData(element: PsiElement) { + element.putUserData(SourceKey.GutterMark, null) + element.putUserData(SourceKey.InlayMark, null) + element.putUserData(SourceKey.GuideMark, null) } fun getParent(): GuideMark? { From 6f6eafb12ddf34364699b4c9fecf13a1454a79c7 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 7 Oct 2022 00:17:41 +0400 Subject: [PATCH 22/28] chore: improve startup performance (lazy load jbcef client) --- .../mark/api/component/jcef/SourceMarkJcefComponent.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/jcef/SourceMarkJcefComponent.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/jcef/SourceMarkJcefComponent.kt index 2ef51c656..8a3c7255e 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/jcef/SourceMarkJcefComponent.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/jcef/SourceMarkJcefComponent.kt @@ -42,12 +42,12 @@ class SourceMarkJcefComponent( ) : SourceMarkComponent { companion object { - private val client: JBCefClient by lazy { JBCefApp.getInstance().createClient() } - - init { + private val client: JBCefClient by lazy { + val client = JBCefApp.getInstance().createClient() if (!ApplicationManager.getApplication().isUnitTestMode) { Disposer.register(ApplicationManager.getApplication(), client) } + client } } From 6c26039edde9a77ffc921bf665270cb9d5d1bae9 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 8 Oct 2022 21:01:22 +0400 Subject: [PATCH 23/28] feat: ability to set LCP on class/method and JVM end brackets (#867) * feat: ability to set LCP on class/method and function end brackets ref: https://github.com/sourceplusplus/sourceplusplus/issues/690, https://github.com/sourceplusplus/sourceplusplus/issues/726 * chore(deps): bump * refactor: remove mark filters (unused) added static method getSourceFileMarker * chore: put back --- commander | 2 +- .../jetbrains/command/LiveLocationContext.kt | 1 - .../marker/js/JavascriptLineMarkerProvider.kt | 2 - .../JavascriptArtifactCreationService.kt | 24 +- .../JavascriptArtifactNamingService.kt | 31 ++- .../marker/jvm/JVMLineMarkerProvider.kt | 22 +- .../marker/jvm/JVMSourceInlayHintProvider.kt | 21 +- .../jvm/service/JVMArtifactCreationService.kt | 8 +- .../jvm/service/JVMArtifactNamingService.kt | 10 +- .../jvm/service/JVMArtifactScopeService.kt | 20 +- .../jvm/service/utils/JVMMarkerUtils.kt | 222 +++++++----------- .../jvm/JVMArtifactNamingServiceTest.kt | 5 + .../marker/jvm/JVMGuideProviderTest.kt | 2 +- .../jvm/detect/JVMLoggerDetectorTest.kt | 4 +- .../marker/py/PythonLineMarkerProvider.kt | 2 - .../service/PythonArtifactCreationService.kt | 24 +- .../marker/py/PythonGuideProviderTest.kt | 2 +- .../jetbrains/marker/IArtifactScopeService.kt | 1 + .../spp/jetbrains/marker/SourceMarker.kt | 4 + .../marker/SourceMarkerConfiguration.kt | 2 - .../spp/jetbrains/marker/SourceMarkerUtils.kt | 33 ++- .../marker/impl/ArtifactScopeService.kt | 10 + .../marker/plugin/SourceInlayHintProvider.kt | 3 +- .../marker/plugin/SourceLineMarkerProvider.kt | 2 +- .../marker/source/SourceFileMarker.kt | 69 ++---- .../marker/source/mark/api/SourceMark.kt | 92 ++++---- .../mark/api/component/tooltip/LiveTooltip.kt | 2 +- .../api/config/SourceMarkConfiguration.kt | 2 - .../mark/api/filter/ApplySourceMarkFilter.kt | 36 --- .../mark/api/filter/CreateSourceMarkFilter.kt | 37 --- .../guide/config/GuideMarkConfiguration.kt | 2 - .../gutter/config/GutterMarkConfiguration.kt | 2 - .../source/mark/inlay/ExpressionInlayMark.kt | 8 + .../inlay/config/InlayMarkConfiguration.kt | 2 - .../jetbrains/sourcemarker/ControlBar.java | 41 ++-- .../sourcemarker/command/ControlBarAction.kt | 14 +- .../command/ControlBarController.kt | 54 +++-- .../mark/PluginSourceMarkEventListener.kt | 2 +- .../status/util/ControlBarCellRenderer.kt | 1 - 39 files changed, 311 insertions(+), 510 deletions(-) delete mode 100644 marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/ApplySourceMarkFilter.kt delete mode 100644 marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/CreateSourceMarkFilter.kt diff --git a/commander b/commander index 8332f7432..07c226757 160000 --- a/commander +++ b/commander @@ -1 +1 @@ -Subproject commit 8332f743299d9357834ffc5f9b491a2562cfc2ae +Subproject commit 07c22675706c52a973a9eb0f78bbbafc4f71b74f diff --git a/core/src/main/kotlin/spp/jetbrains/command/LiveLocationContext.kt b/core/src/main/kotlin/spp/jetbrains/command/LiveLocationContext.kt index 1414343b6..0872cad83 100644 --- a/core/src/main/kotlin/spp/jetbrains/command/LiveLocationContext.kt +++ b/core/src/main/kotlin/spp/jetbrains/command/LiveLocationContext.kt @@ -21,7 +21,6 @@ import spp.jetbrains.marker.source.SourceFileMarker import spp.protocol.artifact.ArtifactQualifiedName data class LiveLocationContext( - val lineNumber: Int, val qualifiedName: ArtifactQualifiedName, val fileMarker: SourceFileMarker, val element: PsiElement, diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLineMarkerProvider.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLineMarkerProvider.kt index 26f8e7b29..3243e392c 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLineMarkerProvider.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/JavascriptLineMarkerProvider.kt @@ -19,7 +19,6 @@ package spp.jetbrains.marker.js import com.intellij.codeInsight.daemon.LineMarkerInfo import com.intellij.lang.javascript.psi.JSFile import com.intellij.psi.PsiElement -import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.plugin.SourceLineMarkerProvider import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.gutter.GutterMark @@ -40,7 +39,6 @@ class JavascriptLineMarkerProvider : SourceLineMarkerProvider() { } override fun getLineMarkerInfo(parent: PsiElement?, element: PsiElement): LineMarkerInfo? { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) return null //todo: this } diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt index cf25ba58e..4a27b4000 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactCreationService.kt @@ -84,12 +84,8 @@ class JavascriptArtifactCreationService : IArtifactCreationService { SourceMark.Type.GUTTER ) as ExpressionGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - null - } + gutterMark.apply(true) + gutterMark } else { gutterMark } @@ -151,12 +147,8 @@ class JavascriptArtifactCreationService : IArtifactCreationService { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -188,12 +180,8 @@ class JavascriptArtifactCreationService : IArtifactCreationService { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - null - } + inlayMark.apply(true) + inlayMark } else { inlayMark } diff --git a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt index 643aa5fe5..a904a1629 100644 --- a/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt +++ b/marker/js-marker/src/main/kotlin/spp/jetbrains/marker/js/service/JavascriptArtifactNamingService.kt @@ -79,15 +79,18 @@ class JavascriptArtifactNamingService : IArtifactNamingService { override fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName { return when (element) { - is JSClass -> { - ArtifactQualifiedName(element.qualifiedName!!, null, ArtifactType.CLASS) - } + is JSClass -> ArtifactQualifiedName( + element.qualifiedName!!, + type = ArtifactType.CLASS, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) is JSFunctionExpression -> getStatementOrExpressionQualifiedName(element, ArtifactType.EXPRESSION) - - is JSFunction -> { - ArtifactQualifiedName(element.qualifiedName!!, null, ArtifactType.METHOD) - } + is JSFunction -> ArtifactQualifiedName( + element.qualifiedName!!, + type = ArtifactType.METHOD, + lineNumber = SourceMarkerUtils.getLineNumber(element) + ) is JSStatement, is JSStatementList -> getStatementOrExpressionQualifiedName(element, ArtifactType.STATEMENT) else -> getStatementOrExpressionQualifiedName(element, ArtifactType.EXPRESSION) @@ -104,12 +107,14 @@ class JavascriptArtifactNamingService : IArtifactNamingService { val parentElement = element.parentOfType() return if (parentElement != null) { ArtifactQualifiedName( - "${getFullyQualifiedName(parentElement).identifier}.${name}", null, type, + "${getFullyQualifiedName(parentElement).identifier}.${name}", + type = type, lineNumber = SourceMarkerUtils.getLineNumber(element) ) } else { ArtifactQualifiedName( - "${element.containingFile.virtualFile.path}#$name", null, type, + "${element.containingFile.virtualFile.path}#$name", + type = type, lineNumber = SourceMarkerUtils.getLineNumber(element) ) } @@ -120,7 +125,13 @@ class JavascriptArtifactNamingService : IArtifactNamingService { psiFile.acceptChildren(object : JSRecursiveWalkingElementVisitor() { override fun visitJSClass(node: JSClass) { // TODO: check this also works for typescript classes, otherwise use visitTypescriptClass super.visitJSClass(node) - classQualifiedNames.add(ArtifactQualifiedName(node.qualifiedName!!, type = ArtifactType.CLASS)) + classQualifiedNames.add( + ArtifactQualifiedName( + node.qualifiedName!!, + type = ArtifactType.CLASS, + lineNumber = SourceMarkerUtils.getLineNumber(node) + ) + ) } }) return classQualifiedNames diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt index d15838001..92037eb16 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMLineMarkerProvider.kt @@ -18,7 +18,6 @@ package spp.jetbrains.marker.jvm import com.intellij.codeInsight.daemon.GutterIconNavigationHandler import com.intellij.codeInsight.daemon.LineMarkerInfo -import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.editor.markup.GutterIconRenderer import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement @@ -27,13 +26,11 @@ import com.intellij.psi.PsiJavaFile import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.plugins.groovy.lang.psi.GroovyFile import org.jetbrains.uast.UClass -import org.jetbrains.uast.UMethod import org.jetbrains.uast.toUElement -import org.jetbrains.uast.toUElementOfType import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.impl.ArtifactCreationService -import spp.jetbrains.marker.plugin.SourceLineMarkerProvider import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils +import spp.jetbrains.marker.plugin.SourceLineMarkerProvider import spp.jetbrains.marker.source.SourceFileMarker.Companion.SUPPORTED_FILE_TYPES import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.key.SourceKey @@ -49,10 +46,6 @@ import spp.jetbrains.marker.source.mark.gutter.MethodGutterMark */ abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() { - companion object { - private val log = logger() - } - override fun getLineMarkerInfo( parent: PsiElement?, element: PsiElement @@ -65,9 +58,8 @@ abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() { } private fun getClassGutterMark(element: PsiIdentifier): LineMarkerInfo? { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) ?: return null + val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile) ?: return null val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(element.parent.toUElement() as UClass) - if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null //check by artifact name first due to user can erroneously name same class twice var gutterMark = fileMarker.getSourceMark(artifactQualifiedName, SourceMark.Type.GUTTER) as ClassGutterMark? @@ -95,14 +87,8 @@ abstract class JVMLineMarkerProvider : SourceLineMarkerProvider() { } private fun getMethodGutterMark(element: PsiElement): LineMarkerInfo? { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) ?: return null - val uMethod = element.parent.toUElementOfType() - if (uMethod == null) { - log.warn("Unable to transform to UMethod: ${element.parent}") - return null - } - val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(uMethod) - if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) return null + val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile) ?: return null + val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(element) //check by artifact name first due to user can erroneously name same method twice var gutterMark = fileMarker.getSourceMark( diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt index a6127405c..90d2da3e3 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/JVMSourceInlayHintProvider.kt @@ -22,12 +22,9 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethodCallExpression import com.intellij.psi.PsiStatement -import org.jetbrains.uast.UExpression -import org.jetbrains.uast.UMethod -import org.jetbrains.uast.toUElement import spp.jetbrains.marker.SourceMarker -import spp.jetbrains.marker.plugin.SourceInlayHintProvider import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils +import spp.jetbrains.marker.plugin.SourceInlayHintProvider import spp.jetbrains.marker.source.mark.inlay.InlayMark import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkVirtualText @@ -44,19 +41,11 @@ class JVMSourceInlayHintProvider : SourceInlayHintProvider() { if ((parent is PsiMethod && element === parent.nameIdentifier) || (JVMMarkerUtils.getNameIdentifier(parent) === element) ) { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile)!! - val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName(parent.toUElement() as UMethod) - return if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else { - JVMMarkerUtils.getOrCreateMethodInlayMark(fileMarker, element) - } + val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile)!! + return JVMMarkerUtils.getOrCreateMethodInlayMark(fileMarker, element) } else if (element is PsiStatement) { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile)!! - val artifactQualifiedName = JVMMarkerUtils.getFullyQualifiedName( - JVMMarkerUtils.getUniversalExpression(element).toUElement() as UExpression - ) - return if (!SourceMarker.getInstance(element.project).configuration.createSourceMarkFilter.test(artifactQualifiedName)) null else { - JVMMarkerUtils.getOrCreateExpressionInlayMark(fileMarker, element) - } + val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile)!! + return JVMMarkerUtils.getOrCreateExpressionInlayMark(fileMarker, element) } return null } diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt index 8f077e47e..7015da9c6 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt @@ -73,12 +73,8 @@ class JVMArtifactCreationService : IArtifactCreationService { SourceMark.Type.GUTTER ) as MethodGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - null - } + gutterMark.apply(true) + gutterMark } else { gutterMark } diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt index 9c3be7736..783034181 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactNamingService.kt @@ -21,7 +21,6 @@ import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.psi.* import com.intellij.psi.util.ClassUtil -import org.jetbrains.uast.* import spp.jetbrains.marker.IArtifactNamingService import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils @@ -84,14 +83,7 @@ class JVMArtifactNamingService : IArtifactNamingService { } override fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName { - return when (val uElement = element.toUElement()) { - is UClass -> JVMMarkerUtils.getFullyQualifiedName(uElement) - is UMethod -> JVMMarkerUtils.getFullyQualifiedName(uElement) - is UExpression -> JVMMarkerUtils.getFullyQualifiedName(element) - is UDeclaration -> JVMMarkerUtils.getFullyQualifiedName(element) - is UIdentifier -> JVMMarkerUtils.getFullyQualifiedName(element) - else -> TODO("Not yet implemented") - } + return JVMMarkerUtils.getFullyQualifiedName(element) } override fun getQualifiedClassNames(psiFile: PsiFile): List { diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt index 647e6a508..2abb90e43 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt @@ -22,6 +22,7 @@ import com.intellij.psi.scope.util.PsiScopesUtil import com.intellij.psi.util.parentOfTypes import com.siyeh.ig.psiutils.ControlFlowUtils import org.jetbrains.kotlin.psi.KtNamedFunction +import org.joor.Reflect import spp.jetbrains.marker.IArtifactScopeService import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.source.SourceFileMarker @@ -34,14 +35,6 @@ import spp.jetbrains.marker.source.SourceFileMarker */ class JVMArtifactScopeService : IArtifactScopeService { - fun isMethodAtLine(psiFile: PsiFile, lineNumber: Int): Boolean { - var el = SourceMarkerUtils.getElementAtLine(psiFile, lineNumber) - while (el is PsiKeyword || el is PsiModifierList) { - el = el.parent - } - return el is PsiMethod - } - override fun getScopeVariables(fileMarker: SourceFileMarker, lineNumber: Int): List { //determine available vars var checkLine = lineNumber @@ -73,4 +66,15 @@ class JVMArtifactScopeService : IArtifactScopeService { } override fun isJVM(element: PsiElement): Boolean = true + + override fun canShowControlBar(psiElement: PsiElement): Boolean { + return when (psiElement::class.java.name) { + "org.jetbrains.kotlin.psi.KtObjectDeclaration" -> false + "org.jetbrains.kotlin.psi.KtProperty" -> { + Reflect.on(psiElement).call("isLocal").get() == true + } + + else -> super.canShowControlBar(psiElement) + } + } } diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt index 45210267f..da6e66e88 100755 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt @@ -20,6 +20,8 @@ import com.intellij.lang.jvm.util.JvmClassUtil import com.intellij.openapi.diagnostic.logger import com.intellij.psi.* import com.intellij.psi.util.PsiUtil +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.uast.* import org.joor.Reflect import spp.jetbrains.marker.SourceMarkerUtils @@ -59,8 +61,7 @@ object JVMMarkerUtils { autoApply: Boolean = false ): ExpressionInlayMark? { log.trace("getOrCreateExpressionInlayMark: $element") - val statementExpression: PsiElement = getUniversalExpression(element) - var lookupExpression: PsiElement = statementExpression + var lookupExpression: PsiElement = element if (lookupExpression is PsiDeclarationStatement) { //todo: support for multi-declaration statements lookupExpression = lookupExpression.firstChild @@ -73,12 +74,8 @@ object JVMMarkerUtils { SourceMark.Type.INLAY ) as ExpressionInlayMark? if (inlayMark != null) { - if (inlayMark.updatePsiExpression( - statementExpression, - getFullyQualifiedName(statementExpression.toUElement() as UExpression) - ) - ) { - statementExpression.putUserData(SourceKey.InlayMark, inlayMark) + if (inlayMark.updatePsiExpression(lookupExpression, getFullyQualifiedName(lookupExpression))) { + lookupExpression.putUserData(SourceKey.InlayMark, inlayMark) } else { inlayMark = null } @@ -87,22 +84,18 @@ object JVMMarkerUtils { return if (inlayMark == null) { inlayMark = fileMarker.createExpressionSourceMark( - statementExpression, + lookupExpression, SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - null - } + inlayMark.apply(true) + inlayMark } else { inlayMark } } else { if (fileMarker.removeIfInvalid(inlayMark)) { - statementExpression.putUserData(SourceKey.InlayMark, null) + lookupExpression.putUserData(SourceKey.InlayMark, null) null } else { inlayMark @@ -131,10 +124,7 @@ object JVMMarkerUtils { SourceMark.Type.INLAY ) as ExpressionInlayMark? if (inlayMark != null) { - if (inlayMark.updatePsiExpression( - element, getFullyQualifiedName(element.toUElement() as UExpression) - ) - ) { + if (inlayMark.updatePsiExpression(element, getFullyQualifiedName(element))) { element.putUserData(SourceKey.InlayMark, inlayMark) } else { inlayMark = null @@ -143,19 +133,17 @@ object JVMMarkerUtils { } return if (inlayMark == null) { - val uExpression = element.toUElement() - if (uExpression !is UExpression && uExpression !is UDeclaration) return null + if (element.text != "}") { + val uExpression = element.toUElement() + if (uExpression !is UExpression && uExpression !is UDeclaration) return null + } inlayMark = fileMarker.createExpressionSourceMark( element, SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - null - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -183,18 +171,13 @@ object JVMMarkerUtils { autoApply: Boolean = false ): ExpressionInlayMark { log.trace("createExpressionInlayMark: $element") - val statementExpression: PsiElement = getUniversalExpression(element) val inlayMark = fileMarker.createExpressionSourceMark( - statementExpression, + element, SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -219,12 +202,8 @@ object JVMMarkerUtils { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -244,8 +223,7 @@ object JVMMarkerUtils { autoApply: Boolean = false ): ExpressionGutterMark? { log.trace("getOrCreateExpressionGutterMark: $element") - val statementExpression: PsiElement = getUniversalExpression(element) - var lookupExpression: PsiElement = statementExpression + var lookupExpression: PsiElement = element if (lookupExpression is PsiDeclarationStatement) { //todo: support for multi-declaration statements lookupExpression = lookupExpression.firstChild @@ -258,11 +236,8 @@ object JVMMarkerUtils { SourceMark.Type.GUTTER ) as ExpressionGutterMark? if (gutterMark != null) { - if (gutterMark.updatePsiExpression( - statementExpression, getFullyQualifiedName(statementExpression.toUElement() as UExpression) - ) - ) { - statementExpression.putUserData(SourceKey.GutterMark, gutterMark) + if (gutterMark.updatePsiExpression(lookupExpression, getFullyQualifiedName(lookupExpression))) { + lookupExpression.putUserData(SourceKey.GutterMark, gutterMark) } else { gutterMark = null } @@ -271,22 +246,18 @@ object JVMMarkerUtils { return if (gutterMark == null) { gutterMark = fileMarker.createExpressionSourceMark( - statementExpression, + lookupExpression, SourceMark.Type.GUTTER ) as ExpressionGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - null - } + gutterMark.apply(true) + gutterMark } else { gutterMark } } else { if (fileMarker.removeIfInvalid(gutterMark)) { - statementExpression.putUserData(SourceKey.InlayMark, null) + lookupExpression.putUserData(SourceKey.InlayMark, null) null } else { gutterMark @@ -294,20 +265,6 @@ object JVMMarkerUtils { } } - /** - * todo: description. - * - * @since 0.1.0 - */ - @JvmStatic - fun getUniversalExpression(element: PsiStatement): PsiElement { - var statementExpression: PsiElement = element - if (statementExpression is PsiExpressionStatement) { - statementExpression = statementExpression.firstChild - } - return statementExpression - } - /** * todo: description. * @@ -339,12 +296,8 @@ object JVMMarkerUtils { SourceMark.Type.INLAY ) as MethodInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - null - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -394,12 +347,8 @@ object JVMMarkerUtils { SourceMark.Type.GUTTER ) as ClassGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - null - } + gutterMark.apply(true) + gutterMark } else { gutterMark } @@ -433,63 +382,32 @@ object JVMMarkerUtils { return null } - /** - * todo: description. - * - * @since 0.1.0 - */ - @JvmStatic - fun getQualifiedClassName(qualifiedName: ArtifactQualifiedName): ArtifactQualifiedName { - var withoutArgs = qualifiedName.identifier.substring(0, qualifiedName.identifier.indexOf("(")) - val classQualifiedName = if (withoutArgs.contains("<")) { - withoutArgs = withoutArgs.substring(0, withoutArgs.indexOf("<")) - withoutArgs.substring(withoutArgs.lastIndexOf("?") + 1, withoutArgs.lastIndexOf(".")) - } else { - withoutArgs.substring(withoutArgs.lastIndexOf("?") + 1, withoutArgs.lastIndexOf(".")) - } - return ArtifactQualifiedName(classQualifiedName, type = ArtifactType.CLASS) - } - - /** - * todo: description. - * - * @since 0.1.0 - */ - @JvmStatic - fun getFullyQualifiedName(expression: UExpression): ArtifactQualifiedName { - val qualifiedMethodName = expression.getContainingUMethod()?.let { getFullyQualifiedName(it) } - return ArtifactQualifiedName( - """${qualifiedMethodName!!.identifier}#${ - Base64.getEncoder().encodeToString(expression.toString().toByteArray()) - }""", - type = ArtifactType.EXPRESSION, - lineNumber = expression.sourcePsi?.let { SourceMarkerUtils.getLineNumber(it) } - ) - } - @JvmStatic fun getFullyQualifiedName(element: PsiElement): ArtifactQualifiedName { - val expression = element.toUElement()!! - var expressionString = expression.sourcePsi?.text ?: expression.toString() - var parentIdentifier = expression.getContainingUMethod()?.let { getFullyQualifiedName(it) } - if (parentIdentifier == null) { - parentIdentifier = expression.sourcePsi?.findAnyContainingStrict(UMethod::class.java)?.let { - getFullyQualifiedName(it) - } + if (element is KtClass) { + return getFullyQualifiedName(element) + } else if (element is KtFunction) { + return getFullyQualifiedName(element) + } else if (element is PsiClass) { + return getFullyQualifiedName(element) + } else if (element is PsiMethod) { + return getFullyQualifiedName(element) } - if (parentIdentifier == null) { - parentIdentifier = expression.getContainingUClass()?.let { getFullyQualifiedName(it) } + + var expressionString = element.text + var parentIdentifier = element.findAnyContainingStrict(PsiMethod::class.java, KtFunction::class.java)?.let { + getFullyQualifiedName(it) } if (parentIdentifier == null) { - parentIdentifier = expression.sourcePsi?.findAnyContainingStrict(UClass::class.java)?.let { + parentIdentifier = element.findAnyContainingStrict(PsiClass::class.java, KtClass::class.java)?.let { getFullyQualifiedName(it) } } if (parentIdentifier == null) { - error("Could not determine parent of element: $element") + error("Could not determine parent of element: $element") //todo: extension function, see SourceMarkerConfig, make test } - expression.sourcePsi?.textRange?.startOffset?.let { + element.textRange.startOffset.let { expressionString = "$expressionString:$it" } return ArtifactQualifiedName( @@ -525,16 +443,42 @@ object JVMMarkerUtils { */ @JvmStatic fun getFullyQualifiedName(theClass: UClass): ArtifactQualifiedName { - return ArtifactQualifiedName("${JvmClassUtil.getJvmClassName(theClass)}", type = ArtifactType.CLASS) + return getFullyQualifiedName(theClass as PsiClass) + } + + @JvmStatic + fun getFullyQualifiedName(clazz: PsiClass): ArtifactQualifiedName { + return ArtifactQualifiedName( + "${JvmClassUtil.getJvmClassName(clazz)}", + type = ArtifactType.CLASS, + lineNumber = clazz.nameIdentifier?.let { SourceMarkerUtils.getLineNumber(it) } + ) + } + + @JvmStatic + private fun getFullyQualifiedName(theClass: KtClass): ArtifactQualifiedName { + return getFullyQualifiedName(theClass.toUElementOfType()!!) + } + + @JvmStatic + private fun getFullyQualifiedName(method: KtFunction): ArtifactQualifiedName { + return getFullyQualifiedName(method.toUElementOfType()!!) + } + + @JvmStatic + fun getFullyQualifiedName(method: PsiMethod): ArtifactQualifiedName { + val classQualifiedName = method.findAnyContainingStrict(PsiClass::class.java)?.let { + getFullyQualifiedName(it).identifier + } + return ArtifactQualifiedName( + "$classQualifiedName.${getQualifiedName(method)}", + type = ArtifactType.METHOD, + lineNumber = method.nameIdentifier?.let { SourceMarkerUtils.getLineNumber(it) } + ) } - /** - * todo: description. - * - * @since 0.1.0 - */ @JvmStatic - fun getQualifiedName(method: UMethod): String { + private fun getQualifiedName(method: PsiMethod): String { val methodName = method.nameIdentifier!!.text var methodParams = "" method.parameterList.parameters.forEach { @@ -577,14 +521,14 @@ object JVMMarkerUtils { return arrayDimensions } - private fun PsiElement?.findAnyContainingStrict( + private fun PsiElement?.findAnyContainingStrict( vararg types: Class ): T? { val depthLimit: Int = Integer.MAX_VALUE - var element = this + var element = this?.parent var i = 0 while (i < depthLimit && element != null && element !is PsiFileSystemItem) { - element.toUElement()?.let { + element.let { for (type in types) { if (type.isInstance(it)) { return it as T diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt index e68469df3..761fc5d66 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMArtifactNamingServiceTest.kt @@ -73,6 +73,7 @@ class JVMArtifactNamingServiceTest : BasePlatformTestCase() { val name = JVMArtifactNamingService().getFullyQualifiedName(clazz!!) assertEquals(getTestName(false) + "", name.identifier) assertEquals(ArtifactType.CLASS, name.type) + assertNotNull(name.lineNumber) } fun testJavaInnerClassName() { @@ -95,6 +96,7 @@ class JVMArtifactNamingServiceTest : BasePlatformTestCase() { val parentName = JVMArtifactNamingService().getFullyQualifiedName(clazz!!) assertEquals(getTestName(false) + "", parentName.identifier) assertEquals(ArtifactType.CLASS, parentName.type) + assertNotNull(parentName.lineNumber) val innerClazz = clazz.findDescendantOfType { it !== clazz } assertNotNull(innerClazz) @@ -102,6 +104,7 @@ class JVMArtifactNamingServiceTest : BasePlatformTestCase() { val innerName = JVMArtifactNamingService().getFullyQualifiedName(innerClazz!!) assertEquals(getTestName(false) + "\$InnerClassName", innerName.identifier) assertEquals(ArtifactType.CLASS, innerName.type) + assertNotNull(innerName.lineNumber) } fun testJavaMethodName() { @@ -124,6 +127,7 @@ class JVMArtifactNamingServiceTest : BasePlatformTestCase() { val name = JVMArtifactNamingService().getFullyQualifiedName(method!!) assertEquals(getTestName(false) + ".foo()", name.identifier) assertEquals(ArtifactType.METHOD, name.type) + assertNotNull(name.lineNumber) } fun testJavaInnerClassMethodName() { @@ -146,6 +150,7 @@ class JVMArtifactNamingServiceTest : BasePlatformTestCase() { val name = JVMArtifactNamingService().getFullyQualifiedName(method!!) assertEquals(getTestName(false) + "\$InnerClassName.foo()", name.identifier) assertEquals(ArtifactType.METHOD, name.type) + assertNotNull(name.lineNumber) } fun testJavaMethodVariable() { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMGuideProviderTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMGuideProviderTest.kt index 226035614..924e686f0 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMGuideProviderTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/JVMGuideProviderTest.kt @@ -65,7 +65,7 @@ class JVMGuideProviderTest : BasePlatformTestCase() { private fun doTest(extension: String) { val psiFile = myFixture.configureByFile(getTestName(false) + ".$extension") - val fileMarker = SourceMarker.getInstance(myFixture.project).getSourceFileMarker(psiFile) + val fileMarker = SourceMarker.getSourceFileMarker(psiFile) assertNotNull(fileMarker) runBlocking { diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt index 34010f5da..9d64cf9e5 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt @@ -148,7 +148,7 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { JVMMarker.setup() SourceFileMarker.SUPPORTED_FILE_TYPES.add(PsiJavaFile::class.java) - val fileMarker = SourceMarker.getInstance(project).getSourceFileMarker(sourceFile!!) + val fileMarker = SourceMarker.getSourceFileMarker(sourceFile!!) assertNotNull(fileMarker) val result = JVMLoggerDetector(project.apply { UserData.vertx(this, Vertx.vertx()) }) @@ -184,7 +184,7 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { JVMMarker.setup() SourceFileMarker.SUPPORTED_FILE_TYPES.add(KtFile::class.java) - val fileMarker = SourceMarker.getInstance(project).getSourceFileMarker(sourceFile!!) + val fileMarker = SourceMarker.getSourceFileMarker(sourceFile!!) assertNotNull(fileMarker) val result = JVMLoggerDetector(project.apply { UserData.vertx(this, Vertx.vertx()) }) diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLineMarkerProvider.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLineMarkerProvider.kt index 203571ed3..04aae1a81 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLineMarkerProvider.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/PythonLineMarkerProvider.kt @@ -19,7 +19,6 @@ package spp.jetbrains.marker.py import com.intellij.codeInsight.daemon.LineMarkerInfo import com.intellij.psi.PsiElement import com.jetbrains.python.psi.PyFile -import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.plugin.SourceLineMarkerProvider import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.gutter.GutterMark @@ -39,7 +38,6 @@ class PythonLineMarkerProvider : SourceLineMarkerProvider() { } override fun getLineMarkerInfo(parent: PsiElement?, element: PsiElement): LineMarkerInfo? { - val fileMarker = SourceMarker.getInstance(element.project).getSourceFileMarker(element.containingFile) return null //todo: this } diff --git a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt index 1f1a09ad2..8f1696dbe 100644 --- a/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt +++ b/marker/py-marker/src/main/kotlin/spp/jetbrains/marker/py/service/PythonArtifactCreationService.kt @@ -84,12 +84,8 @@ class PythonArtifactCreationService : IArtifactCreationService { SourceMark.Type.GUTTER ) as ExpressionGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - null - } + gutterMark.apply(true) + gutterMark } else { gutterMark } @@ -151,12 +147,8 @@ class PythonArtifactCreationService : IArtifactCreationService { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -188,12 +180,8 @@ class PythonArtifactCreationService : IArtifactCreationService { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - null - } + inlayMark.apply(true) + inlayMark } else { inlayMark } diff --git a/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt index 190f9c375..6c1e01619 100644 --- a/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt +++ b/marker/py-marker/src/test/kotlin/spp/jetbrains/marker/py/PythonGuideProviderTest.kt @@ -48,7 +48,7 @@ class PythonGuideProviderTest : BasePlatformTestCase() { fun testPythonMethod() { val psiFile = myFixture.configureByFile(getTestName(false) + ".py") - val fileMarker = SourceMarker.getInstance(myFixture.project).getSourceFileMarker(psiFile) + val fileMarker = SourceMarker.getSourceFileMarker(psiFile) assertNotNull(fileMarker) runBlocking { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactScopeService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactScopeService.kt index 78b7bba39..8bf04c9e9 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactScopeService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/IArtifactScopeService.kt @@ -31,4 +31,5 @@ interface IArtifactScopeService : ISourceMarkerService { fun isInsideFunction(element: PsiElement): Boolean fun isInsideEndlessLoop(element: PsiElement): Boolean = false fun isJVM(element: PsiElement): Boolean = false + fun canShowControlBar(psiElement: PsiElement): Boolean = true } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt index 1f3a5bc12..76bcde3d1 100755 --- a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarker.kt @@ -60,6 +60,10 @@ class SourceMarker { } return project.getUserData(KEY)!! } + + fun getSourceFileMarker(psiFile: PsiFile): SourceFileMarker? { + return getInstance(psiFile.project).getSourceFileMarker(psiFile) + } } @Volatile diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerConfiguration.kt b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerConfiguration.kt index f0f266a67..2b64f97e9 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerConfiguration.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerConfiguration.kt @@ -18,7 +18,6 @@ package spp.jetbrains.marker import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.SourceFileMarkerProvider -import spp.jetbrains.marker.source.mark.api.filter.CreateSourceMarkFilter import spp.jetbrains.marker.source.mark.guide.config.GuideMarkConfiguration import spp.jetbrains.marker.source.mark.gutter.config.GutterMarkConfiguration import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkConfiguration @@ -30,7 +29,6 @@ import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkConfiguration * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ class SourceMarkerConfiguration { - var createSourceMarkFilter: CreateSourceMarkFilter = CreateSourceMarkFilter.ALL var sourceFileMarkerProvider: SourceFileMarkerProvider = object : SourceFileMarkerProvider {} var gutterMarkConfiguration: GutterMarkConfiguration = GutterMarkConfiguration() var inlayMarkConfiguration: InlayMarkConfiguration = InlayMarkConfiguration() diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt index 30cb120d3..2429d80a0 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt @@ -17,9 +17,8 @@ package spp.jetbrains.marker import com.intellij.openapi.editor.Document -import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile +import com.intellij.psi.* +import com.intellij.psi.util.parentOfType import spp.jetbrains.marker.source.mark.api.SourceMark /** @@ -30,20 +29,6 @@ import spp.jetbrains.marker.source.mark.api.SourceMark */ object SourceMarkerUtils { - /** - * todo: description. - * - * @since 0.3.0 - */ - @JvmStatic - fun isBlankLine(psiFile: PsiFile, lineNumber: Int): Boolean { - val element = getElementAtLine(psiFile, lineNumber) - if (element != null) { - return getLineNumber(element) != lineNumber - } - return true - } - /** * todo: description. * @@ -61,6 +46,20 @@ object SourceMarkerUtils { val offset = document.getLineStartOffset(line - 1) var element = file.viewProvider.findElementAt(offset) if (element != null) { + //check for name identifier on same line (e.g. class/method name) + val nameIdentifierOwner = element.parentOfType() + if (nameIdentifierOwner != null && nameIdentifierOwner.nameIdentifier?.let { getLineNumber(it) } == line) { + return nameIdentifierOwner + } + + //check for annotation on same line + val annotation = element.parentOfType() + if (annotation != null && getLineNumber(annotation) == line) { + if (annotation.owner is PsiModifierList) { + return (annotation.owner as PsiModifierList).parent + } + } + if (document.getLineNumber(element.textOffset) != line - 1) { element = element.nextSibling } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt index e94da413a..dd8ad3ad1 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/impl/ArtifactScopeService.kt @@ -20,6 +20,8 @@ import com.intellij.psi.PsiElement import spp.jetbrains.marker.AbstractSourceMarkerService import spp.jetbrains.marker.IArtifactScopeService import spp.jetbrains.marker.source.SourceFileMarker +import spp.protocol.artifact.ArtifactQualifiedName +import spp.protocol.artifact.ArtifactType /** * todo: description. @@ -33,10 +35,18 @@ object ArtifactScopeService : AbstractSourceMarkerService return getService(fileMarker.psiFile.language).getScopeVariables(fileMarker, lineNumber) } + fun isOnFunction(qualifiedName: ArtifactQualifiedName): Boolean { + return qualifiedName.type == ArtifactType.METHOD + } + override fun isInsideFunction(element: PsiElement): Boolean { return getService(element.language).isInsideFunction(element) } + fun isOnOrInsideFunction(qualifiedName: ArtifactQualifiedName, element: PsiElement): Boolean { + return isOnFunction(qualifiedName) || isInsideFunction(element) + } + override fun isInsideEndlessLoop(element: PsiElement): Boolean { return getService(element.language).isInsideEndlessLoop(element) } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt b/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt index 3a124df9b..aa881ce4a 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt @@ -146,14 +146,13 @@ abstract class SourceInlayHintProvider : InlayHintsProvider { return object : FactoryInlayHintsCollector(editor) { override fun collect(element: PsiElement, editor: Editor, sink: InlayHintsSink): Boolean { - val fileMarker = SourceMarker.getInstance(editor.project!!).getSourceFileMarker(element.containingFile) ?: return true + val fileMarker = SourceMarker.getSourceFileMarker(element.containingFile) ?: return true var inlayMark = element.getUserData(SourceKey.InlayMark) if (inlayMark == null) { if (SourceMarker.getInstance(editor.project!!).configuration.inlayMarkConfiguration.strictlyManualCreation) return true else { inlayMark = createInlayMarkIfNecessary(element) ?: return true } } - if (!fileMarker.containsSourceMark(inlayMark) && !inlayMark.canApply()) return true if (!fileMarker.containsSourceMark(inlayMark)) inlayMark.apply() if (!inlayMark.isVisible()) { return true diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceLineMarkerProvider.kt b/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceLineMarkerProvider.kt index b136a5c68..091193788 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceLineMarkerProvider.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceLineMarkerProvider.kt @@ -87,7 +87,7 @@ abstract class SourceLineMarkerProvider : LineMarkerProviderDescriptor() { } elements.stream().map { it.containingFile }.distinct().forEach { - SourceMarker.getInstance(it.project).getSourceFileMarker(it)?.removeInvalidSourceMarks() + SourceMarker.getSourceFileMarker(it)?.removeInvalidSourceMarks() } } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/SourceFileMarker.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/SourceFileMarker.kt index 0fe6560fb..559280e18 100755 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/SourceFileMarker.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/SourceFileMarker.kt @@ -150,28 +150,25 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider { @JvmOverloads open fun applySourceMark( sourceMark: SourceMark, - autoRefresh: Boolean = false, - overrideFilter: Boolean = false + autoRefresh: Boolean = false ): Boolean { - if (overrideFilter || sourceMark.canApply()) { - log.trace("Applying source mark for artifact: $sourceMark") - sourceMark.triggerEvent(SourceMarkEvent(sourceMark, SourceMarkEventCode.MARK_BEFORE_ADDED)) - if (sourceMarks.add(sourceMark)) { - when (sourceMark) { - is ClassGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark) - is ClassGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark) - is MethodGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark) - is MethodInlayMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.InlayMark, sourceMark) - is MethodGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark) - is ExpressionGutterMark -> sourceMark.getPsiElement().putUserData(SourceKey.GutterMark, sourceMark) - is ExpressionInlayMark -> sourceMark.getPsiElement().putUserData(SourceKey.InlayMark, sourceMark) - is ExpressionGuideMark -> sourceMark.getPsiElement().putUserData(SourceKey.GuideMark, sourceMark) - } - - if (autoRefresh) refresh() - log.trace("Applied source mark for artifact: $sourceMark") - return true + log.trace("Applying source mark for artifact: $sourceMark") + sourceMark.triggerEvent(SourceMarkEvent(sourceMark, SourceMarkEventCode.MARK_BEFORE_ADDED)) + if (sourceMarks.add(sourceMark)) { + when (sourceMark) { + is ClassGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark) + is ClassGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark) + is MethodGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark) + is MethodInlayMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.InlayMark, sourceMark) + is MethodGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark) + is ExpressionGutterMark -> sourceMark.getPsiElement().putUserData(SourceKey.GutterMark, sourceMark) + is ExpressionInlayMark -> sourceMark.getPsiElement().putUserData(SourceKey.InlayMark, sourceMark) + is ExpressionGuideMark -> sourceMark.getPsiElement().putUserData(SourceKey.GuideMark, sourceMark) } + + if (autoRefresh) refresh() + log.trace("Applied source mark for artifact: $sourceMark") + return true } return false } @@ -255,12 +252,8 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider { SourceMark.Type.GUTTER ) as MethodGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - error("Could not apply gutter mark: $gutterMark") - } + gutterMark.apply(true) + gutterMark } else { gutterMark } @@ -276,12 +269,8 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider { SourceMark.Type.INLAY ) as MethodInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } @@ -297,12 +286,8 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider { SourceMark.Type.GUTTER ) as ExpressionGutterMark return if (autoApply) { - if (gutterMark.canApply()) { - gutterMark.apply(true) - gutterMark - } else { - error("Could not apply gutter mark: $gutterMark") - } + gutterMark.apply(true) + gutterMark } else { gutterMark } @@ -318,12 +303,8 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider { SourceMark.Type.INLAY ) as ExpressionInlayMark return if (autoApply) { - if (inlayMark.canApply()) { - inlayMark.apply(true) - inlayMark - } else { - error("Could not apply inlay mark: $inlayMark") - } + inlayMark.apply(true) + inlayMark } else { inlayMark } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt index 32d612c2d..dfff51bd2 100755 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/SourceMark.kt @@ -137,8 +137,6 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener fun isVisible(): Boolean fun setVisible(visible: Boolean) - fun canApply(): Boolean = configuration.applySourceMarkFilter.test(this) - fun applyIfMissing() { if (!sourceFileMarker.containsSourceMark(this)) { apply(true) @@ -149,7 +147,7 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener fun apply(addToMarker: Boolean = true, editor: Editor? = null) { SourceMarker.getInstance(project).getGlobalSourceMarkEventListeners().forEach(::addEventListener) - if (addToMarker && sourceFileMarker.applySourceMark(this, autoRefresh = true, overrideFilter = true)) { + if (addToMarker && sourceFileMarker.applySourceMark(this, autoRefresh = true)) { triggerEvent(SourceMarkEvent(this, SourceMarkEventCode.MARK_ADDED)) if (this is GutterMark) { @@ -168,60 +166,56 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener } } else if (this is InlayMark) { if (configuration.showComponentInlay) { - val selectedEditor = editor ?: FileEditorManager.getInstance(project).selectedTextEditor - if (selectedEditor == null) { - TODO() - } else { - val provider = SourceInlayComponentProvider.from(selectedEditor) - val viewport = (selectedEditor as? EditorImpl)?.scrollPane?.viewport!! - var displayLineIndex = lineNumber - 1 - if (this is ExpressionInlayMark) { - if (showAboveExpression) { - displayLineIndex-- - } + val selectedEditor = editor ?: FileEditorManager.getInstance(project).selectedTextEditor!! + val provider = SourceInlayComponentProvider.from(selectedEditor) + val viewport = (selectedEditor as? EditorImpl)?.scrollPane?.viewport!! + var displayLineIndex = artifactQualifiedName.lineNumber!! - 1 + if (this is ExpressionInlayMark) { + if (showAboveExpression) { + displayLineIndex-- } + } - if (isVisible()) { - val inlay = provider.insertAfter( - displayLineIndex, - configuration.componentProvider.getComponent(this).getComponent() - ) - configuration.inlayRef = Ref.create() - configuration.inlayRef!!.set(inlay) - viewport.dispatchEvent(ComponentEvent(viewport, ComponentEvent.COMPONENT_RESIZED)) - - //initial mark visible event - triggerEvent(SourceMarkEvent(this, INLAY_MARK_VISIBLE)) - } else { - setVisible(false) - } + if (isVisible()) { + val inlay = provider.insertAfter( + displayLineIndex, + configuration.componentProvider.getComponent(this).getComponent() + ) + configuration.inlayRef = Ref.create() + configuration.inlayRef!!.set(inlay) + viewport.dispatchEvent(ComponentEvent(viewport, ComponentEvent.COMPONENT_RESIZED)) - addEventListener(SynchronousSourceMarkEventListener { - when (it.eventCode) { - INLAY_MARK_VISIBLE -> { - ApplicationManager.getApplication().invokeLater { - configuration.inlayRef = Ref.create() - configuration.inlayRef!!.set( - provider.insertAfter( - displayLineIndex, - configuration.componentProvider.getComponent(this).getComponent() - ) - ) - viewport.dispatchEvent( - ComponentEvent(viewport, ComponentEvent.COMPONENT_RESIZED) + //initial mark visible event + triggerEvent(SourceMarkEvent(this, INLAY_MARK_VISIBLE)) + } else { + setVisible(false) + } + + addEventListener(SynchronousSourceMarkEventListener { + when (it.eventCode) { + INLAY_MARK_VISIBLE -> { + ApplicationManager.getApplication().invokeLater { + configuration.inlayRef = Ref.create() + configuration.inlayRef!!.set( + provider.insertAfter( + displayLineIndex, + configuration.componentProvider.getComponent(this).getComponent() ) - } + ) + viewport.dispatchEvent( + ComponentEvent(viewport, ComponentEvent.COMPONENT_RESIZED) + ) } + } - INLAY_MARK_HIDDEN -> { - ApplicationManager.getApplication().invokeLater { - configuration.inlayRef?.get()?.dispose() - configuration.inlayRef = null - } + INLAY_MARK_HIDDEN -> { + ApplicationManager.getApplication().invokeLater { + configuration.inlayRef?.get()?.dispose() + configuration.inlayRef = null } } - }) - } + } + }) } else { ApplicationManager.getApplication().invokeLater { InlayHintsPassFactory.forceHintsUpdateOnNextPass() diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/tooltip/LiveTooltip.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/tooltip/LiveTooltip.kt index 6feabdd93..5793eccc8 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/tooltip/LiveTooltip.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/component/tooltip/LiveTooltip.kt @@ -136,7 +136,7 @@ open class LiveTooltip(val guideMark: GuideMark, var panel: JPanel? = null) { private fun getLiveDisplays(editor: Editor): List { val project = editor.project ?: return emptyList() val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return emptyList() - return SourceMarker.getInstance(project).getSourceFileMarker(psiFile) + return SourceMarker.getSourceFileMarker(psiFile) ?.getSourceMarks()?.filterIsInstance()?.mapNotNull { it.configuration.liveTooltip } ?: emptyList() } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/config/SourceMarkConfiguration.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/config/SourceMarkConfiguration.kt index c6af9990b..49755307c 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/config/SourceMarkConfiguration.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/config/SourceMarkConfiguration.kt @@ -18,7 +18,6 @@ package spp.jetbrains.marker.source.mark.api.config import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponentProvider -import spp.jetbrains.marker.source.mark.api.filter.ApplySourceMarkFilter /** * Used to configure [SourceMark]s. @@ -27,7 +26,6 @@ import spp.jetbrains.marker.source.mark.api.filter.ApplySourceMarkFilter * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ interface SourceMarkConfiguration { - var applySourceMarkFilter: ApplySourceMarkFilter var activateOnKeyboardShortcut: Boolean var componentProvider: SourceMarkComponentProvider } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/ApplySourceMarkFilter.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/ApplySourceMarkFilter.kt deleted file mode 100644 index 20448346a..000000000 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/ApplySourceMarkFilter.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spp.jetbrains.marker.source.mark.api.filter - -import spp.jetbrains.marker.source.mark.api.SourceMark -import java.util.function.Predicate - -/** - * Used to filter auto-applied [SourceMark]s. - * - * @since 0.1.0 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -fun interface ApplySourceMarkFilter : Predicate { - companion object { - @JvmStatic - val ALL: ApplySourceMarkFilter = ApplySourceMarkFilter { true } - - @JvmStatic - val NONE: ApplySourceMarkFilter = ApplySourceMarkFilter { false } - } -} diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/CreateSourceMarkFilter.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/CreateSourceMarkFilter.kt deleted file mode 100644 index b5ac6a894..000000000 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/api/filter/CreateSourceMarkFilter.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spp.jetbrains.marker.source.mark.api.filter - -import spp.jetbrains.marker.source.mark.api.SourceMark -import spp.protocol.artifact.ArtifactQualifiedName -import java.util.function.Predicate - -/** - * Used to filter auto-created [SourceMark]s. - * - * @since 0.1.0 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -fun interface CreateSourceMarkFilter : Predicate { - companion object { - @JvmStatic - val ALL: CreateSourceMarkFilter = CreateSourceMarkFilter { true } - - @JvmStatic - val NONE: CreateSourceMarkFilter = CreateSourceMarkFilter { false } - } -} diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/guide/config/GuideMarkConfiguration.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/guide/config/GuideMarkConfiguration.kt index b182a568d..edb6518af 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/guide/config/GuideMarkConfiguration.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/guide/config/GuideMarkConfiguration.kt @@ -20,7 +20,6 @@ import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponentPro import spp.jetbrains.marker.source.mark.api.component.jcef.SourceMarkJcefComponentProvider import spp.jetbrains.marker.source.mark.api.component.tooltip.LiveTooltip import spp.jetbrains.marker.source.mark.api.config.SourceMarkConfiguration -import spp.jetbrains.marker.source.mark.api.filter.ApplySourceMarkFilter import spp.jetbrains.marker.source.mark.guide.GuideMark /** @@ -31,7 +30,6 @@ import spp.jetbrains.marker.source.mark.guide.GuideMark */ data class GuideMarkConfiguration( var liveTooltip: LiveTooltip? = null, - override var applySourceMarkFilter: ApplySourceMarkFilter = ApplySourceMarkFilter.ALL, override var activateOnKeyboardShortcut: Boolean = false, override var componentProvider: SourceMarkComponentProvider = SourceMarkJcefComponentProvider() ) : SourceMarkConfiguration diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/gutter/config/GutterMarkConfiguration.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/gutter/config/GutterMarkConfiguration.kt index 9eb9f5583..2892c9597 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/gutter/config/GutterMarkConfiguration.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/gutter/config/GutterMarkConfiguration.kt @@ -19,7 +19,6 @@ package spp.jetbrains.marker.source.mark.gutter.config import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponentProvider import spp.jetbrains.marker.source.mark.api.component.jcef.SourceMarkJcefComponentProvider import spp.jetbrains.marker.source.mark.api.config.SourceMarkConfiguration -import spp.jetbrains.marker.source.mark.api.filter.ApplySourceMarkFilter import spp.jetbrains.marker.source.mark.gutter.GutterMark import javax.swing.Icon @@ -30,7 +29,6 @@ import javax.swing.Icon * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ data class GutterMarkConfiguration( - override var applySourceMarkFilter: ApplySourceMarkFilter = ApplySourceMarkFilter.ALL, var tooltipText: (() -> String)? = null, var icon: Icon? = null, var activateOnMouseHover: Boolean = true, diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/ExpressionInlayMark.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/ExpressionInlayMark.kt index cc87fe99b..fcc4298b8 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/ExpressionInlayMark.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/ExpressionInlayMark.kt @@ -21,6 +21,7 @@ import spp.jetbrains.marker.SourceMarker import spp.jetbrains.marker.plugin.action.SourceMarkerVisibilityAction import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.api.ExpressionSourceMark +import spp.protocol.artifact.ArtifactType import java.util.* import java.util.concurrent.atomic.AtomicBoolean @@ -39,4 +40,11 @@ class ExpressionInlayMark constructor( override val configuration = SourceMarker.getInstance(project).configuration.inlayMarkConfiguration.copy() override var visible = AtomicBoolean(SourceMarkerVisibilityAction.globalVisibility) var showAboveExpression = false + + init { + //show above element by default for method and class artifacts + if (artifactQualifiedName.type in listOf(ArtifactType.METHOD, ArtifactType.CLASS)) { + showAboveExpression = true + } + } } diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/config/InlayMarkConfiguration.kt b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/config/InlayMarkConfiguration.kt index 1b7d2b738..1fb3f6949 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/config/InlayMarkConfiguration.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/source/mark/inlay/config/InlayMarkConfiguration.kt @@ -21,7 +21,6 @@ import com.intellij.openapi.util.Ref import spp.jetbrains.marker.source.mark.api.component.api.SourceMarkComponentProvider import spp.jetbrains.marker.source.mark.api.component.jcef.SourceMarkJcefComponentProvider import spp.jetbrains.marker.source.mark.api.config.SourceMarkConfiguration -import spp.jetbrains.marker.source.mark.api.filter.ApplySourceMarkFilter import spp.jetbrains.marker.source.mark.inlay.InlayMark /** @@ -31,7 +30,6 @@ import spp.jetbrains.marker.source.mark.inlay.InlayMark * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ data class InlayMarkConfiguration( - override var applySourceMarkFilter: ApplySourceMarkFilter = ApplySourceMarkFilter.NONE, var strictlyManualCreation: Boolean = false, var virtualText: InlayMarkVirtualText? = null, var showComponentInlay: Boolean = false, diff --git a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java index 7a0424036..f6135fc0a 100644 --- a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java +++ b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java @@ -60,7 +60,6 @@ public ControlBar(Editor editor, InlayMark inlayMark, List availabl this.inlayMark = inlayMark; LiveLocationContext context = new LiveLocationContext( - inlayMark.getLineNumber(), inlayMark.getArtifactQualifiedName(), inlayMark.getSourceFileMarker(), inlayMark.getPsiElement() @@ -94,9 +93,9 @@ public ControlBar(Editor editor, InlayMark inlayMark, List availabl textField1.addSaveListener(() -> { String autoCompleteText = textField1.getSelectedText(); if (autoCompleteText != null) { - ControlBarController.INSTANCE.handleCommandInput(autoCompleteText, editor); + ControlBarController.handleCommandInput(autoCompleteText, editor); } else { - ControlBarController.INSTANCE.handleCommandInput(textField1.getText(), editor); + ControlBarController.handleCommandInput(textField1.getText(), editor); } }); } @@ -119,22 +118,16 @@ public void keyPressed(KeyEvent e) { //ignore tab; handled by auto-complete e.consume(); } else if (e.getKeyCode() == KeyEvent.VK_UP && !textField1.isPopupVisible()) { - int lineNumber = inlayMark.getLineNumber(); - while (--lineNumber > 0) { - if (ControlBarController.INSTANCE.canShowControlBar(inlayMark.getSourceFileMarker(), lineNumber)) { - dispose(); - ControlBarController.INSTANCE.showControlBar(editor, lineNumber, true); - break; - } + Integer nextLine = ControlBarController.getNextAvailableControlBarLine(editor, inlayMark, true); + if (nextLine != null) { + dispose(); + ControlBarController.showControlBar(editor, nextLine); } } else if (e.getKeyCode() == KeyEvent.VK_DOWN && !textField1.isPopupVisible()) { - int lineNumber = inlayMark.getLineNumber(); - while (++lineNumber < editor.getDocument().getLineCount()) { - if (ControlBarController.INSTANCE.canShowControlBar(inlayMark.getSourceFileMarker(), lineNumber)) { - dispose(); - ControlBarController.INSTANCE.showControlBar(editor, lineNumber, true); - break; - } + Integer nextLine = ControlBarController.getNextAvailableControlBarLine(editor, inlayMark, false); + if (nextLine != null) { + dispose(); + ControlBarController.showControlBar(editor, nextLine); } } } @@ -147,13 +140,13 @@ public void keyTyped(KeyEvent e) { if (!textField1.getReady()) return; String autoCompleteText = textField1.getSelectedText(); if (autoCompleteText != null) { - ControlBarController.INSTANCE.handleCommandInput(autoCompleteText, textField1.getActualText(), editor); + ControlBarController.handleCommandInput(autoCompleteText, textField1.getActualText(), editor); } else if (!textField1.getText().isEmpty()) { List commands = lookup.apply(textField1.getText()); if (commands.isEmpty()) { - ControlBarController.INSTANCE.handleCommandInput(textField1.getText(), editor); + ControlBarController.handleCommandInput(textField1.getText(), editor); } else { - ControlBarController.INSTANCE.handleCommandInput(commands.get(0).getText(), editor); + ControlBarController.handleCommandInput(commands.get(0).getText(), editor); } } } @@ -222,9 +215,13 @@ private void initComponents() { inlayMark.getLanguage(), inlayMark.getArtifactQualifiedName() ); - textField1 = new AutocompleteField( + location = message("location") + ": " + location; + if (inlayMark.getArtifactQualifiedName().getType().showLineNumber()) { + location += "#" + inlayMark.getLineNumber(); + } + textField1 = new AutocompleteField<>( inlayMark.getProject(), - message("location") + ": " + location + "#" + inlayMark.getLineNumber(), + location, availableCommands, lookup, inlayMark.getArtifactQualifiedName(), true); textField1.setReplaceCommandOnTab(true); textField1.setAutocompleteAndFinishOnEnter(true); diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarAction.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarAction.kt index d9ac23d61..c0de35b43 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarAction.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarAction.kt @@ -20,10 +20,9 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.project.Project -import com.intellij.openapi.util.TextRange /** - * todo: description. + * Shows the Live Command Palette on keyboard shortcut. * * @since 0.3.0 * @author [Brandon Fergerson](mailto:bfergerson@apache.org) @@ -38,15 +37,6 @@ class ControlBarAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { val editor = e.getData(PlatformDataKeys.EDITOR) ?: return val lineNumber = editor.document.getLineNumber(editor.caretModel.offset) - val lineStart = editor.document.getLineStartOffset(lineNumber) - val lineEnd = editor.document.getLineEndOffset(lineNumber) - val text = editor.document.getText(TextRange(lineStart, lineEnd)) - val codeStartsAt = text.length - text.trimStart().length - if (editor.caretModel.offset <= lineStart + codeStartsAt) { - //caret is before the current line's code - ControlBarController.showControlBar(editor, lineNumber) - } else { - ControlBarController.showControlBar(editor, lineNumber + 1) - } + ControlBarController.showControlBar(editor, lineNumber + 1) } } diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarController.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarController.kt index 38fb1fe82..cea27cd0b 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarController.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/ControlBarController.kt @@ -19,15 +19,14 @@ package spp.jetbrains.sourcemarker.command import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.editor.Editor import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.PsiElement import liveplugin.implementation.common.toFilePath -import org.joor.Reflect import spp.jetbrains.ScopeExtensions.safeRunBlocking import spp.jetbrains.command.LiveCommand import spp.jetbrains.command.LiveCommandContext import spp.jetbrains.command.LiveLocationContext import spp.jetbrains.marker.impl.ArtifactCreationService import spp.jetbrains.marker.impl.ArtifactNamingService +import spp.jetbrains.marker.impl.ArtifactScopeService import spp.jetbrains.marker.source.SourceFileMarker import spp.jetbrains.marker.source.mark.api.SourceMark import spp.jetbrains.marker.source.mark.api.component.swing.SwingSourceMarkComponentProvider @@ -56,7 +55,6 @@ object ControlBarController { availableCommandsAtLocation.addAll( LivePluginService.getInstance(inlayMark.project).getRegisteredLiveCommands( LiveLocationContext( - inlayMark.lineNumber, inlayMark.artifactQualifiedName, inlayMark.sourceFileMarker, inlayMark.getPsiElement() @@ -66,10 +64,12 @@ object ControlBarController { return availableCommandsAtLocation.toList() } + @JvmStatic fun handleCommandInput(input: String, editor: Editor) { handleCommandInput(input, input, editor) } + @JvmStatic fun handleCommandInput(input: String, fullText: String, editor: Editor) { log.info("Processing command input: $input") LivePluginService.getInstance(editor.project!!).getRegisteredLiveCommands() @@ -103,7 +103,8 @@ object ControlBarController { /** * Attempts to display live control bar below [lineNumber]. */ - fun showControlBar(editor: Editor, lineNumber: Int, tryingAboveLine: Boolean = false) { + @JvmStatic + fun showControlBar(editor: Editor, lineNumber: Int) { //close previous control bar (if open) previousControlBar?.dispose(true, false) previousControlBar = null @@ -117,14 +118,9 @@ object ControlBarController { } val findInlayMark = ArtifactCreationService.getOrCreateExpressionInlayMark(fileMarker, lineNumber) - if (findInlayMark.isPresent && canShowControlBar(findInlayMark.get().getPsiElement())) { + if (findInlayMark.isPresent && ArtifactScopeService.canShowControlBar(findInlayMark.get().getPsiElement())) { val inlayMark = findInlayMark.get() - if (fileMarker.containsSourceMark(inlayMark)) { - if (!tryingAboveLine) { - //already showing inlay here, try line above - showControlBar(editor, lineNumber - 1, true) - } - } else { + if (!fileMarker.containsSourceMark(inlayMark)) { //create and display control bar previousControlBar = inlayMark @@ -144,27 +140,35 @@ object ControlBarController { controlBar.focus() } - } else if (tryingAboveLine) { - log.warn("No detected expression at line $lineNumber. Inlay mark ignored") - } else { - showControlBar(editor, lineNumber - 1, true) } } - fun canShowControlBar(fileMarker: SourceFileMarker, lineNumber: Int): Boolean { - val expressionInlayMark = ArtifactCreationService.getOrCreateExpressionInlayMark(fileMarker, lineNumber) - return expressionInlayMark.isPresent && canShowControlBar(expressionInlayMark.get().getPsiElement()) + private fun canShowControlBar(fileMarker: SourceFileMarker, lineNumber: Int): InlayMark? { + val inlayMark = ArtifactCreationService.getOrCreateExpressionInlayMark(fileMarker, lineNumber) + return if (inlayMark.isPresent && ArtifactScopeService.canShowControlBar(inlayMark.get().getPsiElement())) { + inlayMark.get() + } else null } - private fun canShowControlBar(psiElement: PsiElement): Boolean { - return when (psiElement::class.java.name) { - "org.jetbrains.kotlin.psi.KtObjectDeclaration" -> false - "org.jetbrains.kotlin.psi.KtProperty" -> { - Reflect.on(psiElement).call("isLocal").get() == true + @JvmStatic + fun getNextAvailableControlBarLine(editor: Editor, inlayMark: InlayMark, moveUp: Boolean): Int? { + var lineNumber = inlayMark.artifactQualifiedName.lineNumber!! + if (moveUp) { + while (--lineNumber > 0) { + val nextMark = canShowControlBar(inlayMark.sourceFileMarker, lineNumber) + if (nextMark != null && nextMark.artifactQualifiedName != inlayMark.artifactQualifiedName) { + return lineNumber + } + } + } else { + while (++lineNumber < editor.document.lineCount) { + val nextMark = canShowControlBar(inlayMark.sourceFileMarker, lineNumber) + if (nextMark != null && nextMark.artifactQualifiedName != inlayMark.artifactQualifiedName) { + return lineNumber + } } - - else -> true } + return null } private fun substringAfterIgnoreCase(str: String, search: String): String { diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt index cbf5fda89..f5749bf87 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/mark/PluginSourceMarkEventListener.kt @@ -87,7 +87,7 @@ class PluginSourceMarkEventListener(val project: Project, val vertx: Vertx) : Sy FileEditorManager.getInstance(project).allEditors.forEach { ApplicationManager.getApplication().runReadAction { PsiManager.getInstance(project).findFile(it.file)?.let { - SourceMarker.getInstance(project).getSourceFileMarker(it) + SourceMarker.getSourceFileMarker(it) DaemonCodeAnalyzer.getInstance(project).restart(it) } } diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/ControlBarCellRenderer.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/ControlBarCellRenderer.kt index 52335d3cb..ae2694cfd 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/ControlBarCellRenderer.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/ControlBarCellRenderer.kt @@ -55,7 +55,6 @@ class ControlBarCellRenderer( row.setCommandIcon(rowValue.getUnselectedIcon()) val context = LiveLocationContext( - autocompleteField.artifactQualifiedName.lineNumber!!, autocompleteField.artifactQualifiedName, inlayMark.sourceFileMarker, inlayMark.getPsiElement() From 9181f3c15b9bacb9183a11e13bae97a6a1ef9bc2 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 9 Oct 2022 17:59:28 +0400 Subject: [PATCH 24/28] refactor: shorten long locations fixes https://github.com/sourceplusplus/sourceplusplus/issues/697 --- .../java/spp/jetbrains/sourcemarker/ControlBar.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java index f6135fc0a..c0756b9c2 100644 --- a/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java +++ b/plugin/src/main/java/spp/jetbrains/sourcemarker/ControlBar.java @@ -215,6 +215,16 @@ private void initComponents() { inlayMark.getLanguage(), inlayMark.getArtifactQualifiedName() ); + + //remove method params if location is too long + if (location.length() > 75 && !location.contains("()")) { + location = location.substring(0, location.indexOf("(")) + "(...)"; + } + //remove class name if location is still too long + if (location.length() > 75 && location.contains(".")) { + location = location.substring(location.indexOf(".") + 1); + } + location = message("location") + ": " + location; if (inlayMark.getArtifactQualifiedName().getType().showLineNumber()) { location += "#" + inlayMark.getLineNumber(); From 67cdb4591fdb7d595df36a31c5c10c22d4e9f936 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 9 Oct 2022 17:59:47 +0400 Subject: [PATCH 25/28] refactor: suggestions --- .../jetbrains/sourcemarker/status/util/AutocompleteField.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/AutocompleteField.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/AutocompleteField.kt index e4278c4df..ef5c03597 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/AutocompleteField.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/util/AutocompleteField.kt @@ -401,14 +401,14 @@ class AutocompleteField( if (text.isEmpty() && placeHolderText != null) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - val textLength = pG.getFontMetrics().stringWidth(placeHolderText) + val textLength = g.fontMetrics.stringWidth(placeHolderText) val fieldLength = width g.color = placeHolderTextColor ?: PluginUI.getPlaceholderForeground() g.drawString( placeHolderText, insets.left + (fieldLength / 2) - (textLength / 2), - pG.getFontMetrics().maxAscent + insets.top + g.fontMetrics.maxAscent + insets.top ) } From cf37b61695dadff7721ced9aaae96e5210799711 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 9 Oct 2022 19:20:15 +0400 Subject: [PATCH 26/28] chore: groovy LCP positioning improves --- .../jvm/service/JVMArtifactCreationService.kt | 9 +++++++++ .../marker/jvm/service/utils/JVMMarkerUtils.kt | 4 ++-- .../spp/jetbrains/marker/SourceMarkerUtils.kt | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt index 7015da9c6..f7df6aa52 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt @@ -19,6 +19,9 @@ package spp.jetbrains.marker.jvm.service import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner import com.intellij.psi.PsiStatement +import com.intellij.psi.impl.source.tree.LeafPsiElement +import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement +import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition import spp.jetbrains.marker.IArtifactCreationService import spp.jetbrains.marker.SourceMarkerUtils import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils @@ -102,6 +105,12 @@ class JVMArtifactCreationService : IArtifactCreationService { autoApply: Boolean ): Optional { val element = SourceMarkerUtils.getElementAtLine(fileMarker.psiFile, lineNumber) + if (element is LeafPsiElement && element.parent is GrImportStatement) { + return Optional.empty() + } else if (element is LeafPsiElement && element.parent is GrPackageDefinition) { + return Optional.empty() + } + return if (element is PsiStatement) { Optional.ofNullable(JVMMarkerUtils.getOrCreateExpressionInlayMark(fileMarker, element, autoApply)) } else if (element is PsiElement) { diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt index da6e66e88..e04aa3139 100755 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt @@ -133,7 +133,7 @@ object JVMMarkerUtils { } return if (inlayMark == null) { - if (element.text != "}") { + if (element.language.id != "Groovy" && element.text != "}") { val uExpression = element.toUElement() if (uExpression !is UExpression && uExpression !is UDeclaration) return null } @@ -404,7 +404,7 @@ object JVMMarkerUtils { } } if (parentIdentifier == null) { - error("Could not determine parent of element: $element") //todo: extension function, see SourceMarkerConfig, make test + error("Could not determine parent of element: $element") //todo: extension function, see SourceMarkerConfig, make test, groovy import statements } element.textRange.startOffset.let { diff --git a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt index 2429d80a0..65ea7a31d 100644 --- a/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt +++ b/marker/src/main/kotlin/spp/jetbrains/marker/SourceMarkerUtils.kt @@ -18,6 +18,9 @@ package spp.jetbrains.marker import com.intellij.openapi.editor.Document import com.intellij.psi.* +import com.intellij.psi.impl.source.tree.LeafPsiElement +import com.intellij.psi.javadoc.PsiDocComment +import com.intellij.psi.javadoc.PsiDocToken import com.intellij.psi.util.parentOfType import spp.jetbrains.marker.source.mark.api.SourceMark @@ -35,7 +38,7 @@ object SourceMarkerUtils { * @since 0.1.0 */ @JvmStatic - fun getElementAtLine(file: PsiFile, line: Int): PsiElement? { + fun getElementAtLine(file: PsiFile, line: Int, ignoreComments: Boolean = true): PsiElement? { val document: Document = PsiDocumentManager.getInstance(file.project).getDocument(file)!! if (document.lineCount == line - 1) { return null @@ -67,11 +70,22 @@ object SourceMarkerUtils { if (element != null && getLineNumber(element) != line) { return null + } else if (element != null && ignoreComments && isComment(element)) { + return null } return element } + private fun isComment(element: PsiElement): Boolean { + val comment = element is PsiDocToken || element is PsiComment || element is PsiDocComment + if (comment) return true + + return if (element is LeafPsiElement) { + isComment(element.parent) + } else false + } + /** * todo: description. * From 7cea2e4e04b823f82423628ab91c99e3790cb69b Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 9 Oct 2022 19:26:39 +0400 Subject: [PATCH 27/28] chore: fix merge --- .../marker/jvm/detect/JVMLoggerDetector.kt | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt index e69de29bb..87080bd35 100644 --- a/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt +++ b/marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetector.kt @@ -0,0 +1,177 @@ +/* + * Source++, the open-source live coding platform. + * Copyright (C) 2022 CodeBrig, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spp.jetbrains.marker.jvm.detect + +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.diagnostic.logger +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Computable +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiRecursiveElementVisitor +import com.intellij.refactoring.suggested.endOffset +import com.intellij.refactoring.suggested.startOffset +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod +import org.jetbrains.uast.UCallExpression +import org.jetbrains.uast.ULiteralExpression +import org.jetbrains.uast.UMethod +import org.jetbrains.uast.toUElementOfType +import org.jetbrains.uast.visitor.AbstractUastVisitor +import spp.jetbrains.marker.source.SourceFileMarker +import spp.jetbrains.marker.source.info.LoggerDetector +import spp.jetbrains.marker.source.info.LoggerDetector.Companion.DETECTED_LOGGER +import spp.jetbrains.marker.source.info.LoggerDetector.DetectedLogger +import spp.jetbrains.marker.source.mark.api.SourceMark +import spp.jetbrains.marker.source.mark.guide.MethodGuideMark + +/** + * Detects the presence of log statements within methods and saves log patterns. + * + * @since 0.2.0 + * @author [Brandon Fergerson](mailto:bfergerson@apache.org) + */ +class JVMLoggerDetector(val project: Project) : LoggerDetector { + + companion object { + private val log = logger() + + private val LOGGER_CLASSES = setOf( + "org.apache.logging.log4j.spi.AbstractLogger", + "ch.qos.logback.classic.Logger", + "org.slf4j.Logger" + ) + private val LOGGER_METHODS = setOf( + "trace", "debug", "info", "warn", "error" + ) + } + + override fun determineLoggerStatements(guideMark: MethodGuideMark): List { + if (guideMark.language.id == "Groovy") { + determineLoggerStatements(guideMark.getPsiMethod() as GrMethod, guideMark.sourceFileMarker) + } else { + val uMethod = ApplicationManager.getApplication().runReadAction(Computable { + guideMark.getPsiMethod().toUElementOfType() + }) + if (uMethod != null) { + determineLoggerStatements(uMethod, guideMark.sourceFileMarker) + } + } + return guideMark.getChildren().mapNotNull { it.getUserData(DETECTED_LOGGER) } + } + + fun determineLoggerStatements(uMethod: UMethod, fileMarker: SourceFileMarker): List { + val loggerStatements = mutableListOf() + ApplicationManager.getApplication().runReadAction { + uMethod.accept(object : AbstractUastVisitor() { + override fun visitCallExpression(node: UCallExpression): Boolean { + val expression = node.sourcePsi ?: return super.visitCallExpression(node) + val loggerClass = node.resolve()?.containingClass?.qualifiedName + if (loggerClass != null && LOGGER_CLASSES.contains(loggerClass)) { + val methodName = node.methodIdentifier?.name + if (methodName != null && LOGGER_METHODS.contains(methodName)) { + val logTemplate = node.valueArguments.firstOrNull()?.run { + (this as? ULiteralExpression)?.value as? String + } + + if (logTemplate != null) { + log.debug("Found log statement: $logTemplate") + val detectedLogger = DetectedLogger( + logTemplate, methodName, getLineNumber(expression) + 1 + ) + loggerStatements.add(detectedLogger) + + //create expression guide mark for the log statement + val guideMark = fileMarker.createExpressionSourceMark( + expression.parent, SourceMark.Type.GUIDE + ) + if (!fileMarker.containsSourceMark(guideMark)) { + guideMark.putUserData(DETECTED_LOGGER, detectedLogger) + guideMark.apply(true) + } else { + fileMarker.getSourceMark(guideMark.artifactQualifiedName, SourceMark.Type.GUIDE) + ?.putUserData(DETECTED_LOGGER, detectedLogger) + } + } else { + log.warn("No log template argument available for expression: $expression") + } + } + } + return super.visitCallExpression(node) + } + }) + } + return loggerStatements + } + + /** + * Unsure why, but Groovy UAST visitors don't work here. Have to use Groovy PSI. + */ + fun determineLoggerStatements(grMethod: GrMethod, fileMarker: SourceFileMarker): List { + val loggerStatements = mutableListOf() + ApplicationManager.getApplication().runReadAction { + grMethod.acceptChildren(object : PsiRecursiveElementVisitor() { + override fun visitElement(element: PsiElement) { + if (element is GrMethodCallExpression) { + val loggerClass = element.resolveMethod()?.containingClass?.qualifiedName + if (loggerClass != null && LOGGER_CLASSES.contains(loggerClass)) { + val methodName = element.resolveMethod()?.name + if (methodName != null && LOGGER_METHODS.contains(methodName)) { + val logTemplate = element.argumentList.expressionArguments.firstOrNull()?.run { + (this as? GrLiteral)?.value as? String + } + + if (logTemplate != null) { + log.debug("Found log statement: $logTemplate") + val detectedLogger = DetectedLogger( + logTemplate, methodName, getLineNumber(element) + 1 + ) + loggerStatements.add(detectedLogger) + + //create expression guide mark for the log statement + val guideMark = fileMarker.createExpressionSourceMark( + element, SourceMark.Type.GUIDE + ) + if (!fileMarker.containsSourceMark(guideMark)) { + guideMark.putUserData(DETECTED_LOGGER, detectedLogger) + guideMark.apply(true) + } else { + fileMarker.getSourceMark(guideMark.artifactQualifiedName, SourceMark.Type.GUIDE) + ?.putUserData(DETECTED_LOGGER, detectedLogger) + } + } else { + log.warn("No log template argument available for expression: $element") + } + } + } + } + super.visitElement(element) + } + }) + } + return loggerStatements + } + + private fun getLineNumber(element: PsiElement, start: Boolean = true): Int { + val document = element.containingFile.viewProvider.document + ?: PsiDocumentManager.getInstance(element.project).getDocument(element.containingFile) + val index = if (start) element.startOffset else element.endOffset + if (index > (document?.textLength ?: 0)) return 0 + return document?.getLineNumber(index) ?: 0 + } +} From f664db970d5c325ea4cf2c533b29e963b9bf908f Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 9 Oct 2022 19:27:29 +0400 Subject: [PATCH 28/28] chore: fix merge --- .../jvm/detect/JVMLoggerDetectorTest.kt | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt index 91aecbd4b..d9c1ca7b3 100644 --- a/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt +++ b/marker/jvm-marker/src/test/kotlin/spp/jetbrains/marker/jvm/detect/JVMLoggerDetectorTest.kt @@ -230,40 +230,4 @@ class JVMLoggerDetectorTest : LightJavaCodeInsightFixtureTestCase() { assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") } } - - fun testKotlinLogbackLogger() { - @Language("kotlin") val code = """ - import ch.qos.logback.classic.Logger - class TestLogback { - val log: Logger = Logger() - fun loggers() { - log.trace("trace {}", "trace") - log.debug("debug {}", "debug") - log.info("info {}", "info") - log.warn("warn {}", "warn") - log.error("error {}", "error") - } - } - """.trimIndent() - - ApplicationManager.getApplication().runReadAction { - val sourceFile = myFixture.createFile("TestLogback.kt", code).toPsiFile(project) - assertNotNull(sourceFile) - - val uFile = sourceFile.toUElement() as UFile - assertEquals(1, uFile.classes.size) - assertEquals(3, uFile.classes[0].methods.size) - - JVMMarker.setup() - SourceFileMarker.SUPPORTED_FILE_TYPES.add(KtFile::class.java) - val fileMarker = SourceMarker.getSourceFileMarker(sourceFile!!) - assertNotNull(fileMarker) - - val result = JVMLoggerDetector(project.apply { UserData.vertx(this, Vertx.vertx()) }) - .determineLoggerStatements(uFile.classes[0].methods[1], fileMarker!!) - .map { it.logPattern } - assertEquals(5, result.size) - assertContainsOrdered(result, "trace {}", "debug {}", "info {}", "warn {}", "error {}") - } - } }