Adopt API removal in LSP4E

This commit is contained in:
aboyko
2023-06-05 19:03:29 -04:00
parent b59b6123dd
commit 7a6603f520
12 changed files with 143 additions and 186 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2023 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
@@ -11,15 +11,14 @@
package org.springframework.tooling.ls.eclipse.commons;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.LanguageServers;
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")
@@ -27,19 +26,11 @@ public class LSP4ECommandExecutor implements ClientCommandExecutor {
@Override
public Object executeClientCommand(String id, Object... params) throws Exception {
List<LanguageServer> commandHandlers = LanguageServiceAccessor.getActiveLanguageServers(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+"'");
Optional<Object> res = LanguageServers.forProject(null).withFilter(handlesCommand(id)).computeFirst(
ls -> ls.getWorkspaceService().executeCommand(new ExecuteCommandParams(id, Arrays.asList(params))))
.get(2, TimeUnit.SECONDS);
return res.orElseThrow(() -> new UnsupportedOperationException(
"No language server has registered to handle command '" + id + "'"));
}
private Predicate<ServerCapabilities> handlesCommand(String id) {