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

@@ -12,7 +12,6 @@ package org.springframework.ide.eclipse.boot.dash;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.core.net.proxy.IProxyService;
@@ -33,7 +32,6 @@ import org.springframework.ide.eclipse.boot.core.BootPropertyTester;
import org.springframework.ide.eclipse.boot.dash.di.SimpleDIContext;
import org.springframework.ide.eclipse.boot.dash.liveprocess.CommandInfo;
import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveProcessCommandsExecutor;
import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveProcessCommandsExecutor.Server;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModelContext;
import org.springframework.ide.eclipse.boot.dash.model.BootDashViewModel;
import org.springframework.ide.eclipse.boot.dash.model.DefaultBootDashModelContext;
@@ -45,7 +43,6 @@ import org.springframework.ide.eclipse.boot.dash.util.RunStateTracker.RunStateLi
import org.springframework.ide.eclipse.boot.launch.BootLaunchConfigurationDelegate;
import org.springsource.ide.eclipse.commons.livexp.util.Log;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
@@ -194,7 +191,7 @@ public class BootDashActivator extends AbstractUIPlugin {
return InstanceScope.INSTANCE.getNode(PLUGIN_ID);
}
private final RunStateListener<ILaunchConfiguration> RUN_STATE_LISTENER = new RunStateListener<ILaunchConfiguration>() {
private final RunStateListener<ILaunchConfiguration> RUN_STATE_LISTENER = new RunStateListener<>() {
@Override
public void stateChanged(ILaunchConfiguration owner) {
@@ -211,9 +208,6 @@ public class BootDashActivator extends AbstractUIPlugin {
for (IProcess p : l.getProcesses()) {
String pid = p.getAttribute(IProcess.ATTR_PROCESS_ID);
if (pid != null) {
List<Server> servers = LiveProcessCommandsExecutor.getDefault()
.getLanguageServers();
CommandInfo cmd = new CommandInfo("sts/livedata/connect",
Map.of("processKey", pid));
@@ -221,7 +215,8 @@ public class BootDashActivator extends AbstractUIPlugin {
// "VirtualMachine.list()" call may not list the newly created process which means the process is gone and triggers disconnect.
// If lifecycle management is enabled the ready state seem to be a great indicator of a boot process fully started.
// TODO: explore health endpoint perhaps instead of ready state under Admin endpoint.
Flux.fromIterable(servers).flatMap(s -> Mono.delay(Duration.ofMillis(500)).then(s.executeCommand(cmd))).subscribe();
// Flux.fromIterable(servers).flatMap(s -> Mono.delay(Duration.ofMillis(500)).then(s.executeCommand(cmd))).subscribe();
Mono.delay(Duration.ofMillis(500)).then(LiveProcessCommandsExecutor.getDefault().executeCommand(cmd)).subscribe();
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Pivotal Software, Inc.
* Copyright (c) 2019, 2023 Pivotal Software, 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
@@ -10,14 +10,17 @@
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.liveprocess;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4e.LanguageServers.LanguageServerProjectExecutor;
import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import com.google.common.collect.ImmutableList;
@@ -29,46 +32,43 @@ public final class DefaultLiveProcessCommandExecutor implements LiveProcessComma
private static final String CMD_LIST_PROCESSES = "sts/livedata/listProcesses";
private class DefaultServer implements Server {
private LanguageServer ls;
public DefaultServer(LanguageServer ls) {
this.ls = ls;
}
@Override
@SuppressWarnings("unchecked")
public Flux<CommandInfo> listCommands() {
return Mono.fromFuture(ls.getWorkspaceService().executeCommand(new ExecuteCommandParams(
CMD_LIST_PROCESSES,
ImmutableList.of()
)))
.flatMapIterable(list -> (List<?>)list)
.map(_cmdInfo -> {
Map<String,String> map = (Map<String, String>) _cmdInfo;
return new CommandInfo(map.get("action"), map);
});
}
@Override
public Mono<Void> executeCommand(CommandInfo cmd) {
return Mono.fromRunnable(() -> ls.getWorkspaceService().executeCommand(new ExecuteCommandParams(
cmd.command,
ImmutableList.of(cmd.info)
)));
}
@SuppressWarnings("unchecked")
@Override
public Flux<CommandInfo> listCommands() {
List<CompletableFuture<List<CommandInfo>>> futures = getLanguageServers().computeAll(ls -> ls.getWorkspaceService().executeCommand(new ExecuteCommandParams(
CMD_LIST_PROCESSES,
ImmutableList.of()
)).thenApply(o -> {
if (o instanceof List) {
List<?> list = (List<?>) o;
return list.stream().map(_cmdInfo -> {
Map<String,String> map = (Map<String, String>) _cmdInfo;
return new CommandInfo(map.get("action"), map);
}).collect(Collectors.toList());
}
return Collections.<CommandInfo>emptyList();
}));
Flux<CommandInfo> f = Flux.fromIterable(futures).flatMap(fo -> Mono.fromFuture(fo).flatMapIterable(l -> l));
return f;
}
@Override
public List<Server> getLanguageServers() {
return LanguageServiceAccessor.getActiveLanguageServers(cap -> {
public Mono<Void> executeCommand(CommandInfo cmd) {
return Mono.fromFuture(getLanguageServers().collectAll(ls -> ls.getWorkspaceService().executeCommand(new ExecuteCommandParams(
cmd.command,
ImmutableList.of(cmd.info)
))).thenAccept(null));
}
private LanguageServerProjectExecutor getLanguageServers() {
return LanguageServers.forProject(null).withFilter(cap -> {
ExecuteCommandOptions commandCap = cap.getExecuteCommandProvider();
if (commandCap!=null) {
List<String> supportedCommands = commandCap.getCommands();
return supportedCommands!=null && supportedCommands.contains(CMD_LIST_PROCESSES);
}
return false;
})
.stream()
.map(DefaultServer::new)
.collect(Collectors.toList());
}).withPreferredServer(LanguageServersRegistry.getInstance()
.getDefinition("org.eclipse.languageserver.languages.springboot"));
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal Software, Inc.
* Copyright (c) 2019, 2023 Pivotal Software, 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
@@ -20,7 +20,6 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.springframework.ide.eclipse.boot.dash.BootDashActivator;
import org.springframework.ide.eclipse.boot.dash.liveprocess.LiveProcessCommandsExecutor.Server;
import org.springframework.ide.eclipse.boot.dash.model.BootDashElement;
import org.springframework.ide.eclipse.boot.dash.model.BootDashModel.ElementStateListener;
import org.springframework.ide.eclipse.boot.dash.model.RunState;
@@ -35,8 +34,6 @@ import org.springsource.ide.eclipse.commons.livexp.util.Log;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import reactor.core.publisher.Flux;
public class LiveDataConnectionManagementActions extends AbstractDisposable implements DynamicSubMenuSupplier {
private static final IAction DUMMY_ACTION = new Action("No matching processes") {
@@ -75,12 +72,10 @@ public class LiveDataConnectionManagementActions extends AbstractDisposable impl
public class ExecuteCommandAction extends AbstractBootDashElementsAction {
private String projectName;
private String label;
private Server server;
private CommandInfo commandInfo;
public ExecuteCommandAction(Server server, CommandInfo commandInfo) {
public ExecuteCommandAction(CommandInfo commandInfo) {
super(params);
this.server = server;
this.commandInfo = commandInfo;
String command = commandInfo.command;
int lastSlash = command.lastIndexOf("/");
@@ -113,7 +108,7 @@ public class LiveDataConnectionManagementActions extends AbstractDisposable impl
@Override
public void run() {
try {
server.executeCommand(commandInfo).block(Duration.ofSeconds(2));
liveProcessCmds.executeCommand(commandInfo).block(Duration.ofSeconds(2));
} catch (Exception e) {
Log.log(e);
}
@@ -128,7 +123,7 @@ public class LiveDataConnectionManagementActions extends AbstractDisposable impl
this.params = params;
this.liveProcessCmds = params.getLiveProcessCmds();
ObservableSet<BootDashElement> selection = params.getSelection().getElements();
this.isEnabled = addDisposableChild(new LiveExpression<Boolean>(false) {
this.isEnabled = addDisposableChild(new LiveExpression<>(false) {
ElementStateListener elementStateListener = (BootDashElement e) -> {
refresh();
@@ -178,12 +173,7 @@ public class LiveDataConnectionManagementActions extends AbstractDisposable impl
};
}
try {
List<LiveProcessCommandsExecutor.Server> servers = liveProcessCmds.getLanguageServers();
return Flux.fromIterable(servers)
.flatMap((Server server) ->
server.listCommands()
.map(cmdInfo -> new ExecuteCommandAction(server, cmdInfo))
)
return liveProcessCmds.listCommands().map(cmdInfo -> new ExecuteCommandAction(cmdInfo))
.filter(filter)
.cast(IAction.class)
.collect(Collectors.toList())

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Pivotal Software, Inc.
* Copyright (c) 2019, 2023 Pivotal Software, 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
@@ -10,21 +10,15 @@
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.liveprocess;
import java.util.List;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface LiveProcessCommandsExecutor {
interface Server {
Flux<CommandInfo> listCommands();
Mono<Void> executeCommand(CommandInfo cmd);
}
Flux<CommandInfo> listCommands();
Mono<Void> executeCommand(CommandInfo cmd);
static LiveProcessCommandsExecutor getDefault() {
return new DefaultLiveProcessCommandExecutor();
}
List<Server> getLanguageServers();
}