PT #159690831: Remove inline boot icon decoration

This commit is contained in:
BoykoAlex
2018-08-10 10:07:44 -04:00
parent c953ff93c1
commit e92631b036
3 changed files with 4 additions and 128 deletions

View File

@@ -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;
}
}

View File

@@ -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<String, Annotation[]> currentAnnotations = new HashMap<>();
private Map<ISourceViewer, InlinedAnnotationSupport> 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<Annotation, Position> 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<Range> 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<AbstractInlinedAnnotation> 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<Annotation, Position> createAnnotations(IDocument doc, List<Range> highlights) {
ImmutableMap.Builder<Annotation, Position> annotations = ImmutableMap.builder();
if (highlights==null) {

View File

@@ -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);
}
}
}