mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[parameter hints] support for language customizable options
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil
|
||||
import com.intellij.psi.impl.source.tree.java.PsiMethodCallExpressionImpl
|
||||
@@ -67,7 +66,8 @@ object JavaInlayHintsProvider {
|
||||
with(resultSet) {
|
||||
getVarArgInlay(info)?.let { add(it) }
|
||||
|
||||
if (ParameterNameHintsSettings.getInstance().isShowForParamsWithSameType) {
|
||||
val hintsProvider = JavaInlayParameterHintsProvider.getInstance()
|
||||
if (hintsProvider.isShowForParamsWithSameType.get()) {
|
||||
addAll(createSameTypeInlays(args))
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ object JavaInlayHintsProvider {
|
||||
if (params.isEmpty()) return false
|
||||
if (params.size == 1) {
|
||||
if (isBuilderLike(callExpression, method) || isSetterNamed(method)) return false
|
||||
if (ParameterNameHintsSettings.getInstance().isDoNotShowIfMethodNameContainsParameterName
|
||||
val hintsProvider = JavaInlayParameterHintsProvider.getInstance()
|
||||
if (hintsProvider.isDoNotShowIfMethodNameContainsParameterName.get()
|
||||
&& isParamNameContainedInMethodName(params[0], method)) return false
|
||||
}
|
||||
return true
|
||||
|
||||
+20
-1
@@ -15,13 +15,18 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.hints
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiCallExpression
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
|
||||
class JavaInlayParameterHintsProvider : InlayParameterHintsProvider {
|
||||
|
||||
|
||||
companion object {
|
||||
fun getInstance() = InlayParameterHintsExtension.forLanguage(JavaLanguage.INSTANCE) as JavaInlayParameterHintsProvider
|
||||
}
|
||||
|
||||
override fun getMethodInfo(element: PsiElement): MethodInfo? {
|
||||
if (element is PsiCallExpression) {
|
||||
val resolvedElement = element.resolveMethodGenerics().element
|
||||
@@ -82,4 +87,18 @@ class JavaInlayParameterHintsProvider : InlayParameterHintsProvider {
|
||||
"org.slf4j.Logger.*"
|
||||
)
|
||||
|
||||
val isDoNotShowIfMethodNameContainsParameterName = Option("java.method.name.contains.parameter.name",
|
||||
"Do not show if method name contains parameter name",
|
||||
true)
|
||||
|
||||
val isShowForParamsWithSameType = Option("java.multiple.params.same.type",
|
||||
"Show for non-literals in case of multiple params with the same type",
|
||||
false)
|
||||
|
||||
override fun getSupportedOptions(): List<Option> {
|
||||
return listOf(
|
||||
isDoNotShowIfMethodNameContainsParameterName,
|
||||
isShowForParamsWithSameType
|
||||
)
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.inlays
|
||||
|
||||
import com.intellij.codeInsight.hints.JavaInlayParameterHintsProvider
|
||||
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
@@ -601,7 +602,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun `test do not show hint for name contained in method`() {
|
||||
ParameterNameHintsSettings.getInstance().isDoNotShowIfMethodNameContainsParameterName = true
|
||||
JavaInlayParameterHintsProvider.getInstance().isDoNotShowIfMethodNameContainsParameterName.set(true)
|
||||
check("""
|
||||
class Test {
|
||||
void main() {
|
||||
@@ -615,7 +616,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun `test show if multiple params but name contained`() {
|
||||
ParameterNameHintsSettings.getInstance().isDoNotShowIfMethodNameContainsParameterName = true
|
||||
JavaInlayParameterHintsProvider.getInstance().isDoNotShowIfMethodNameContainsParameterName.set(true)
|
||||
check("""
|
||||
class Test {
|
||||
void main() {
|
||||
@@ -629,7 +630,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun `test show same params`() {
|
||||
ParameterNameHintsSettings.getInstance().isShowForParamsWithSameType = true
|
||||
JavaInlayParameterHintsProvider.getInstance().isShowForParamsWithSameType.set(true)
|
||||
check("""
|
||||
class Test {
|
||||
void main() {
|
||||
@@ -644,7 +645,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun `test show triple`() {
|
||||
ParameterNameHintsSettings.getInstance().isShowForParamsWithSameType = true
|
||||
JavaInlayParameterHintsProvider.getInstance().isShowForParamsWithSameType.set(true)
|
||||
check("""
|
||||
class Test {
|
||||
void main() {
|
||||
@@ -658,7 +659,7 @@ class Test {
|
||||
}
|
||||
|
||||
fun `test show couple of doubles`() {
|
||||
ParameterNameHintsSettings.getInstance().isShowForParamsWithSameType = true
|
||||
JavaInlayParameterHintsProvider.getInstance().isShowForParamsWithSameType.set(true)
|
||||
check("""
|
||||
class Test {
|
||||
void main() {
|
||||
|
||||
+28
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.hints
|
||||
|
||||
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.lang.LanguageExtension
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -46,6 +47,32 @@ interface InlayParameterHintsProvider {
|
||||
* E.g. to prevent possible Groovy and Kotlin extensions from showing hints for blacklisted java methods.
|
||||
*/
|
||||
fun getBlackListDependencyLanguage(): Language? = null
|
||||
|
||||
|
||||
/**
|
||||
* List of supported options, shown in settings dialog
|
||||
*/
|
||||
fun getSupportedOptions(): List<Option> = emptyList()
|
||||
|
||||
}
|
||||
|
||||
|
||||
data class Option(val id: String,
|
||||
val name: String,
|
||||
val defaultValue: Boolean) {
|
||||
|
||||
fun get(): Boolean {
|
||||
return ParameterNameHintsSettings.getInstance().getOption(id) ?: defaultValue
|
||||
}
|
||||
|
||||
fun set(newValue: Boolean) {
|
||||
val settings = ParameterNameHintsSettings.getInstance()
|
||||
if (newValue == defaultValue) {
|
||||
settings.setOption(id, null)
|
||||
}
|
||||
else {
|
||||
settings.setOption(id, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+32
-35
@@ -16,10 +16,7 @@
|
||||
package com.intellij.codeInsight.hints.settings
|
||||
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.components.*
|
||||
import org.jdom.Element
|
||||
|
||||
|
||||
@@ -30,8 +27,6 @@ private object XmlTagHelper {
|
||||
val ADDED = "added"
|
||||
val REMOVED = "removed"
|
||||
val PATTERN = "pattern"
|
||||
val DO_NOT_SHOW_IF_PARAM_NAME_CONTAINED_IN_METHOD_NAME = "showIfParamNameContained"
|
||||
val SHOW_WHEN_MULTIPLE_PARAMS_WITH_SAME_TYPE = "showWhenMultipleParamsWithSameType"
|
||||
}
|
||||
|
||||
|
||||
@@ -63,10 +58,8 @@ class Diff(val added: Set<String>, val removed: Set<String>) {
|
||||
class ParameterNameHintsSettings : PersistentStateComponent<Element> {
|
||||
private val myRemovedPatterns = hashMapOf<String, Set<String>>()
|
||||
private val myAddedPatterns = hashMapOf<String, Set<String>>()
|
||||
|
||||
var isDoNotShowIfMethodNameContainsParameterName: Boolean = true
|
||||
var isShowForParamsWithSameType: Boolean = false
|
||||
|
||||
private val myOptions = hashMapOf<String, Boolean>()
|
||||
|
||||
fun addIgnorePattern(language: Language, pattern: String) {
|
||||
val patternsBefore = getAddedPatterns(language)
|
||||
setAddedPatterns(language, patternsBefore + pattern)
|
||||
@@ -98,27 +91,22 @@ class ParameterNameHintsSettings : PersistentStateComponent<Element> {
|
||||
blacklists.addLanguagePatternElements(language, patterns, XmlTagHelper.ADDED)
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDoNotShowIfMethodNameContainsParameterName) {
|
||||
root.getOrCreateChild(XmlTagHelper.DO_NOT_SHOW_IF_PARAM_NAME_CONTAINED_IN_METHOD_NAME)
|
||||
.setAttribute("value", isDoNotShowIfMethodNameContainsParameterName.toString())
|
||||
|
||||
myOptions.forEach { id, value ->
|
||||
val element = Element("option")
|
||||
element.setAttribute("id", id)
|
||||
element.setAttribute("value", value.toString())
|
||||
root.addContent(element)
|
||||
}
|
||||
|
||||
if (isShowForParamsWithSameType) {
|
||||
root.getOrCreateChild(XmlTagHelper.SHOW_WHEN_MULTIPLE_PARAMS_WITH_SAME_TYPE)
|
||||
.setAttribute("value", isShowForParamsWithSameType.toString())
|
||||
}
|
||||
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
override fun loadState(state: Element) {
|
||||
myAddedPatterns.clear()
|
||||
myRemovedPatterns.clear()
|
||||
|
||||
isDoNotShowIfMethodNameContainsParameterName = true
|
||||
isShowForParamsWithSameType = false
|
||||
|
||||
myOptions.clear()
|
||||
|
||||
val allBlackLists = state
|
||||
.getChild(XmlTagHelper.BLACKLISTS)
|
||||
?.getChildren(XmlTagHelper.LANGUAGE_LIST) ?: emptyList()
|
||||
@@ -128,21 +116,30 @@ class ParameterNameHintsSettings : PersistentStateComponent<Element> {
|
||||
myAddedPatterns[language] = blacklist.extractPatterns(XmlTagHelper.ADDED)
|
||||
myRemovedPatterns[language] = blacklist.extractPatterns(XmlTagHelper.REMOVED)
|
||||
}
|
||||
|
||||
isDoNotShowIfMethodNameContainsParameterName = state
|
||||
.getBooleanValue(XmlTagHelper.DO_NOT_SHOW_IF_PARAM_NAME_CONTAINED_IN_METHOD_NAME, true)
|
||||
|
||||
isShowForParamsWithSameType = state
|
||||
.getBooleanValue(XmlTagHelper.SHOW_WHEN_MULTIPLE_PARAMS_WITH_SAME_TYPE, false)
|
||||
}
|
||||
|
||||
private fun Element.getBooleanValue(childName: String, defaultValue: Boolean): Boolean {
|
||||
return getChild(childName)?.getAttributeValue("value")?.toBoolean() ?: defaultValue
|
||||
|
||||
state.getChildren("option").forEach {
|
||||
val id = it.getAttributeValue("id")
|
||||
val value = it.getAttributeValue("value").toBoolean()
|
||||
myOptions[id] = value
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance() = service<ParameterNameHintsSettings>()
|
||||
fun getInstance(): ParameterNameHintsSettings = ServiceManager.getService(ParameterNameHintsSettings::class.java)
|
||||
}
|
||||
|
||||
fun getOption(optionId: String): Boolean? {
|
||||
return myOptions[optionId]
|
||||
}
|
||||
|
||||
fun setOption(optionId: String, value: Boolean?) {
|
||||
if (value == null) {
|
||||
myOptions.remove(optionId)
|
||||
}
|
||||
else {
|
||||
myOptions[optionId] = value
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAddedPatterns(language: Language): Set<String> {
|
||||
+24
-61
@@ -1,25 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInsight.hints.settings.ParameterNameHintsConfigurable">
|
||||
<grid id="27dc6" binding="myConfigurable" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<grid id="27dc6" binding="myConfigurable" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="2069" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="24a8f" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="24a8f" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<constraints border-constraint="Center"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="e5aa7" binding="myBlacklistPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="e5aa7" binding="myBlacklistPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -32,44 +29,24 @@
|
||||
<text value="<html> No in-line parameter name hints will be shown for methods matching any of these patterns.<br> Patterns are matched on fully qualified method name, parameter count and parameter names. <ul> <li><code>java.lang</code> matches all methods from <em>java.lang</em> package</li> <li><code>java.lang.*(*, *)</code> matches all methods from the <em>java.lang</em> package with two parameters</li> <li><code>(*info)</code> matches all single parameter methods where the parameter name ends with <em>info</em></li> <li><code>(key, value)</code> matches all methods with parameters <em>key</em> and <em>value</em></li> <li><code>*.put(key, value)</code> matches all <em>put</em> methods with <em>key</em> and <em>value</em> parameters </ul> </html>"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="8ca84" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="5eb47">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="6747b" class="com.intellij.openapi.ui.ComboBox" binding="myCurrentLanguageCombo" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="4be87" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Language:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="8ecb1" class="com.intellij.ui.EditorTextField" binding="myEditorTextField" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ea5b3" binding="myOptionsPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="ea5b3" binding="myOptionsPanel" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="8ca84" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -77,38 +54,24 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="fe87e">
|
||||
<hspacer id="5eb47">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="443be" class="com.intellij.ui.components.JBLabel">
|
||||
<component id="6747b" class="com.intellij.openapi.ui.ComboBox" binding="myCurrentLanguageCombo" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Show for non-literals in case of multiple params with the same type"/>
|
||||
</properties>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="a19f3" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Do not show if method name contains parameter name"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="359bc" class="com.intellij.ui.components.JBCheckBox" binding="myShowWhenMultipleParamsWithSameType" custom-create="true">
|
||||
<component id="4be87" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="fb44" class="com.intellij.ui.components.JBCheckBox" binding="myDoNotShowIfParameterNameContainedInMethodName" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<properties>
|
||||
<text value="Language:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
|
||||
+92
-62
@@ -17,16 +17,17 @@ package com.intellij.codeInsight.hints.settings;
|
||||
|
||||
import com.intellij.codeInsight.hints.InlayParameterHintsExtension;
|
||||
import com.intellij.codeInsight.hints.InlayParameterHintsProvider;
|
||||
import com.intellij.codeInsight.hints.Option;
|
||||
import com.intellij.codeInsight.hints.filtering.MatcherConstructor;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
@@ -46,19 +47,18 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
|
||||
public JPanel myConfigurable;
|
||||
private EditorTextField myEditorTextField;
|
||||
private ComboBox<Language> myCurrentLanguageCombo;
|
||||
|
||||
private JBCheckBox myShowWhenMultipleParamsWithSameType;
|
||||
private JBCheckBox myDoNotShowIfParameterNameContainedInMethodName;
|
||||
private JPanel myOptionsPanel;
|
||||
private JPanel myBlacklistPanel;
|
||||
|
||||
private final Language myInitiallySelectedLanguage;
|
||||
private final String myNewPreselectedItem;
|
||||
|
||||
private final Map<Language, String> myBlackLists;
|
||||
|
||||
private Map<Language, String> myBlackLists = ContainerUtil.newHashMap();
|
||||
private Map<Option, JBCheckBox> myOptions;
|
||||
|
||||
private CardLayout myCardLayout;
|
||||
|
||||
public ParameterNameHintsConfigurable() {
|
||||
this(null, null);
|
||||
@@ -67,17 +67,33 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
public ParameterNameHintsConfigurable(@Nullable Language selectedLanguage,
|
||||
@Nullable String newPreselectedPattern) {
|
||||
super(null);
|
||||
myInitiallySelectedLanguage = selectedLanguage;
|
||||
|
||||
myNewPreselectedItem = newPreselectedPattern;
|
||||
myBlackLists = ContainerUtil.newHashMap();
|
||||
|
||||
setTitle("Configure Parameter Name Hints");
|
||||
init();
|
||||
|
||||
myOptionsPanel.setVisible(true);
|
||||
myOptionsPanel.setBorder(IdeBorderFactory.createTitledBorder("Options"));
|
||||
myBlacklistPanel.setBorder(IdeBorderFactory.createTitledBorder("Blacklist"));
|
||||
|
||||
if (selectedLanguage != null) {
|
||||
myCurrentLanguageCombo.setSelectedItem(selectedLanguage);
|
||||
showLanguageOptions(selectedLanguage);
|
||||
if (newPreselectedPattern != null) {
|
||||
addSelectedText(newPreselectedPattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSelectedText(@Nullable String newPreselectedPattern) {
|
||||
String text = myEditorTextField.getText();
|
||||
final int startOffset = text.length();
|
||||
text += "\n" + newPreselectedPattern;
|
||||
final int endOffset = text.length();
|
||||
|
||||
myEditorTextField.setText(text);
|
||||
myEditorTextField.addSettingsProvider((editor) -> {
|
||||
SelectionModel model = editor.getSelectionModel();
|
||||
model.setSelection(startOffset + 1, endOffset);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateOkEnabled() {
|
||||
@@ -104,10 +120,8 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
String text = entry.getValue();
|
||||
storeBlackListDiff(lang, text);
|
||||
});
|
||||
|
||||
ParameterNameHintsSettings settings = ParameterNameHintsSettings.getInstance();
|
||||
settings.setDoNotShowIfMethodNameContainsParameterName(myDoNotShowIfParameterNameContainedInMethodName.isSelected());
|
||||
settings.setShowForParamsWithSameType(myShowWhenMultipleParamsWithSameType.isSelected());
|
||||
|
||||
myOptions.forEach((option, checkBox) -> option.set(checkBox.isEnabled()));
|
||||
}
|
||||
|
||||
private static void storeBlackListDiff(@NotNull Language language, @NotNull String text) {
|
||||
@@ -130,15 +144,11 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
List<Language> languages = getBaseLanguagesWithProviders();
|
||||
|
||||
Language selected = myInitiallySelectedLanguage;
|
||||
if (selected == null) {
|
||||
selected = languages.get(0);
|
||||
}
|
||||
List<Language> allLanguages = getBaseLanguagesWithProviders();
|
||||
Language selected = allLanguages.get(0);
|
||||
|
||||
String text = getLanguageBlackList(selected);
|
||||
myEditorTextField = createEditor(text, myNewPreselectedItem);
|
||||
myEditorTextField = createEditorField(text);
|
||||
myEditorTextField.addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
@@ -146,17 +156,41 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
}
|
||||
});
|
||||
|
||||
myDoNotShowIfParameterNameContainedInMethodName = new JBCheckBox();
|
||||
myShowWhenMultipleParamsWithSameType = new JBCheckBox();
|
||||
|
||||
ParameterNameHintsSettings settings = ParameterNameHintsSettings.getInstance();
|
||||
myDoNotShowIfParameterNameContainedInMethodName.setSelected(settings.isDoNotShowIfMethodNameContainsParameterName());
|
||||
myShowWhenMultipleParamsWithSameType.setSelected(settings.isShowForParamsWithSameType());
|
||||
|
||||
initLanguageCombo(languages, selected);
|
||||
initLanguageCombo(selected, allLanguages);
|
||||
createOptionsPanel(selected, allLanguages);
|
||||
}
|
||||
|
||||
private void initLanguageCombo(List<Language> languages, Language selected) {
|
||||
private void createOptionsPanel(final Language selected,
|
||||
final List<Language> allLanguages) {
|
||||
myCardLayout = new CardLayout();
|
||||
myOptionsPanel = new JPanel();
|
||||
myOptionsPanel.setLayout(myCardLayout);
|
||||
myOptions = ContainerUtil.newHashMap();
|
||||
|
||||
allLanguages.forEach(language -> {
|
||||
final List<Option> options = getOptions(language);
|
||||
|
||||
final JPanel languagePanel = new JPanel();
|
||||
final BoxLayout boxLayout = new BoxLayout(languagePanel, BoxLayout.Y_AXIS);
|
||||
languagePanel.setLayout(boxLayout);
|
||||
|
||||
if (!options.isEmpty()) {
|
||||
languagePanel.setBorder(IdeBorderFactory.createTitledBorder("Options"));
|
||||
}
|
||||
|
||||
for (Option option : options) {
|
||||
JBCheckBox box = new JBCheckBox(option.getName(), option.get());
|
||||
myOptions.put(option, box);
|
||||
languagePanel.add(box);
|
||||
}
|
||||
|
||||
myOptionsPanel.add(language.getDisplayName(), languagePanel);
|
||||
});
|
||||
|
||||
myCardLayout.show(myOptionsPanel, selected.getDisplayName());
|
||||
}
|
||||
|
||||
private void initLanguageCombo(Language selected, List<Language> languages) {
|
||||
ListComboBoxModel<Language> model = new ListComboBoxModel<>(languages);
|
||||
|
||||
myCurrentLanguageCombo = new ComboBox<>(model);
|
||||
@@ -173,19 +207,36 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
Language language = (Language)e.getItem();
|
||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||
myBlackLists.put(language, myEditorTextField.getText());
|
||||
deselectLanguage(language);
|
||||
}
|
||||
else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
String text = myBlackLists.get(language);
|
||||
if (text == null) {
|
||||
text = getLanguageBlackList(language);
|
||||
}
|
||||
myEditorTextField.setText(text);
|
||||
showLanguageOptions(language);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deselectLanguage(Language language) {
|
||||
myBlackLists.put(language, myEditorTextField.getText());
|
||||
}
|
||||
|
||||
private void showLanguageOptions(Language language) {
|
||||
String text = myBlackLists.get(language);
|
||||
if (text == null) {
|
||||
text = getLanguageBlackList(language);
|
||||
}
|
||||
myEditorTextField.setText(text);
|
||||
myCardLayout.show(myOptionsPanel, language.getDisplayName());
|
||||
}
|
||||
|
||||
private static List<Option> getOptions(Language language) {
|
||||
InlayParameterHintsProvider provider = InlayParameterHintsExtension.INSTANCE.forLanguage(language);
|
||||
if (provider != null) {
|
||||
return provider.getSupportedOptions();
|
||||
}
|
||||
return ContainerUtil.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getLanguageBlackList(@NotNull Language language) {
|
||||
InlayParameterHintsProvider hintsProvider = InlayParameterHintsExtension.INSTANCE.forLanguage(language);
|
||||
@@ -206,25 +257,9 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
.sorted(Comparator.comparingInt(l -> l.getDisplayName().length()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static EditorTextField createEditor(@NotNull String text, @Nullable String newPreselectedItem) {
|
||||
final TextRange range;
|
||||
if (newPreselectedItem != null) {
|
||||
text += "\n";
|
||||
|
||||
final int startOffset = text.length();
|
||||
text += newPreselectedItem;
|
||||
range = new TextRange(startOffset, text.length());
|
||||
}
|
||||
else {
|
||||
range = null;
|
||||
}
|
||||
|
||||
return createEditorField(text, range);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private static EditorTextField createEditorField(@NotNull String text, @Nullable TextRange rangeToSelect) {
|
||||
private static EditorTextField createEditorField(@NotNull String text) {
|
||||
Document document = EditorFactory.getInstance().createDocument(text);
|
||||
EditorTextField field = new EditorTextField(document, null, FileTypes.PLAIN_TEXT, false, false);
|
||||
field.setPreferredSize(new Dimension(200, 350));
|
||||
@@ -232,11 +267,6 @@ public class ParameterNameHintsConfigurable extends DialogWrapper {
|
||||
editor.setVerticalScrollbarVisible(true);
|
||||
editor.setHorizontalScrollbarVisible(true);
|
||||
editor.getSettings().setAdditionalLinesCount(2);
|
||||
if (rangeToSelect != null) {
|
||||
editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset());
|
||||
editor.getScrollingModel().scrollVertically(document.getTextLength() - 1);
|
||||
editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset());
|
||||
}
|
||||
});
|
||||
return field;
|
||||
}
|
||||
|
||||
-2
@@ -49,8 +49,6 @@ class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) {
|
||||
val hintSettings = ParameterNameHintsSettings.getInstance()
|
||||
|
||||
hintSettings.loadState(default.state)
|
||||
hintSettings.isShowForParamsWithSameType = default.isShowForParamsWithSameType
|
||||
hintSettings.isDoNotShowIfMethodNameContainsParameterName = default.isDoNotShowIfMethodNameContainsParameterName
|
||||
}
|
||||
|
||||
fun checkInlays() {
|
||||
|
||||
Reference in New Issue
Block a user