PT #151428541: connected watchdog with new protocol extension to show live hover hints

This commit is contained in:
Martin Lippert
2017-10-04 14:33:15 +02:00
parent 8a12d8b179
commit 9a0b5c8023
4 changed files with 7 additions and 80 deletions

View File

@@ -92,7 +92,6 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
documents.onDidChangeContent(params -> {
TextDocument doc = params.getDocument();
validateWith(doc.getId(), reconcileEngine);
highlighWith(doc, new WordHighlighter(this, "foo"));
});
ICompletionEngine bootCompletionEngine = createCompletionEngine(javaProjectFinder, indexProvider);

View File

@@ -1,58 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017 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.ide.vscode.boot.java;
import java.util.List;
import java.util.function.Function;
import org.eclipse.lsp4j.Range;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.TextDocumentContentChange;
import org.springframework.ide.vscode.commons.util.BadLocationException;
import org.springframework.ide.vscode.commons.util.Log;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
import com.google.common.collect.ImmutableList;
/**
* Sample implementation of a 'highlighter' that can be used with {@link SimpleLanguageServer}.highlightWith.
* <p>
* Finds every occurence of a given word and highlights it.
*
* @author Kris De Volder
*/
public class WordHighlighter implements Function<TextDocument, List<Range>> {
private final SimpleLanguageServer server;
private final String word;
public WordHighlighter(SimpleLanguageServer server, String word) {
super();
this.server = server;
this.word = word;
}
@Override
public List<Range> apply(TextDocument doc) {
String text = doc.get();
int wordStart = text.indexOf(word);
ImmutableList.Builder<Range> highlights = ImmutableList.builder();
while (wordStart>=0) {
try {
highlights.add(doc.toRange(wordStart, word.length()));
} catch (BadLocationException e) {
Log.log(e);
}
wordStart = text.indexOf(word, wordStart+word.length());
}
return highlights.build();
}
}

View File

@@ -10,15 +10,18 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.utils;
import java.util.Arrays;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentSkipListSet;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
import org.springframework.ide.vscode.boot.java.handlers.BootJavaHoverProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.languageserver.HighlightParams;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
@@ -80,7 +83,7 @@ public class SpringLiveHoverWatchdog {
TextDocument doc = this.server.getTextDocumentService().get(docURI);
if (doc != null) {
Range[] ranges = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
publishLiveHints(ranges);
publishLiveHints(docURI, ranges);
}
} catch (Exception e) {
e.printStackTrace();
@@ -95,15 +98,9 @@ public class SpringLiveHoverWatchdog {
}
}
private void publishLiveHints(Range[] ranges) {
for (Range range : ranges) {
int startLine = range.getStart().getLine();
int startChar = range.getStart().getCharacter();
int endLine = range.getEnd().getLine();
int endChar = range.getEnd().getCharacter();
System.out.println("live hover information at: " + startLine + ":" + startChar + " - " + endLine + ":" + endChar);
}
private void publishLiveHints(String docURI, Range[] ranges) {
System.out.println(" PUBLISH LIVE HOVER HINTS !!! " + ranges.length);
server.getClient().highlight(new HighlightParams(new TextDocumentIdentifier(docURI), Arrays.asList(ranges)));
}
private void cleanupLiveHints(String docURI) {