PT #159485440: Only update hints if doc versions are matching
This commit is contained in:
@@ -13,30 +13,30 @@ package org.springframework.tooling.ls.eclipse.commons;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
|
||||
public class HighlightParams {
|
||||
|
||||
|
||||
//TODO: Identical copy of this exists in org.springframework.ide.vscode.commons.languageserver.HighlightParams
|
||||
// But because that is only built in plain maven jar (not osgi) we can't use it. We should find a solution
|
||||
// for this somehow (i.e. build a version of some of our 'plain maven' jars as osgi bundles and publish on
|
||||
// a update site.
|
||||
|
||||
private TextDocumentIdentifier doc;
|
||||
private VersionedTextDocumentIdentifier doc;
|
||||
private List<Range> ranges;
|
||||
|
||||
public HighlightParams() {
|
||||
}
|
||||
|
||||
public HighlightParams(TextDocumentIdentifier doc, List<Range> ranges) {
|
||||
public HighlightParams(VersionedTextDocumentIdentifier doc, List<Range> ranges) {
|
||||
super();
|
||||
this.doc = doc;
|
||||
this.ranges = ranges;
|
||||
}
|
||||
public TextDocumentIdentifier getDoc() {
|
||||
public VersionedTextDocumentIdentifier getDoc() {
|
||||
return doc;
|
||||
}
|
||||
public void setDoc(TextDocumentIdentifier doc) {
|
||||
public void setDoc(VersionedTextDocumentIdentifier doc) {
|
||||
this.doc = doc;
|
||||
}
|
||||
public List<Range> getRanges() {
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -42,6 +41,7 @@ import org.eclipse.lsp4e.LanguageClientImpl;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor.LSPDocumentInfo;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
@@ -138,7 +138,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
* Latest highlight request params. It is sufficient to only remember the last request per uri, because
|
||||
* each new request is expected to replace the previous highlights.
|
||||
*/
|
||||
private Map<String, List<Range>> currentHighlights = new HashMap<>();
|
||||
private Map<String, HighlightParams> currentHighlights = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Current markers... indexed per document uri, needed sp we to be removed upon next update.
|
||||
@@ -149,23 +149,32 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
|
||||
private synchronized void updateAnnotations(String target, ISourceViewer sourceViewer, IAnnotationModelExtension annotationModel) {
|
||||
if (target!=null) {
|
||||
HighlightParams highlightParams = currentHighlights.get(target);
|
||||
IDocument doc = sourceViewer.getDocument();
|
||||
Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true);
|
||||
for (LSPDocumentInfo docInfo : infos) {
|
||||
URI uri = docInfo.getFileUri();
|
||||
if (uri!=null && uri.toString().equals(target)) {
|
||||
Annotation[] toRemove = currentAnnotations.get(target);
|
||||
if (toRemove==null) {
|
||||
toRemove = new Annotation[0];
|
||||
}
|
||||
List<Range> highlights = currentHighlights.get(target);
|
||||
Map<Annotation, Position> newAnnotations = createAnnotations(doc, highlights);
|
||||
annotationModel.replaceAnnotations(toRemove, newAnnotations);
|
||||
currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]));
|
||||
updateInlinedAnnotations(sourceViewer, highlights);
|
||||
if (isProperDocumentIdFor(doc, highlightParams.getDoc())) {
|
||||
Annotation[] toRemove = currentAnnotations.get(target);
|
||||
if (toRemove==null) {
|
||||
toRemove = new Annotation[0];
|
||||
}
|
||||
List<Range> highlights = highlightParams == null ? null : highlightParams.getRanges();
|
||||
Map<Annotation, Position> newAnnotations = createAnnotations(doc, highlights);
|
||||
annotationModel.replaceAnnotations(toRemove, newAnnotations);
|
||||
currentAnnotations.put(target, newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]));
|
||||
updateInlinedAnnotations(sourceViewer, highlights);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocumentIdentifier id) {
|
||||
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
|
||||
if (info.getVersion() == id.getVersion()) {
|
||||
URI uri = info.getFileUri();
|
||||
if (uri != null && uri.toString().equals(id.getUri())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateInlinedAnnotations(final ISourceViewer sourceViewer, List<Range> highlights) {
|
||||
@@ -247,7 +256,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
public synchronized void highlight(HighlightParams highlights) {
|
||||
String target = highlights.getDoc().getUri();
|
||||
if (target!=null) {
|
||||
currentHighlights.put(target, highlights.getRanges());
|
||||
currentHighlights.put(target, highlights);
|
||||
new UpdateHighlights(target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,17 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
|
||||
public class HighlightParams {
|
||||
|
||||
private TextDocumentIdentifier doc;
|
||||
private VersionedTextDocumentIdentifier doc;
|
||||
private List<Range> ranges;
|
||||
|
||||
public HighlightParams() {
|
||||
}
|
||||
|
||||
public HighlightParams(TextDocumentIdentifier doc, List<Range> ranges) {
|
||||
public HighlightParams(VersionedTextDocumentIdentifier doc, List<Range> ranges) {
|
||||
super();
|
||||
this.doc = doc;
|
||||
this.ranges = ranges;
|
||||
@@ -31,7 +32,7 @@ public class HighlightParams {
|
||||
public TextDocumentIdentifier getDoc() {
|
||||
return doc;
|
||||
}
|
||||
public void setDoc(TextDocumentIdentifier doc) {
|
||||
public void setDoc(VersionedTextDocumentIdentifier doc) {
|
||||
this.doc = doc;
|
||||
}
|
||||
public List<Range> getRanges() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaHoverProvider;
|
||||
@@ -195,7 +196,10 @@ public class SpringLiveHoverWatchdog {
|
||||
}
|
||||
|
||||
private void publishLiveHints(String docURI, Range[] ranges) {
|
||||
server.getClient().highlight(new HighlightParams(new TextDocumentIdentifier(docURI), Arrays.asList(ranges)));
|
||||
int version = server.getTextDocumentService().get(docURI).getVersion();
|
||||
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(version);
|
||||
id.setUri(docURI);
|
||||
server.getClient().highlight(new HighlightParams(id, Arrays.asList(ranges)));
|
||||
}
|
||||
|
||||
private void cleanupLiveHints(String docURI) {
|
||||
|
||||
Reference in New Issue
Block a user