From e92631b036ecc26d92bae33e2a920176d14816c9 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Fri, 10 Aug 2018 10:07:44 -0400 Subject: [PATCH] PT #159690831: Remove inline boot icon decoration --- .../eclipse/commons/BootInlineAnnotation.java | 55 --------------- .../commons/STS4LanguageClientImpl.java | 68 ------------------- .../commons-vscode/src/highlight-service.ts | 9 ++- 3 files changed, 4 insertions(+), 128 deletions(-) delete mode 100644 eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/BootInlineAnnotation.java diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/BootInlineAnnotation.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/BootInlineAnnotation.java deleted file mode 100644 index eb5fdc71d..000000000 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/BootInlineAnnotation.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.tooling.ls.eclipse.commons; - -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.inlined.LineContentAnnotation; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.FontMetrics; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; - -/** - * Boot icon inlined annotation - * - * @author Alex Boyko - * - */ -public class BootInlineAnnotation extends LineContentAnnotation { - - private static final int SPACING = 2; - - public BootInlineAnnotation(Position pos, ISourceViewer viewer) { - super(pos, viewer); - } - - @Override - protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) { - FontMetrics fontMetrics = gc.getFontMetrics(); - int height = fontMetrics.getHeight(); - - Image bootImage = LanguageServerCommonsActivator.getInstance().getImageRegistry().get(LanguageServerCommonsActivator.BOOT_KEY); - Rectangle bootImgBounds = bootImage.getBounds(); - int width = (int) Math.round(bootImgBounds.width / (double) bootImgBounds.height * height); - - Rectangle backgroundRect = new Rectangle(x, y, width + SPACING, fontMetrics.getHeight()); - gc.setBackground(textWidget.getBackground()); - gc.fillRectangle(backgroundRect); - - gc.drawImage(bootImage, bootImgBounds.x, bootImgBounds.y, bootImgBounds.width, bootImgBounds.height, x, y, width, height); - - return backgroundRect.width; - } - -} \ No newline at end of file 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 d081503c0..51fec3619 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 @@ -13,11 +13,8 @@ package org.springframework.tooling.ls.eclipse.commons; import java.lang.reflect.Method; import java.net.URI; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; import java.util.concurrent.CompletableFuture; import org.eclipse.core.runtime.IProgressMonitor; @@ -26,16 +23,11 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewerExtension2; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationPainter; -import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation; -import org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport; import org.eclipse.lsp4e.LSPEclipseUtils; import org.eclipse.lsp4e.LanguageClientImpl; import org.eclipse.lsp4e.LanguageServiceAccessor; @@ -145,8 +137,6 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La */ private Map currentAnnotations = new HashMap<>(); - private Map viewerInlinedAnnotationSupport = new WeakHashMap<>(); - private synchronized void updateAnnotations(String target, ISourceViewer sourceViewer, IAnnotationModelExtension annotationModel) { if (target!=null) { HighlightParams highlightParams = currentHighlights.get(target); @@ -160,7 +150,6 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La Map newAnnotations = createAnnotations(doc, highlights); annotationModel.replaceAnnotations(toRemove, newAnnotations); currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()])); - updateInlinedAnnotations(sourceViewer, highlights); } } } @@ -177,63 +166,6 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La return false; } - private void updateInlinedAnnotations(final ISourceViewer sourceViewer, List highlights) { - InlinedAnnotationSupport support = viewerInlinedAnnotationSupport.get(sourceViewer); - if (support == null) { - final InlinedAnnotationSupport inlinedSupport = new InlinedAnnotationSupport(); - inlinedSupport.install(sourceViewer, createAnnotationPainter(sourceViewer)); - viewerInlinedAnnotationSupport.put(sourceViewer, inlinedSupport); - sourceViewer.getTextWidget().addDisposeListener((e) -> { - inlinedSupport.uninstall(); - viewerInlinedAnnotationSupport.remove(sourceViewer); - }); - support = inlinedSupport; - } - Set annotations = new HashSet<>(); - if (highlights==null) { - highlights = ImmutableList.of(); - } - IDocument doc = sourceViewer.getDocument(); - for (Range rng : highlights) { - try { - int start = LSPEclipseUtils.toOffset(rng.getStart(), doc); - int end = LSPEclipseUtils.toOffset(rng.getEnd(), doc); - Position colorPos = new Position(start, end - start); - BootInlineAnnotation colorAnnotation = support.findExistingAnnotation(colorPos); - if (colorAnnotation == null) { - colorAnnotation = new BootInlineAnnotation(colorPos, sourceViewer); - } - annotations.add(colorAnnotation); - } catch (BadLocationException e) { - //ignore invalid highlights - } - } - support.updateAnnotations(annotations); - } - - private static AnnotationPainter createAnnotationPainter(ISourceViewer viewer) { - IAnnotationAccess annotationAccess = new IAnnotationAccess() { - @Override - public Object getType(Annotation annotation) { - return annotation.getType(); - } - - @Override - public boolean isMultiLine(Annotation annotation) { - return true; - } - - @Override - public boolean isTemporary(Annotation annotation) { - return true; - } - - }; - AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess); - ((ITextViewerExtension2) viewer).addPainter(painter); - return painter; - } - private Map createAnnotations(IDocument doc, List highlights) { ImmutableMap.Builder annotations = ImmutableMap.builder(); if (highlights==null) { diff --git a/vscode-extensions/commons-vscode/src/highlight-service.ts b/vscode-extensions/commons-vscode/src/highlight-service.ts index 974653dcf..d2d68c45b 100644 --- a/vscode-extensions/commons-vscode/src/highlight-service.ts +++ b/vscode-extensions/commons-vscode/src/highlight-service.ts @@ -27,10 +27,10 @@ export class HighlightService { constructor() { this.DECORATION = VSCode.window.createTextEditorDecorationType({ - before: { - contentIconPath: path.resolve(__dirname, "../icons/boot-12h.png"), - margin: '2px 2px 0px 0px' - }, + // before: { + // contentIconPath: path.resolve(__dirname, "../icons/boot-12h.png"), + // margin: '2px 2px 0px 0px' + // }, backgroundColor: 'rgba(109,179,63,0.25)', borderColor: 'rgba(109,179,63,0.25)', borderSpacing: '4px', @@ -55,7 +55,6 @@ export class HighlightService { let highlights : Range[] = this.highlights.get(docId.uri) || []; let decorations = highlights.map(hl => toDecoration(hl)); editor.setDecorations(this.DECORATION, decorations); - editor.setDecorations(this.DECORATION, decorations); } } }