[parameter hints] allow to provide hints which will not be matched by blacklist

This commit is contained in:
Yaroslav Lepenkin
2017-07-12 20:34:47 +03:00
parent 74f45fb3c6
commit e0becd80e8
2 changed files with 31 additions and 20 deletions
@@ -20,13 +20,17 @@ import com.intellij.lang.Language
import com.intellij.lang.LanguageExtension
object InlayParameterHintsExtension: LanguageExtension<InlayParameterHintsProvider>("com.intellij.codeInsight.parameterNameHints")
object InlayParameterHintsExtension : LanguageExtension<InlayParameterHintsProvider>("com.intellij.codeInsight.parameterNameHints")
class InlayInfo(val text: String, val offset: Int, val isShowOnlyIfExistedBefore: Boolean) {
constructor(text: String, offset: Int): this(text, offset, false)
class InlayInfo(val text: String,
val offset: Int,
val isShowOnlyIfExistedBefore: Boolean,
val isFilterByBlacklist: Boolean) {
constructor(text: String, offset: Int, isShowOnlyIfExistedBefore: Boolean) : this(text, offset, isShowOnlyIfExistedBefore, true)
constructor(text: String, offset: Int) : this(text, offset, false, true)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -54,7 +58,7 @@ sealed class HintInfo {
* @language in case you want to put this method into blacklist of another language
*/
open class MethodInfo(val fullyQualifiedName: String, val paramNames: List<String>, val language: Language?) : HintInfo() {
constructor(fullyQualifiedName: String, paramNames: List<String>): this(fullyQualifiedName, paramNames, null)
constructor(fullyQualifiedName: String, paramNames: List<String>) : this(fullyQualifiedName, paramNames, null)
open fun getMethodName(): String {
val start = fullyQualifiedName.lastIndexOf('.') + 1
@@ -63,15 +67,15 @@ sealed class HintInfo {
}
open class OptionInfo(protected val option: Option) : HintInfo() {
open fun disable() = alternate()
open fun enable() = alternate()
private fun alternate() {
val current = option.get()
option.set(!current)
}
open val optionName = option.name
fun isOptionEnabled(): Boolean = option.isEnabled()
@@ -31,6 +31,7 @@ import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Stream;
import static com.intellij.codeInsight.hints.ParameterHintsPassFactory.putCurrentPsiModificationStamp;
@@ -71,18 +72,24 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass {
List<InlayInfo> hints = provider.getParameterHints(element);
if (hints.isEmpty()) return;
HintInfo info = provider.getHintInfo(element);
if (info == null || myHintInfoFilter.showHint(info)) {
hints.forEach((hint) -> {
String presentation = provider.getInlayPresentation(hint.getText());
int offset = hint.getOffset();
if (hint.isShowOnlyIfExistedBefore()) {
myShowOnlyIfExistedBeforeHints.put(offset, presentation);
}
else {
myHints.put(offset, presentation);
}
});
boolean showHints = info == null || info instanceof HintInfo.OptionInfo || myHintInfoFilter.showHint(info);
Stream<InlayInfo> inlays = hints.stream();
if (!showHints) {
inlays = inlays.filter((inlayInfo -> !inlayInfo.isFilterByBlacklist()));
}
inlays.forEach((hint) -> {
String presentation = provider.getInlayPresentation(hint.getText());
int offset = hint.getOffset();
if (hint.isShowOnlyIfExistedBefore()) {
myShowOnlyIfExistedBeforeHints.put(offset, presentation);
}
else {
myHints.put(offset, presentation);
}
});
}
@Override