From 142ab96a5a3e0f2f06eb91e70556cd9f35effbab Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 31 Aug 2015 17:59:31 +0300 Subject: [PATCH] Run/Debug editor gutter drop down does not work in Kotlin files (KT-8720) #KT-8720 Fixed --- .../MainFunctionGutterVisitor.kt | 43 ---------------- .../kotlin/idea/highlighter/JetPsiChecker.kt | 5 +- idea/src/META-INF/plugin.xml | 1 + .../KotlinRunLineMarkerProvider.kt | 51 +++++++++++++++++++ 4 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/MainFunctionGutterVisitor.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerProvider.kt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/MainFunctionGutterVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/MainFunctionGutterVisitor.kt deleted file mode 100644 index a1585ccb032..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/MainFunctionGutterVisitor.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * 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 org.jetbrains.kotlin.idea.configuration - -import com.intellij.lang.annotation.AnnotationHolder -import com.intellij.openapi.editor.markup.GutterIconRenderer -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.idea.JetIcons -import org.jetbrains.kotlin.idea.MainFunctionDetector -import org.jetbrains.kotlin.psi.JetNamedFunction -import org.jetbrains.kotlin.psi.JetVisitorVoid -import org.jetbrains.kotlin.resolve.BindingContext -import javax.swing.Icon - -class MainFunctionGutterVisitor(val holder: AnnotationHolder, val bindingContext: BindingContext) : JetVisitorVoid() { - override fun visitNamedFunction(function: JetNamedFunction) { - if (MainFunctionDetector(bindingContext).isMain(function)) { - function.nameIdentifier?.let { nameIdentifier -> - holder.createInfoAnnotation(nameIdentifier, "Run configuration from here").gutterIconRenderer = MainGutterIconRenderer(nameIdentifier) - } - } - } -} - -class MainGutterIconRenderer(val nameIdentifier: PsiElement) : GutterIconRenderer() { - override fun getIcon(): Icon = JetIcons.LAUNCH - override fun hashCode(): Int = nameIdentifier.hashCode() - override fun equals(other: Any?): Boolean = other is MainGutterIconRenderer && other.nameIdentifier == nameIdentifier -} \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/JetPsiChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/JetPsiChecker.kt index a5e2920a947..43c6332c626 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/JetPsiChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/JetPsiChecker.kt @@ -39,8 +39,6 @@ import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult -import org.jetbrains.kotlin.idea.configuration.MainFunctionGutterVisitor -import org.jetbrains.kotlin.idea.kdoc.KDocHighlightingVisitor import org.jetbrains.kotlin.idea.quickfix.QuickFixes import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.util.ProjectRootsUtil @@ -240,9 +238,8 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension { PropertiesHighlightingVisitor(holder, bindingContext), FunctionsHighlightingVisitor(holder, bindingContext), VariablesHighlightingVisitor(holder, bindingContext), - TypeKindHighlightingVisitor(holder, bindingContext), + TypeKindHighlightingVisitor(holder, bindingContext) //DeprecatedAnnotationVisitor(holder, bindingContext) - MainFunctionGutterVisitor(holder, bindingContext) ) public fun createQuickfixes(diagnostic: Diagnostic): Collection { diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 55bb0227038..227bda213c4 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -405,6 +405,7 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerProvider.kt new file mode 100644 index 00000000000..f4f9f70f2ea --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRunLineMarkerProvider.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * 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 org.jetbrains.kotlin.idea.highlighter + +import com.intellij.codeInsight.daemon.LineMarkerInfo +import com.intellij.codeInsight.daemon.LineMarkerProvider +import com.intellij.execution.lineMarker.RunLineMarkerInfo +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.JetIcons +import org.jetbrains.kotlin.idea.MainFunctionDetector +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor +import org.jetbrains.kotlin.psi.JetNamedFunction + + +public class KotlinRunLineMarkerProvider : LineMarkerProvider { + override fun getLineMarkerInfo(e: PsiElement): LineMarkerInfo? { + val function = e.parent as? JetNamedFunction + if (function == null) return null + + if (function.nameIdentifier != e) return null + + val detector = MainFunctionDetector { function -> + function.resolveToDescriptor() as FunctionDescriptor + } + + if (detector.isMain(function)) { + return RunLineMarkerInfo(function, JetIcons.LAUNCH, null) + } + + return null + + } + + override fun collectSlowLineMarkers(elements: List, result: MutableCollection>) { + } +} \ No newline at end of file