Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Clarify Dart's closing label by changing it to an End symbol. #893

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.jetbrains.lang.dart.ide.codeInsight.DartCodeInsightSettings;
import org.dartlang.analysis.server.protocol.ClosingLabel;
import org.jetbrains.annotations.NotNull;
import com.jetbrains.lang.dart.highlight.DartSyntaxHighlighterColors;

import java.awt.*;
import java.util.EventListener;
Expand All @@ -46,7 +47,7 @@ public void closingLabelPreferenceChanged() {
}
}
},
this);
this);
}

public static DartClosingLabelManager getInstance() {
Expand Down Expand Up @@ -113,25 +114,28 @@ void computedClosingLabels(@NotNull Project project, @NotNull String filePath, @
lineText.put(line, lineText.get(line) + ", " + label.getLabel());
}
else {
lineText.put(line, "// " + label.getLabel());
// lineText.put(line, "// " + label.getLabel());
lineText.put(line, "⦿‹" + label.getLabel());//«
}
}

// build inlays from the line labels
for (Integer line : lineText.keySet()) {
// inlayModel.addAfterLineEndElement(
// editor.getDocument().getLineEndOffset(line), true, new TextLabelCustomElementRenderer(lineText.get(line)));
inlayModel.addAfterLineEndElement(
editor.getDocument().getLineEndOffset(line), true, new TextLabelCustomElementRenderer(lineText.get(line)));
editor.getDocument().getLineEndOffset(line), true, new TextLabelCustomElementRenderer(lineText.get(line) + "›"));// »
}
}
};

ApplicationManager.getApplication()
.invokeLater(runnable, ModalityState.NON_MODAL, DartAnalysisServerService.getInstance(project).getDisposedCondition());
.invokeLater(runnable, ModalityState.NON_MODAL, DartAnalysisServerService.getInstance(project).getDisposedCondition());
}

private static void clearEditorInlays(@NotNull Editor editor) {
editor.getInlayModel().getAfterLineEndElementsInRange(0, editor.getDocument().getTextLength(), TextLabelCustomElementRenderer.class)
.forEach(Disposer::dispose);
.forEach(Disposer::dispose);
}

private static void clearAllInlays() {
Expand All @@ -142,7 +146,7 @@ private static void clearAllInlays() {
if (fileEditor instanceof TextEditor) {
Editor editor = ((TextEditor)fileEditor).getEditor();
editor.getInlayModel().getInlineElementsInRange(0, editor.getDocument().getTextLength(), TextLabelCustomElementRenderer.class)
.forEach(Disposer::dispose);
.forEach(Disposer::dispose);
}
}
}
Expand All @@ -155,7 +159,9 @@ public void dispose() {
}

class TextLabelCustomElementRenderer implements EditorCustomElementRenderer {
private static final TextAttributesKey TEXT_ATTRIBUTES = DefaultLanguageHighlighterColors.LINE_COMMENT;
//private static final TextAttributesKey TEXT_ATTRIBUTES = DefaultLanguageHighlighterColors.LINE_COMMENT;
//private static final TextAttributesKey TEXT_ATTRIBUTES = DefaultLanguageHighlighterColors.INSTANCE_METHOD;
private static final TextAttributesKey TEXT_ATTRIBUTES = DartSyntaxHighlighterColors.CONSTRUCTOR;

private final String label;

Expand All @@ -169,8 +175,8 @@ private static FontInfo getFontInfo(@NotNull Editor editor) {
TextAttributes attributes = editor.getColorsScheme().getAttributes(TEXT_ATTRIBUTES);
int fontStyle = attributes == null ? Font.PLAIN : attributes.getFontType();
return ComplementaryFontsRegistry.getFontAbleToDisplay(
'a', fontStyle, fontPreferences,
FontInfo.getFontRenderContext(editor.getContentComponent()));
'a', fontStyle, fontPreferences,
FontInfo.getFontRenderContext(editor.getContentComponent()));
}

@Override
Expand All @@ -186,6 +192,12 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics g, @NotNull Rectangle
if (attributes == null) return;
Color fgColor = attributes.getForegroundColor();
if (fgColor == null) return;

fgColor = new Color(fgColor.getRed(),
fgColor.getGreen(),
fgColor.getBlue(),
(int)(fgColor.getAlpha() * 0.4));

g.setColor(fgColor);
FontInfo fontInfo = getFontInfo(editor);
int ascent = editor.getAscent();
Expand Down