Add back 'fake' highlighter for testing.
Make it disabled by default (small code edit needed to enable it).
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.ide.vscode.boot.java.value.ValuePropertyReferencesPro
|
||||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleCore;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleProjectFinderStrategy;
|
||||
import org.springframework.ide.vscode.commons.languageserver.HighlightParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.DefaultJavaProjectFinder;
|
||||
@@ -80,6 +81,8 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
private final SpringIndexer indexer;
|
||||
private final SpringLiveHoverWatchdog liveHoverWatchdog;
|
||||
|
||||
private final WordHighlighter testHightlighter = null; //new WordHighlighter("foo");
|
||||
|
||||
public BootJavaLanguageServer(JavaProjectFinder javaProjectFinder, SpringPropertyIndexProvider indexProvider) {
|
||||
super("vscode-boot-java");
|
||||
|
||||
@@ -106,8 +109,12 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
liveHoverWatchdog = new SpringLiveHoverWatchdog(this, hoverInfoProvider);
|
||||
documents.onDidChangeContent(params -> {
|
||||
TextDocument doc = params.getDocument();
|
||||
liveHoverWatchdog.watchDocument(doc.getUri());
|
||||
liveHoverWatchdog.update(doc.getUri());
|
||||
if (testHightlighter!=null) {
|
||||
getClient().highlight(new HighlightParams(params.getDocument().getId(), testHightlighter.apply(doc)));
|
||||
} else {
|
||||
liveHoverWatchdog.watchDocument(doc.getUri());
|
||||
liveHoverWatchdog.update(doc.getUri());
|
||||
}
|
||||
});
|
||||
|
||||
ReferencesHandler referencesHandler = createReferenceHandler(this, javaProjectFinder);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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.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 String word;
|
||||
|
||||
public WordHighlighter(String word) {
|
||||
super();
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user