added reference handler mechanism
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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.commons.languageserver.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.ReferenceParams;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ReferencesHandler {
|
||||
|
||||
CompletableFuture<List<? extends Location>> handle(ReferenceParams params);
|
||||
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
private HoverHandler hoverHandler = null;
|
||||
|
||||
private DefinitionHandler definitionHandler;
|
||||
private ReferencesHandler referencesHandler;
|
||||
|
||||
public SimpleTextDocumentService(SimpleLanguageServer server) {
|
||||
this.server = server;
|
||||
@@ -99,6 +100,11 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
this.definitionHandler = h;
|
||||
}
|
||||
|
||||
public synchronized void onRefeences(ReferencesHandler h) {
|
||||
Assert.isNull("A references handler is already set, multiple handlers not supported yet", referencesHandler);
|
||||
this.referencesHandler = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all documents this service is tracking, generally these are the documents that have been opened / changed,
|
||||
* and not yet closed.
|
||||
@@ -204,8 +210,8 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
}
|
||||
|
||||
public final static CompletionList NO_COMPLETIONS = new CompletionList(false, Collections.emptyList());
|
||||
|
||||
public final static CompletableFuture<Hover> NO_HOVER = CompletableFuture.completedFuture(new Hover(ImmutableList.of(), null));
|
||||
public final static CompletableFuture<List<? extends Location>> NO_REFERENCES = CompletableFuture.completedFuture(ImmutableList.of());
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
|
||||
@@ -253,6 +259,10 @@ public class SimpleTextDocumentService implements TextDocumentService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
|
||||
ReferencesHandler h = this.referencesHandler;
|
||||
if (h != null) {
|
||||
return h.handle(params);
|
||||
}
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user