add basic support for document highlight feature to common ls pieces
This commit is contained in:
@@ -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