diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/css/e4-dark_sts4_prefstyle.css b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/css/e4-dark_sts4_prefstyle.css index e16dab21c..07c9c7a09 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/css/e4-dark_sts4_prefstyle.css +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/css/e4-dark_sts4_prefstyle.css @@ -1,4 +1,4 @@ /* See bug 466075 about the pseudo-selector ":org-springframework-tooling-ls-eclipse-commons" */ IEclipsePreferences#org-eclipse-ui-workbench:org-springframework-tooling-ls-eclipse-commons { preferences: - 'org.springframework.tooling.ls.eclipse.commons.STS4BootMarkerIndicationColor=109,177,63' + 'org.springframework.tooling.ls.eclipse.commons.STS4BootMarkerIndicationColor=56,84,26' diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml index 7d3471c33..4f03d4551 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml @@ -14,6 +14,7 @@ highlightPreferenceKey="STS4BootMarkerHighlighting" highlightPreferenceValue="true" icon="icons/boot-icon.png" + includeOnPreferencePage="false" label="Boot Dynamic Info" overviewRulerPreferenceKey="STS4BootMarkerIndicationInOverviewRuler" overviewRulerPreferenceValue="false" @@ -133,7 +134,7 @@ id="org.springframework.tooling.ls.eclipse.commons.STS4BootMarkerIndicationColor" isEditable="true" label="Live Boot Hint Color" - value="111,179,63"> + value="219,236,207"> Running Spring Boot app live data availability hints diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java index be0a33c69..37e60e391 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java @@ -11,25 +11,33 @@ package org.springframework.tooling.ls.eclipse.commons; import java.net.URL; +import java.util.Objects; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.texteditor.AnnotationPreference; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl.UpdateHighlights; import org.springframework.tooling.ls.eclipse.commons.preferences.PreferenceConstants; +@SuppressWarnings("restriction") public class LanguageServerCommonsActivator extends AbstractUIPlugin { + private static final String BOOT_HINT_ANNOTATION_TYPE = "org.springframework.tooling.bootinfo"; + public static final String PLUGIN_ID = "org.springframework.tooling.ls.eclipse.commons"; public static final String BOOT_KEY = "boot-key"; @@ -42,6 +50,7 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin { public void propertyChange(PropertyChangeEvent event) { switch (event.getProperty()) { case PreferenceConstants.HIGHLIGHT_RANGE_COLOR_THEME: + updateMarkerAnnotationPreferences(); // Fall through to update highlights case PreferenceConstants.HIGHLIGHT_CODELENS_PREFS: new UpdateHighlights(null, true); @@ -52,6 +61,8 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin { }; + private AnnotationPreference bootHintAnnotationPreference; + public LanguageServerCommonsActivator() { } @@ -62,7 +73,22 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin { getImageRegistry().put(BOOT_KEY, getImageDescriptor("icons/boot.png")); getPreferenceStore().addPropertyChangeListener(PROPERTY_LISTENER); - PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(PROPERTY_LISTENER);; + PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(PROPERTY_LISTENER); + + bootHintAnnotationPreference = EditorsPlugin.getDefault().getMarkerAnnotationPreferences() + .getAnnotationPreferences().stream().filter(Objects::nonNull) + .filter(info -> BOOT_HINT_ANNOTATION_TYPE.equals(info.getAnnotationType())).findFirst().orElse(null); + updateMarkerAnnotationPreferences(); + } + + /** + * Forwards theme colors on to marker preferences + */ + private void updateMarkerAnnotationPreferences() { + RGB themeRgb = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry() + .getRGB(PreferenceConstants.HIGHLIGHT_RANGE_COLOR_THEME); + PreferenceConverter.setValue(EditorsPlugin.getDefault().getPreferenceStore(), + bootHintAnnotationPreference.getColorPreferenceKey(), themeRgb); } public Color getBootHighlightRangeColor() { diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java index f25b587e9..54a8f07c4 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.springframework.tooling.ls.eclipse.commons; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; @@ -42,8 +41,6 @@ import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationPainter; -import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.ISourceViewer; @@ -54,12 +51,6 @@ import org.eclipse.lsp4j.CodeLens; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.MarkupKind; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; @@ -68,9 +59,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.progress.UIJob; -import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; import org.eclipse.ui.texteditor.AbstractTextEditor; -import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; import org.springframework.ide.vscode.commons.protocol.CursorMovement; import org.springframework.ide.vscode.commons.protocol.HighlightParams; import org.springframework.ide.vscode.commons.protocol.ProgressParams; @@ -143,8 +132,8 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La private static final String ANNOTION_TYPE_ID = "org.springframework.tooling.bootinfo"; - private static final String ALT_ANNOTATION_DRAWING_STRATEGY_ID = "boot.hint.strategy"; - private static final String ALT_ANNOTATION_TYPE_ID = "org.springframework.tooling.bootinfoCodeLens"; +// private static final String ALT_ANNOTATION_DRAWING_STRATEGY_ID = "boot.hint.strategy"; +// private static final String ALT_ANNOTATION_TYPE_ID = "org.springframework.tooling.bootinfoCodeLens"; /** * Latest highlight request params. It is sufficient to only remember the last request per uri, because @@ -157,32 +146,32 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La */ private static Map currentAnnotations = new ConcurrentHashMap<>(); - private static final IDrawingStrategy BOOT_RANGE_HIGHLIGHT_DRAWING_STRATEGY = new IDrawingStrategy() { - - @Override - public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) { - - if (gc == null) { - textWidget.redrawRange(offset, length, true); - } else { - int oldAlpha = gc.getAlpha(); - Font oldFont = gc.getFont(); - - Point left= textWidget.getLocationAtOffset(offset); - Point right = textWidget.getLocationAtOffset(offset + length); - gc.setFont(textWidget.getFont()); - int fontHeight = gc.getFontMetrics().getHeight(); - Rectangle r = new Rectangle(left.x, left.y + textWidget.getLineHeight(offset) - fontHeight, right.x - left.x, fontHeight); - gc.setAlpha(0x40); - gc.setBackground(color); - gc.fillRectangle(r); - - gc.setAlpha(oldAlpha); - gc.setFont(oldFont); - } - } - - }; +// private static final IDrawingStrategy BOOT_RANGE_HIGHLIGHT_DRAWING_STRATEGY = new IDrawingStrategy() { +// +// @Override +// public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) { +// +// if (gc == null) { +// textWidget.redrawRange(offset, length, true); +// } else { +// int oldAlpha = gc.getAlpha(); +// Font oldFont = gc.getFont(); +// +// Point left= textWidget.getLocationAtOffset(offset); +// Point right = textWidget.getLocationAtOffset(offset + length); +// gc.setFont(textWidget.getFont()); +// int fontHeight = gc.getFontMetrics().getHeight(); +// Rectangle r = new Rectangle(left.x, left.y + textWidget.getLineHeight(offset) - fontHeight, right.x - left.x, fontHeight); +// gc.setAlpha(0x40); +// gc.setBackground(color); +// gc.fillRectangle(r); +// +// gc.setAlpha(oldAlpha); +// gc.setFont(oldFont); +// } +// } +// +// }; static class UpdateHighlights extends UIJob { @@ -231,11 +220,11 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La private static void updateHighlightAnnotations(IEditorPart editor, ISourceViewer sourceViewer, IAnnotationModel annotationModel, String docUri, boolean updateCodeMinings) { - boolean codeLensHighlightOn = isCodeLensHighlightOn(); +// boolean codeLensHighlightOn = isCodeLensHighlightOn(); if (annotationModel instanceof IAnnotationModelExtension) { - if (codeLensHighlightOn) { - addBootRangeHighlightSupport(editor, sourceViewer); - } +// if (codeLensHighlightOn) { +// addBootRangeHighlightSupport(editor, sourceViewer); +// } updateAnnotations(docUri, sourceViewer, (IAnnotationModelExtension) annotationModel); } if (updateCodeMinings && sourceViewer instanceof ISourceViewerExtension5) { @@ -255,39 +244,39 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La } } - private static void addBootRangeHighlightSupport(IEditorPart editor, ISourceViewer sourceViewer) { - if (editor instanceof AbstractDecoratedTextEditor) { - addBootRangeHighlightSupport((AbstractDecoratedTextEditor)editor, sourceViewer); - } -// else if () { -// // TODO: XML multi page editor handling for highlight support of XML source editor +// private static void addBootRangeHighlightSupport(IEditorPart editor, ISourceViewer sourceViewer) { +// if (editor instanceof AbstractDecoratedTextEditor) { +// addBootRangeHighlightSupport((AbstractDecoratedTextEditor)editor, sourceViewer); // } - } - - @SuppressWarnings("unchecked") - private static void addBootRangeHighlightSupport(AbstractDecoratedTextEditor editor, ISourceViewer sourceViewer) { - try { - Field f = AbstractDecoratedTextEditor.class.getDeclaredField("fSourceViewerDecorationSupport"); - f.setAccessible(true); - SourceViewerDecorationSupport support = (SourceViewerDecorationSupport) f.get(editor); - f = SourceViewerDecorationSupport.class.getDeclaredField("fAnnotationPainter"); - f.setAccessible(true); - AnnotationPainter painter = (AnnotationPainter) f.get(support); - - f = AnnotationPainter.class.getDeclaredField("fAnnotationType2Color"); - f.setAccessible(true); - Color highlightColor = LanguageServerCommonsActivator.getInstance().getBootHighlightRangeColor(); - if (highlightColor!=null && ((Map)f.get(painter)).get(ALT_ANNOTATION_TYPE_ID) != highlightColor) { - painter.setAnnotationTypeColor(ALT_ANNOTATION_TYPE_ID, highlightColor); - painter.addDrawingStrategy(ALT_ANNOTATION_DRAWING_STRATEGY_ID, BOOT_RANGE_HIGHLIGHT_DRAWING_STRATEGY); - painter.addAnnotationType(ALT_ANNOTATION_TYPE_ID, ALT_ANNOTATION_DRAWING_STRATEGY_ID); - } - - } catch (Exception e) { - LanguageServerCommonsActivator.logError(e, - "Failed to contribute alternative range highlight annotation. Switch off highlight CodeLense under STS Language Server preferences!"); - } - } +//// else if () { +//// // TODO: XML multi page editor handling for highlight support of XML source editor +//// } +// } +// +// @SuppressWarnings("unchecked") +// private static void addBootRangeHighlightSupport(AbstractDecoratedTextEditor editor, ISourceViewer sourceViewer) { +// try { +// Field f = AbstractDecoratedTextEditor.class.getDeclaredField("fSourceViewerDecorationSupport"); +// f.setAccessible(true); +// SourceViewerDecorationSupport support = (SourceViewerDecorationSupport) f.get(editor); +// f = SourceViewerDecorationSupport.class.getDeclaredField("fAnnotationPainter"); +// f.setAccessible(true); +// AnnotationPainter painter = (AnnotationPainter) f.get(support); +// +// f = AnnotationPainter.class.getDeclaredField("fAnnotationType2Color"); +// f.setAccessible(true); +// Color highlightColor = LanguageServerCommonsActivator.getInstance().getBootHighlightRangeColor(); +// if (highlightColor!=null && ((Map)f.get(painter)).get(ALT_ANNOTATION_TYPE_ID) != highlightColor) { +// painter.setAnnotationTypeColor(ALT_ANNOTATION_TYPE_ID, highlightColor); +// painter.addDrawingStrategy(ALT_ANNOTATION_DRAWING_STRATEGY_ID, BOOT_RANGE_HIGHLIGHT_DRAWING_STRATEGY); +// painter.addAnnotationType(ALT_ANNOTATION_TYPE_ID, ALT_ANNOTATION_DRAWING_STRATEGY_ID); +// } +// +// } catch (Exception e) { +// LanguageServerCommonsActivator.logError(e, +// "Failed to contribute alternative range highlight annotation. Switch off highlight CodeLense under STS Language Server preferences!"); +// } +// } private static boolean isCodeLensHighlightOn() { IPreferenceStore store = LanguageServerCommonsActivator.getInstance().getPreferenceStore(); @@ -302,7 +291,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La } HighlightParams highlightParams = currentHighlights.get(target); List highlights = highlightParams == null ? null : highlightParams.getCodeLenses(); - String annotationType = isCodeLensHighlightOn() ? ALT_ANNOTATION_TYPE_ID : ANNOTION_TYPE_ID; + String annotationType = /*isCodeLensHighlightOn() ? ALT_ANNOTATION_TYPE_ID :*/ ANNOTION_TYPE_ID; Map newAnnotations = createAnnotations(sourceViewer.getDocument(), highlights, annotationType); annotationModel.replaceAnnotations(toRemove, newAnnotations); currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()])); diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/PreferenceConstants.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/PreferenceConstants.java index 0c63ed7a2..de504e5a9 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/PreferenceConstants.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/PreferenceConstants.java @@ -16,4 +16,6 @@ public class PreferenceConstants { public static final String HIGHLIGHT_RANGE_COLOR_THEME = "org.springframework.tooling.ls.eclipse.commons.STS4BootMarkerIndicationColor"; + public static final String HIGHLIGHT_RANGE_COLOR_PREFERENCE = "STS4BootMarkerIndicationColor"; + }