Merge branch 'eclipse-classpath-provider'
This commit is contained in:
@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.8.0",
|
||||
org.eclipse.jface.text,
|
||||
com.google.guava,
|
||||
org.eclipse.debug.ui,
|
||||
org.eclipse.ui.console
|
||||
org.eclipse.ui.console,
|
||||
org.springframework.tooling.jdt.ls.commons
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.springframework.tooling.ls.eclipse.commons,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.lsp4e.LanguageServiceAccessor;
|
||||
import org.eclipse.lsp4j.ExecuteCommandOptions;
|
||||
import org.eclipse.lsp4j.ExecuteCommandParams;
|
||||
import org.eclipse.lsp4j.ServerCapabilities;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
import org.springframework.tooling.jdt.ls.commons.classpath.ClientCommandExecutor;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class LSP4ECommandExecutor implements ClientCommandExecutor {
|
||||
|
||||
@Override
|
||||
public Object executeClientCommand(String id, Object... params) throws Exception {
|
||||
List<LanguageServer> commandHandlers = LanguageServiceAccessor.getLanguageServers(handlesCommand(id));
|
||||
if (commandHandlers!=null) {
|
||||
if (commandHandlers.size()==1) {
|
||||
LanguageServer handler = commandHandlers.get(0);
|
||||
return handler
|
||||
.getWorkspaceService()
|
||||
.executeCommand(new ExecuteCommandParams(id, Arrays.asList(params)))
|
||||
.get(2, TimeUnit.SECONDS);
|
||||
} else if (commandHandlers.size() > 1) {
|
||||
throw new IllegalStateException("Multiple language servers have registered to handle command '"+id+"'");
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException("No language server has registered to handle command '"+id+"'");
|
||||
}
|
||||
|
||||
private Predicate<ServerCapabilities> handlesCommand(String id) {
|
||||
return (serverCaps) -> {
|
||||
ExecuteCommandOptions executeCommandProvider = serverCaps.getExecuteCommandProvider();
|
||||
if (executeCommandProvider!=null) {
|
||||
return executeCommandProvider.getCommands().contains(id);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.progress.UIJob;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
import org.springframework.tooling.jdt.ls.commons.classpath.ReusableClasspathListenerHandler;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -47,6 +48,13 @@ import com.google.common.collect.ImmutableMap;
|
||||
@SuppressWarnings("restriction")
|
||||
public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4LanguageClient {
|
||||
|
||||
private static ReusableClasspathListenerHandler classpathService = new ReusableClasspathListenerHandler(new LSP4ECommandExecutor());
|
||||
|
||||
|
||||
public STS4LanguageClientImpl() {
|
||||
System.out.println("Instantiatin STS4LanguageClientImpl");
|
||||
}
|
||||
|
||||
private static final String ANNOTION_TYPE_ID = "org.springframework.tooling.bootinfo";
|
||||
|
||||
class UpdateHighlights extends UIJob {
|
||||
@@ -178,12 +186,11 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
|
||||
return Futures.fail(new UnsupportedOperationException("Not implemented"));
|
||||
return CompletableFuture.completedFuture(classpathService.addClasspathListener(params.getCallbackCommandId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
|
||||
return Futures.fail(new UnsupportedOperationException("Not implemented"));
|
||||
public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams params) {
|
||||
return CompletableFuture.completedFuture(classpathService.removeClasspathListener(params.getCallbackCommandId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package org.springframework.tooling.jdt.ls.commons.classpath;
|
||||
|
||||
public interface ClientCommandExecutor {
|
||||
Object executeClientCommand(String id, Object... params);
|
||||
Object executeClientCommand(String id, Object... params) throws Exception;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user