added workspace symbol handler infrastructure

This commit is contained in:
Martin Lippert
2017-08-25 17:11:14 +02:00
parent 4c3ae63cf6
commit 88b47b262d
3 changed files with 67 additions and 4 deletions

View File

@@ -248,6 +248,9 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
CODE_ACTION_COMMAND_ID
)));
}
if (hasWorkspaceSymbolHandler()) {
c.setWorkspaceSymbolProvider(true);
}
return c;
}
@@ -272,6 +275,10 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
return quickfixRegistry!=null && quickfixRegistry.hasFixes();
}
private boolean hasWorkspaceSymbolHandler() {
return getWorkspaceService().hasWorkspaceSymbolHandler();
}
@Override
public CompletableFuture<Object> shutdown() {
return CompletableFuture.completedFuture(new Object());
@@ -299,7 +306,7 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
}
public SimpleWorkspaceService createWorkspaceService() {
return new SimpleWorkspaceService();
return new SimpleWorkspaceService(this);
}
@Override

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2017 Pivotal, Inc.
* Copyright (c) 2016, 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
@@ -8,7 +8,6 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.languageserver.util;
import java.util.List;
@@ -23,14 +22,34 @@ import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.springframework.ide.vscode.commons.util.Assert;
import com.google.common.collect.ImmutableList;
import reactor.core.publisher.Mono;
public class SimpleWorkspaceService implements WorkspaceService {
private SimpleLanguageServer server;
private ListenerList<Settings> configurationListeners = new ListenerList<>();
private ExecuteCommandHandler executeCommandHandler;
private WorkspaceSymbolHandler workspaceSymbolHandler;
public SimpleWorkspaceService(SimpleLanguageServer server) {
this.server = server;
}
@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
throw new UnsupportedOperationException();
WorkspaceSymbolHandler workspaceSymbolHandler = this.workspaceSymbolHandler;
if (workspaceSymbolHandler==null) {
return CompletableFuture.completedFuture(ImmutableList.of());
}
return Mono.fromCallable(() -> {
server.waitForReconcile();
return workspaceSymbolHandler.handle(params);
})
.toFuture()
.thenApply(l -> (List<? extends SymbolInformation>)l);
}
@Override
@@ -58,4 +77,14 @@ public class SimpleWorkspaceService implements WorkspaceService {
Assert.isNull("A executeCommandHandler is already set, multiple handlers not supported yet", this.executeCommandHandler);
this.executeCommandHandler = handler;
}
public synchronized void onWorkspaceSymbol(WorkspaceSymbolHandler h) {
Assert.isNull("A WorkspaceSymbolHandler is already set, multiple handlers not supported yet", workspaceSymbolHandler);
this.workspaceSymbolHandler = h;
}
public boolean hasWorkspaceSymbolHandler() {
return this.workspaceSymbolHandler != null;
}
}

View File

@@ -0,0 +1,27 @@
/*******************************************************************************
* 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 org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import com.google.common.collect.ImmutableList;
@FunctionalInterface
public interface WorkspaceSymbolHandler {
WorkspaceSymbolHandler NO_SYMBOLS = (params) -> ImmutableList.of();
List<? extends SymbolInformation> handle(WorkspaceSymbolParams params);
}