KT-32368 Rework Inline hints settings // compatibility with earlier IDEA versions
This commit is contained in:
@@ -25,7 +25,6 @@ import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||
import com.intellij.testFramework.ExtensionTestUtil
|
||||
import com.intellij.testFramework.runInEdtAndWait
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.hints.HintType
|
||||
import org.jetbrains.kotlin.idea.perf.util.logMessage
|
||||
import org.jetbrains.kotlin.idea.test.runPostStartupActivitiesOnce
|
||||
import java.nio.file.Paths
|
||||
@@ -61,9 +60,6 @@ fun saveDocument(document: Document) {
|
||||
}
|
||||
}
|
||||
|
||||
fun enableHints(enable: Boolean) =
|
||||
HintType.values().forEach { it.option.set(enable) }
|
||||
|
||||
fun dispatchAllInvocationEvents() {
|
||||
runInEdtAndWait {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
|
||||
-5
@@ -27,9 +27,7 @@ import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||
import com.intellij.testFramework.ExtensionTestUtil
|
||||
import com.intellij.testFramework.runInEdtAndWait
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
||||
import org.jetbrains.kotlin.idea.perf.util.logMessage
|
||||
import org.jetbrains.kotlin.idea.test.runPostStartupActivitiesOnce
|
||||
import java.nio.file.Paths
|
||||
|
||||
fun commitAllDocuments() {
|
||||
@@ -63,9 +61,6 @@ fun saveDocument(document: Document) {
|
||||
}
|
||||
}
|
||||
|
||||
fun enableHints(enable: Boolean) =
|
||||
HintType.values().forEach { it.option.set(enable) }
|
||||
|
||||
fun dispatchAllInvocationEvents() {
|
||||
runInEdtAndWait {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.ChangeListener
|
||||
import com.intellij.codeInsight.hints.ImmediateConfigurable
|
||||
import com.intellij.codeInsight.hints.settings.InlayHintsConfigurable
|
||||
import com.intellij.ui.layout.panel
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import javax.swing.JComponent
|
||||
|
||||
|
||||
typealias CompatibleInlayHintsConfigurable = InlayHintsConfigurable
|
||||
|
||||
fun createLambdaHintsImmediateConfigurable(settings: KotlinLambdasHintsProvider.Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
override fun createComponent(listener: ChangeListener): JComponent = panel {}
|
||||
|
||||
override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items")
|
||||
|
||||
override val cases: List<ImmediateConfigurable.Case>
|
||||
get() = listOf(
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.lambda.return"),
|
||||
"hints.lambda.return",
|
||||
settings::returnExpressions
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.lambda.receivers.parameters"),
|
||||
"hints.lambda.receivers.parameters",
|
||||
settings::implicitReceiversAndParams
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun createTypeHintsImmediateConfigurable(settings: KotlinReferencesTypeHintsProvider.Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
override fun createComponent(listener: ChangeListener): JComponent = panel {}
|
||||
|
||||
override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items")
|
||||
|
||||
override val cases: List<ImmediateConfigurable.Case>
|
||||
get() = listOf(
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.property"),
|
||||
"hints.type.property",
|
||||
settings::propertyType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.variable"),
|
||||
"hints.type.variable",
|
||||
settings::localVariableType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.return"),
|
||||
"hints.type.function.return",
|
||||
settings::functionReturnType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.parameter"),
|
||||
"hints.type.function.parameter",
|
||||
settings::parameterType
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.ChangeListener
|
||||
import com.intellij.codeInsight.hints.ImmediateConfigurable
|
||||
import com.intellij.codeInsight.hints.config.InlayHintsConfigurable
|
||||
import com.intellij.ui.components.JBCheckBox
|
||||
import com.intellij.ui.layout.panel
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import javax.swing.JComponent
|
||||
|
||||
|
||||
typealias CompatibleInlayHintsConfigurable = InlayHintsConfigurable
|
||||
|
||||
fun createLambdaHintsImmediateConfigurable(settings: KotlinLambdasHintsProvider.Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
|
||||
private val returnExprField = JBCheckBox(KotlinBundle.message("hints.settings.lambda.return"), settings.returnExpressions)
|
||||
|
||||
private val receiversAndParamsField = JBCheckBox(
|
||||
KotlinBundle.message("hints.settings.lambda.receivers.parameters"),
|
||||
settings.implicitReceiversAndParams
|
||||
)
|
||||
|
||||
override fun createComponent(listener: ChangeListener): JComponent {
|
||||
returnExprField.isSelected = settings.returnExpressions
|
||||
returnExprField.addActionListener { settings.returnExpressions = returnExprField.isSelected }
|
||||
|
||||
receiversAndParamsField.isSelected = settings.implicitReceiversAndParams
|
||||
receiversAndParamsField.addActionListener { settings.implicitReceiversAndParams = receiversAndParamsField.isSelected }
|
||||
|
||||
return panel {
|
||||
row { returnExprField(pushX) }
|
||||
row { receiversAndParamsField(pushX) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createTypeHintsImmediateConfigurable(settings: KotlinReferencesTypeHintsProvider.Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
|
||||
private val propertyTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.property"), settings.propertyType)
|
||||
private val variableTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.variable"), settings.localVariableType)
|
||||
private val funReturnTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.return"), settings.functionReturnType)
|
||||
private val paramTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.parameter"), settings.parameterType)
|
||||
|
||||
override fun createComponent(listener: ChangeListener): JComponent {
|
||||
propertyTypeField.isSelected = settings.propertyType
|
||||
propertyTypeField.addActionListener { settings.propertyType = propertyTypeField.isSelected }
|
||||
|
||||
variableTypeField.isSelected = settings.localVariableType
|
||||
variableTypeField.addActionListener { settings.localVariableType = variableTypeField.isSelected }
|
||||
|
||||
funReturnTypeField.isSelected = settings.functionReturnType
|
||||
funReturnTypeField.addActionListener { settings.functionReturnType = funReturnTypeField.isSelected }
|
||||
|
||||
paramTypeField.isSelected = settings.parameterType
|
||||
paramTypeField.addActionListener { settings.parameterType = paramTypeField.isSelected }
|
||||
|
||||
return panel {
|
||||
row { propertyTypeField(pushX) }
|
||||
row { variableTypeField(pushX) }
|
||||
row { funReturnTypeField(pushX) }
|
||||
row { paramTypeField(pushX) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.ChangeListener
|
||||
import com.intellij.codeInsight.hints.ImmediateConfigurable
|
||||
import com.intellij.codeInsight.hints.InlayHintsSink
|
||||
import com.intellij.codeInsight.hints.presentation.PresentationRenderer
|
||||
import com.intellij.openapi.application.TransactionGuard
|
||||
import com.intellij.openapi.application.invokeLater
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.ui.layout.panel
|
||||
import com.sun.glass.ui.Application
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import javax.swing.JComponent
|
||||
import org.jetbrains.kotlin.idea.util.application.invokeLater
|
||||
|
||||
/**
|
||||
* Please note that the executable test class is currently not generated. The thing is that [KotlinLambdasHintsProvider] utilizes a hack
|
||||
@@ -61,25 +56,7 @@ class KotlinLambdasHintsProvider : KotlinAbstractHintsProvider<KotlinLambdasHint
|
||||
}
|
||||
|
||||
override fun createConfigurable(settings: Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
override fun createComponent(listener: ChangeListener): JComponent = panel {}
|
||||
|
||||
override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items")
|
||||
|
||||
override val cases: List<ImmediateConfigurable.Case>
|
||||
get() = listOf(
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.lambda.return"),
|
||||
"hints.lambda.return",
|
||||
settings::returnExpressions
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.lambda.receivers.parameters"),
|
||||
"hints.lambda.receivers.parameters",
|
||||
settings::implicitReceiversAndParams
|
||||
)
|
||||
)
|
||||
}
|
||||
return createLambdaHintsImmediateConfigurable(settings)
|
||||
}
|
||||
|
||||
override fun createSettings(): Settings = Settings()
|
||||
|
||||
+2
-29
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.ChangeListener
|
||||
import com.intellij.codeInsight.hints.ImmediateConfigurable
|
||||
import com.intellij.ui.components.JBCheckBox
|
||||
import com.intellij.ui.layout.panel
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import javax.swing.JComponent
|
||||
@@ -24,35 +25,7 @@ class KotlinReferencesTypeHintsProvider : KotlinAbstractHintsProvider<KotlinRefe
|
||||
override val name: String = KotlinBundle.message("hints.settings.types")
|
||||
|
||||
override fun createConfigurable(settings: Settings): ImmediateConfigurable {
|
||||
return object : ImmediateConfigurable {
|
||||
override fun createComponent(listener: ChangeListener): JComponent = panel {}
|
||||
|
||||
override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items")
|
||||
|
||||
override val cases: List<ImmediateConfigurable.Case>
|
||||
get() = listOf(
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.property"),
|
||||
"hints.type.property",
|
||||
settings::propertyType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.variable"),
|
||||
"hints.type.variable",
|
||||
settings::localVariableType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.return"),
|
||||
"hints.type.function.return",
|
||||
settings::functionReturnType
|
||||
),
|
||||
ImmediateConfigurable.Case(
|
||||
KotlinBundle.message("hints.settings.types.parameter"),
|
||||
"hints.type.function.parameter",
|
||||
settings::parameterType
|
||||
),
|
||||
)
|
||||
}
|
||||
return createTypeHintsImmediateConfigurable(settings)
|
||||
}
|
||||
|
||||
override fun createSettings(): Settings = Settings()
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.settings.InlayHintsConfigurable
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
@@ -14,7 +13,7 @@ class ShowInlayHintsSettings : AnAction("Hints Settings...") {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val file = CommonDataKeys.PSI_FILE.getData(e.dataContext) ?: return
|
||||
val fileLanguage = file.language
|
||||
InlayHintsConfigurable.showSettingsDialogForLanguage(
|
||||
CompatibleInlayHintsConfigurable.showSettingsDialogForLanguage(
|
||||
file.project,
|
||||
fileLanguage
|
||||
)
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* 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.codeInsight.hints
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* 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.codeInsight.hints
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* 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.codeInsight.hints;
|
||||
Reference in New Issue
Block a user