IDEA-161418 Missing example of "Inline parameters hint" in color scheme settings

This commit is contained in:
Dmitry Batrak
2016-10-04 14:33:24 +03:00
parent 5d9245771d
commit b32ef4113b
10 changed files with 156 additions and 26 deletions
@@ -85,8 +85,6 @@ public class JavaHighlightingColors {
= TextAttributesKey.createTextAttributesKey("ANONYMOUS_CLASS_NAME_ATTRIBUTES", CLASS_NAME_ATTRIBUTES);
public static final TextAttributesKey IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES
= TextAttributesKey.createTextAttributesKey("IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES", CLASS_NAME_ATTRIBUTES);
public static final TextAttributesKey INLINE_PARAMETER_HINT
= TextAttributesKey.createTextAttributesKey("INLINE_PARAMETER_HINT");
public static final TextAttributesKey TYPE_PARAMETER_NAME_ATTRIBUTES
= TextAttributesKey.createTextAttributesKey("TYPE_PARAMETER_NAME_ATTRIBUTES", DefaultLanguageHighlighterColors.PARAMETER);
public static final TextAttributesKey INTERFACE_NAME_ATTRIBUTES
@@ -74,7 +74,6 @@ public class JavaColorSettingsPage implements RainbowColorSettingsPage, Inspecti
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.reassigned.local.variable"), JavaHighlightingColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.reassigned.parameter"), JavaHighlightingColors.REASSIGNED_PARAMETER_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.implicit.anonymous.parameter"), JavaHighlightingColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.inline.parameter.hint"), JavaHighlightingColors.INLINE_PARAMETER_HINT),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.field"), JavaHighlightingColors.INSTANCE_FIELD_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.final.field"), JavaHighlightingColors.INSTANCE_FINAL_FIELD_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.field"), JavaHighlightingColors.STATIC_FIELD_ATTRIBUTES),
@@ -68,4 +68,5 @@ public class DefaultLanguageHighlighterColors {
public static final TextAttributesKey MARKUP_TAG = TextAttributesKey.createTextAttributesKey("DEFAULT_TAG", HighlighterColors.TEXT);
public static final TextAttributesKey MARKUP_ATTRIBUTE = TextAttributesKey.createTextAttributesKey("DEFAULT_ATTRIBUTE", IDENTIFIER);
public static final TextAttributesKey MARKUP_ENTITY = TextAttributesKey.createTextAttributesKey("DEFAULT_ENTITY", IDENTIFIER);
public static final TextAttributesKey INLINE_PARAMETER_HINT = TextAttributesKey.createTextAttributesKey("INLINE_PARAMETER_HINT");
}
@@ -22,7 +22,6 @@ import com.intellij.codeHighlighting.RainbowHighlighter;
import com.intellij.codeInsight.daemon.UsedColors;
import com.intellij.ide.highlighter.HighlighterFactory;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor;
import com.intellij.openapi.editor.colors.TextAttributesKey;
@@ -36,6 +35,7 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.options.colors.EditorHighlightingProvidingColorSettingsPage;
import com.intellij.openapi.options.colors.RainbowColorSettingsPage;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.Alarm;
@@ -54,7 +54,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES;
public class SimpleEditorPreview implements PreviewPanel {
private static final Map<String, TextAttributesKey> INLINE_ELEMENTS =
Collections.singletonMap("parameter_hint", DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT);
private final ColorSettingsPage myPage;
private final EditorEx myEditor;
@@ -74,7 +79,7 @@ public class SimpleEditorPreview implements PreviewPanel {
myOptions = options;
myPage = page;
myHighlightsExtractor = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap());
myHighlightsExtractor = new HighlightsExtractor(page.getAdditionalHighlightingTagToDescriptorMap(), INLINE_ELEMENTS);
myEditor = (EditorEx)FontEditorPreview.createPreviewEditor(
myHighlightsExtractor.extractHighlights(page.getDemoText(), myHighlightData), // text without tags
10, 3, -1, myOptions, false);
@@ -187,7 +192,7 @@ public class SimpleEditorPreview implements PreviewPanel {
private void updateHighlighters() {
UIUtil.invokeLaterIfNeeded(() -> {
if (myEditor.isDisposed()) return;
myEditor.getMarkupModel().removeAllHighlighters();
removeDecorations(myEditor);
final Map<TextAttributesKey, String> displayText = ColorSettingsUtil.keyToDisplayTextMap(myPage);
for (final HighlightData data : myHighlightData) {
data.addHighlToView(myEditor, myOptions.getSelectedScheme(), displayText);
@@ -195,6 +200,13 @@ public class SimpleEditorPreview implements PreviewPanel {
});
}
private static void removeDecorations(Editor editor) {
editor.getMarkupModel().removeAllHighlighters();
for (Inlay inlay : editor.getInlayModel().getInlineElementsInRange(0, editor.getDocument().getTextLength())) {
Disposer.dispose(inlay);
}
}
private static final int BLINK_COUNT = 3 * 2;
@Override
@@ -248,18 +260,14 @@ public class SimpleEditorPreview implements PreviewPanel {
final int count,
final ColorSettingsPage page) {
if (show && count <= 0) return Collections.emptyList();
editor.getMarkupModel().removeAllHighlighters();
removeDecorations(editor);
boolean found = false;
List<HighlightData> highlights = new ArrayList<>();
List<HighlightData> matchingHighlights = new ArrayList<>();
for (HighlightData highlightData : myHighlightData) {
String type = highlightData.getHighlightType();
highlights.add(highlightData);
if (show && type.equals(attrKey)) {
highlightData =
new HighlightData(highlightData.getStartOffset(), highlightData.getEndOffset(),
CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
highlights.add(highlightData);
boolean highlight = show && highlightData.getHighlightType().equals(attrKey);
highlightData.addToCollection(highlights, highlight);
if (highlight) {
matchingHighlights.add(highlightData);
found = true;
}
@@ -272,8 +280,7 @@ public class SimpleEditorPreview implements PreviewPanel {
for (final TextAttributesKey tokenHighlight : tokenHighlights) {
String type = tokenHighlight.getExternalName();
if (show && type != null && type.equals(attrKey)) {
HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(),
CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
HighlightData highlightData = new HighlightData(iterator.getStart(), iterator.getEnd(), BLINKING_HIGHLIGHTS_ATTRIBUTES);
highlights.add(highlightData);
matchingHighlights.add(highlightData);
}
@@ -25,11 +25,15 @@ import com.intellij.openapi.editor.markup.HighlighterTargetArea;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Collection;
import java.util.Map;
public final class HighlightData {
import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES;
public class HighlightData {
private final int myStartOffset;
private int myEndOffset;
private final TextAttributesKey myHighlightType;
@@ -45,6 +49,11 @@ public final class HighlightData {
myHighlightType = highlightType;
}
public void addToCollection(@NotNull Collection<HighlightData> list, boolean highlighted) {
list.add(this);
if (highlighted) list.add(new HighlightData(getStartOffset(), getEndOffset(), BLINKING_HIGHLIGHTS_ATTRIBUTES));
}
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) {
// XXX: Hack
@@ -18,6 +18,8 @@ package com.intellij.application.options.colors.highlighting;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.Nullable;
@@ -26,8 +28,8 @@ import java.util.List;
import java.util.Map;
public class HighlightsExtractor {
private final Map<String,TextAttributesKey> myTags;
private final Map<String,TextAttributesKey> myInlineElements;
private int myStartOffset;
private int myEndOffset;
@@ -38,18 +40,29 @@ public class HighlightsExtractor {
private List<TextRange> mySkipped = new ArrayList<>();
public HighlightsExtractor(@Nullable Map<String, TextAttributesKey> tags) {
this(tags, null);
}
public HighlightsExtractor(@Nullable Map<String, TextAttributesKey> tags, @Nullable Map<String, TextAttributesKey> inlineElements) {
myTags = tags;
myInlineElements = inlineElements;
}
public String extractHighlights(String text, List<HighlightData> highlights) {
mySkipped.clear();
if (myTags == null || myTags.isEmpty()) return text;
if (ContainerUtil.isEmpty(myTags) && ContainerUtil.isEmpty(myInlineElements)) return text;
resetIndices();
Stack<HighlightData> highlightsStack = new Stack<>();
while (true) {
String tagName = findTagName(text);
if (tagName == null || myIndex < 0) break;
if (myTags.containsKey(tagName)) {
String tagNameWithoutParameters = StringUtil.substringBefore(tagName, " ");
if (myInlineElements != null && tagNameWithoutParameters != null && myInlineElements.containsKey(tagNameWithoutParameters)) {
mySkippedLen += tagName.length() + 2;
String hintText = tagName.substring(tagNameWithoutParameters.length()).trim();
highlights.add(new InlineElementData(myStartOffset - mySkippedLen, myInlineElements.get(tagNameWithoutParameters), hintText));
}
else if (myTags != null && myTags.containsKey(tagName)) {
if (myIsOpeningTag) {
mySkippedLen += tagName.length() + 2;
HighlightData highlightData = new HighlightData(myStartOffset - mySkippedLen, myTags.get(tagName));
@@ -95,12 +108,13 @@ public class HighlightsExtractor {
if (myIsOpeningTag) {
myStartOffset = openTag + tagName.length() + 2;
if (myTags.containsKey(tagName)) {
if (myTags != null && myTags.containsKey(tagName) ||
myInlineElements != null && myInlineElements.containsKey(StringUtil.substringBefore(tagName, " "))) {
mySkipped.add(TextRange.from(openTag, tagName.length() + 2));
}
} else {
myEndOffset = openTag - 1;
if (myTags.containsKey(tagName)) {
if (myTags != null && myTags.containsKey(tagName)) {
mySkipped.add(TextRange.from(openTag - 1, tagName.length() + 3));
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2000-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.
*/
package com.intellij.application.options.colors.highlighting;
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorCustomElementRenderer;
import com.intellij.openapi.editor.Inlay;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.intellij.openapi.editor.colors.CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES;
public class InlineElementData extends HighlightData {
private final String myText;
private boolean myAddBorder;
public InlineElementData(int offset, TextAttributesKey attributesKey, String text) {
this(offset, attributesKey, text, false);
}
private InlineElementData(int offset, TextAttributesKey attributesKey, String text, boolean highlighted) {
super(offset, offset, attributesKey);
myText = text;
myAddBorder = highlighted;
}
public String getText() {
return myText;
}
@Override
public void addHighlToView(Editor view, EditorColorsScheme scheme, Map<TextAttributesKey, String> displayText) {
int offset = getStartOffset();
ParameterHintsPresentationManager.getInstance().addHint(view, offset, myText, false);
List<Inlay> inlays = view.getInlayModel().getInlineElementsInRange(offset, offset);
for (Inlay inlay : inlays) {
EditorCustomElementRenderer renderer = inlay.getRenderer();
if (!(renderer instanceof RendererWrapper)) {
Disposer.dispose(inlay);
RendererWrapper wrapper = new RendererWrapper(renderer);
wrapper.drawBorder = myAddBorder;
view.getInlayModel().addInlineElement(offset, wrapper);
}
}
}
@Override
public void addToCollection(@NotNull Collection<HighlightData> list, boolean highlighted) {
list.add(new InlineElementData(getStartOffset(), getHighlightKey(), myText, highlighted));
}
public static class RendererWrapper implements EditorCustomElementRenderer {
private final EditorCustomElementRenderer myDelegate;
private boolean drawBorder;
public RendererWrapper(EditorCustomElementRenderer delegate) {
myDelegate = delegate;
}
@Override
public int calcWidthInPixels(@NotNull Editor editor) {
return myDelegate.calcWidthInPixels(editor);
}
@Override
public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) {
myDelegate.paint(editor, g, r);
if (drawBorder) {
TextAttributes attributes = editor.getColorsScheme().getAttributes(BLINKING_HIGHLIGHTS_ATTRIBUTES);
if (attributes != null && attributes.getEffectColor() != null) {
g.setColor(attributes.getEffectColor());
g.drawRect(r.x, r.y, r.width, r.height);
}
}
}
}
}
@@ -15,10 +15,10 @@
*/
package com.intellij.codeInsight.daemon.impl;
import com.intellij.ide.highlighter.JavaHighlightingColors;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorCustomElementRenderer;
import com.intellij.openapi.editor.Inlay;
@@ -186,7 +186,7 @@ public class ParameterHintsPresentationManager implements Disposable {
@Override
public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) {
if (myText != null && (step > steps || startWidth != 0)) {
TextAttributes attributes = editor.getColorsScheme().getAttributes(JavaHighlightingColors.INLINE_PARAMETER_HINT);
TextAttributes attributes = editor.getColorsScheme().getAttributes(DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT);
if (attributes != null) {
MyFontMetrics fontMetrics = getFontMetrics(editor);
Color backgroundColor = attributes.getBackgroundColor();
@@ -148,6 +148,8 @@ public class DefaultLanguageColorsPage implements RainbowColorSettingsPage, Disp
OptionsBundle.message("options.language.defaults.function.call"), DefaultLanguageHighlighterColors.FUNCTION_CALL),
new AttributesDescriptor(
OptionsBundle.message("options.language.defaults.parameter"), DefaultLanguageHighlighterColors.PARAMETER),
new AttributesDescriptor(
OptionsBundle.message("options.java.attribute.descriptor.inline.parameter.hint"), DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT),
new AttributesDescriptor(
OptionsBundle.message("options.language.defaults.interface.name"), DefaultLanguageHighlighterColors.INTERFACE_NAME),
new AttributesDescriptor(
@@ -220,7 +222,7 @@ public class DefaultLanguageColorsPage implements RainbowColorSettingsPage, Disp
" */</doc_comment>\n" +
"Function <func_decl>declaration</func_decl> (<param>parameter1</param> <param>parameter2</param> <param>parameter3</param> <param>parameter4</param>)\n" +
" Local <local_var>variable1</local_var> <local_var>variable2</local_var> <local_var>variable3</local_var> <local_var>variable4</local_var>\n" +
"Function <func_call>call</func_call>()\n" +
"Function <func_call>call</func_call>(<parameter_hint value>0)\n" +
"Interface <interface>Name</interface>\n" +
"<metadata>@Metadata</metadata>\n" +
"Class <class_name>Name</class_name>\n" +
@@ -79,7 +79,7 @@ options.java.attribute.descriptor.local.variable=Variables//Local variable
options.java.attribute.descriptor.reassigned.local.variable=Variables//Reassigned local variable
options.java.attribute.descriptor.reassigned.parameter=Parameters//Reassigned parameter
options.java.attribute.descriptor.implicit.anonymous.parameter=Parameters//Implicit anonymous class parameter
options.java.attribute.descriptor.inline.parameter.hint=Parameters//Inline parameter hint
options.java.attribute.descriptor.inline.parameter.hint=Inline parameter hint
options.java.attribute.descriptor.instance.field=Class Fields//Instance field
options.java.attribute.descriptor.instance.final.field=Class Fields//Instance final field
options.java.attribute.descriptor.static.field=Class Fields//Static field