add basic support for document highlight feature to common ls pieces
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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.ide.vscode.commons.languageserver.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DocumentHighlightHandler {
|
||||
|
||||
CompletableFuture<List<? extends DocumentHighlight>> handle(TextDocumentPositionParams position);
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -334,6 +333,9 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
if (hasDocumentSymbolHandler()) {
|
||||
c.setDocumentSymbolProvider(true);
|
||||
}
|
||||
if (hasDocumentHighlightHandler()) {
|
||||
c.setDocumentHighlightProvider(true);
|
||||
}
|
||||
if (hasCodeLensHandler()) {
|
||||
CodeLensOptions codeLensOptions = new CodeLensOptions();
|
||||
codeLensOptions.setResolveProvider(hasCodeLensResolveProvider());
|
||||
@@ -368,6 +370,10 @@ public class SimpleLanguageServer implements Sts4LanguageServer, LanguageClientA
|
||||
return getTextDocumentService().hasDocumentSymbolHandler();
|
||||
}
|
||||
|
||||
private boolean hasDocumentHighlightHandler() {
|
||||
return getTextDocumentService().hasDocumentHighlightHandler();
|
||||
}
|
||||
|
||||
private boolean hasCodeLensHandler() {
|
||||
return getTextDocumentService().hasCodeLensHandler();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 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
|
||||
@@ -79,6 +79,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
private DefinitionHandler definitionHandler;
|
||||
private ReferencesHandler referencesHandler;
|
||||
private DocumentSymbolHandler documentSymbolHandler;
|
||||
private DocumentHighlightHandler documentHighlightHandler;
|
||||
|
||||
private CodeLensHandler codeLensHandler;
|
||||
private CodeLensResolveHandler codeLensResolveHandler;
|
||||
@@ -109,6 +110,11 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
this.documentSymbolHandler = h;
|
||||
}
|
||||
|
||||
public synchronized void onDocumentHighlight(DocumentHighlightHandler h) {
|
||||
Assert.isNull("A DocumentHighlightHandler is already set, multiple handlers not supported yet", documentHighlightHandler);
|
||||
this.documentHighlightHandler = h;
|
||||
}
|
||||
|
||||
public synchronized void onCompletion(CompletionHandler h) {
|
||||
Assert.isNull("A completion handler is already set, multiple handlers not supported yet", completionHandler);
|
||||
this.completionHandler = h;
|
||||
@@ -254,6 +260,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
public final static CompletableFuture<List<? extends Location>> NO_REFERENCES = CompletableFuture.completedFuture(ImmutableList.of());
|
||||
public final static List<? extends SymbolInformation> NO_SYMBOLS = ImmutableList.of();
|
||||
public final static CompletableFuture<List<? extends CodeLens>> NO_CODELENS = CompletableFuture.completedFuture(ImmutableList.of());
|
||||
public final static CompletableFuture<List<? extends DocumentHighlight>> NO_HIGHLIGHTS = CompletableFuture.completedFuture(ImmutableList.of());
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
|
||||
@@ -424,7 +431,11 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(TextDocumentPositionParams position) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
DocumentHighlightHandler handler = this.documentHighlightHandler;
|
||||
if (handler != null) {
|
||||
return handler.handle(position);
|
||||
}
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
public boolean hasDefinitionHandler() {
|
||||
@@ -439,6 +450,10 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
return this.documentSymbolHandler!=null;
|
||||
}
|
||||
|
||||
public boolean hasDocumentHighlightHandler() {
|
||||
return this.documentHighlightHandler!=null;
|
||||
}
|
||||
|
||||
public boolean hasCodeLensHandler() {
|
||||
return this.codeLensHandler != null;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,14 @@ import org.springframework.ide.vscode.boot.java.conditionals.ConditionalsLiveHov
|
||||
import org.springframework.ide.vscode.boot.java.data.DataRepositorySymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaCodeLensEngine;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaCompletionEngine;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaDocumentHighlightEngine;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaDocumentSymbolHandler;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaHoverProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaReferencesHandler;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaWorkspaceSymbolHandler;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.CodeLensProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.CompletionProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.HighlightProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
|
||||
@@ -44,6 +46,7 @@ import org.springframework.ide.vscode.boot.java.requestmapping.LiveAppURLSymbolP
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingHoverProvider;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.WebfluxHandlerCodeLensProvider;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.WebfluxRouteHighlightProdivder;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.WebfluxRouterSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.scope.ScopeCompletionProcessor;
|
||||
import org.springframework.ide.vscode.boot.java.snippets.JavaSnippet;
|
||||
@@ -61,6 +64,7 @@ import org.springframework.ide.vscode.commons.languageserver.composable.Language
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.CodeLensHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DocumentHighlightHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.HoverHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LSFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.ReferencesHandler;
|
||||
@@ -94,6 +98,7 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
private JavaProjectFinder projectFinder;
|
||||
private BootJavaHoverProvider hoverProvider;
|
||||
private CodeLensHandler codeLensHandler;
|
||||
private DocumentHighlightHandler highlightsEngine;
|
||||
|
||||
public BootJavaLanguageServerComponents(SimpleLanguageServer server, LSFactory<BootLanguageServerParams> _params) {
|
||||
this.server = server;
|
||||
@@ -151,7 +156,10 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
|
||||
codeLensHandler = createCodeLensEngine();
|
||||
documents.onCodeLens(codeLensHandler);
|
||||
|
||||
|
||||
highlightsEngine = createDocumentHighlightEngine();
|
||||
documents.onDocumentHighlight(highlightsEngine);
|
||||
|
||||
workspaceService.onDidChangeConfiguraton(settings -> {
|
||||
config.handleConfigurationChange(settings);
|
||||
if (config.isBootHintsEnabled()) {
|
||||
@@ -180,6 +188,10 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
return codeLensHandler;
|
||||
}
|
||||
|
||||
public DocumentHighlightHandler getDocumentHighlightHandler() {
|
||||
return highlightsEngine;
|
||||
}
|
||||
|
||||
private void initialize(InitializeParams params) {
|
||||
this.indexer.initialize(server.getWorkspaceRoots());
|
||||
}
|
||||
@@ -314,6 +326,13 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
|
||||
return new BootJavaCodeLensEngine(this, codeLensProvider);
|
||||
}
|
||||
|
||||
protected BootJavaDocumentHighlightEngine createDocumentHighlightEngine() {
|
||||
Collection<HighlightProvider> highlightProvider = new ArrayList<>();
|
||||
highlightProvider.add(new WebfluxRouteHighlightProdivder(this));
|
||||
|
||||
return new BootJavaDocumentHighlightEngine(this, highlightProvider);
|
||||
}
|
||||
|
||||
public ProjectObserver getProjectObserver() {
|
||||
return projectObserver;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* 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.ide.vscode.boot.java.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DocumentHighlightHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class BootJavaDocumentHighlightEngine implements DocumentHighlightHandler {
|
||||
|
||||
private BootJavaLanguageServerComponents server;
|
||||
private Collection<HighlightProvider> highlightProviders;
|
||||
|
||||
public BootJavaDocumentHighlightEngine(BootJavaLanguageServerComponents server, Collection<HighlightProvider> highlightProviders) {
|
||||
this.server = server;
|
||||
this.highlightProviders = highlightProviders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends DocumentHighlight>> handle(TextDocumentPositionParams params) {
|
||||
SimpleTextDocumentService documents = server.getTextDocumentService();
|
||||
String docURI = params.getTextDocument().getUri();
|
||||
|
||||
if (documents.get(docURI) != null) {
|
||||
TextDocument doc = documents.get(docURI).copy();
|
||||
try {
|
||||
CompletableFuture<List<? extends DocumentHighlight>> highlightResult = provideDocumentHighlights(doc);
|
||||
if (highlightResult != null) {
|
||||
return highlightResult;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return SimpleTextDocumentService.NO_HIGHLIGHTS;
|
||||
}
|
||||
|
||||
private CompletableFuture<List<? extends DocumentHighlight>> provideDocumentHighlights(TextDocument document) {
|
||||
return server.getCompilationUnitCache().withCompilationUnit(document, cu -> {
|
||||
|
||||
if (cu != null) {
|
||||
List<DocumentHighlight> result = new ArrayList<>();
|
||||
for (HighlightProvider highlightProvider : highlightProviders) {
|
||||
highlightProvider.provideHighlights(document, cu, result);
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return CompletableFuture.completedFuture(result);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* 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.ide.vscode.boot.java.handlers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public interface HighlightProvider {
|
||||
|
||||
public void provideHighlights(TextDocument document, CompilationUnit cu, List<DocumentHighlight> resultAccumulator);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* 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.ide.vscode.boot.java.requestmapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.HighlightProvider;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class WebfluxRouteHighlightProdivder implements HighlightProvider {
|
||||
|
||||
public WebfluxRouteHighlightProdivder(BootJavaLanguageServerComponents server) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideHighlights(TextDocument document, CompilationUnit cu,
|
||||
List<DocumentHighlight> resultAccumulator) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user