From 12489ef1b465525df96d724b21a1fb03fdfa20d7 Mon Sep 17 00:00:00 2001 From: Kirill Shmakov Date: Mon, 14 Sep 2020 16:58:23 +0300 Subject: [PATCH] Show run test gutters only when appropriate This is to fix KT-36370 --- .../KotlinTestRunLineMarkerContributor.kt | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt index 9ec22ed0011..b13f70910c7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.highlighter @@ -30,7 +19,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.platform.tooling import org.jetbrains.kotlin.idea.project.platform import org.jetbrains.kotlin.idea.util.projectStructure.module +import org.jetbrains.kotlin.konan.target.HostManager +import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.platform.SimplePlatform +import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.idePlatformKind +import org.jetbrains.kotlin.platform.konan.NativePlatformWithTarget import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.psi.KtNamedFunction @@ -53,6 +47,26 @@ class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() { else -> defaultIcon } } + + fun SimplePlatform.providesRunnableTests(): Boolean { + if (this is NativePlatformWithTarget) { + return when { + HostManager.hostIsMac -> target in listOf( + KonanTarget.IOS_X64, + KonanTarget.MACOS_X64, + KonanTarget.WATCHOS_X64, + KonanTarget.TVOS_X64 + ) + HostManager.hostIsLinux -> target == KonanTarget.LINUX_X64 + HostManager.hostIsMingw -> target in listOf(KonanTarget.MINGW_X86, KonanTarget.MINGW_X64) + else -> false + } + } + + return true + } + + fun TargetPlatform.providesRunnableTests(): Boolean = componentPlatforms.any { it.providesRunnableTests() } } override fun getInfo(element: PsiElement): Info? { @@ -67,6 +81,7 @@ class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() { val descriptor = declaration.resolveToDescriptorIfAny() ?: return null val targetPlatform = declaration.module?.platform ?: return null + if (!targetPlatform.providesRunnableTests()) return null val icon = targetPlatform.idePlatformKind.tooling.getTestIcon(declaration, descriptor) ?: return null return Info(icon, Function { KotlinBundle.message("highlighter.tool.tip.text.run.test") }, *ExecutorAction.getActions()) }