added commands to manually deal with live hover process connections

This commit is contained in:
Martin Lippert
2019-09-05 09:17:00 +02:00
parent 2481a372c1
commit 8c1fe4c664
15 changed files with 571 additions and 46 deletions

View File

@@ -358,4 +358,12 @@
</extension>
-->
<extension
point="org.eclipse.ui.quickAccess">
<computer
class="org.springframework.tooling.boot.ls.commands.LiveProcessCommandsQuickAccessProvider"
name="Spring - Live Process Information"
requiresUIAccess="false"/>
</extension>
</plugin>

View File

@@ -0,0 +1,99 @@
/*******************************************************************************
* Copyright (c) 2019 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.quickaccess.QuickAccessElement;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class LiveProcessCommandElement extends QuickAccessElement {
public static final String COMMAND_LIST_PROCESSES = "sts/livedata/listProcesses";
public static final String COMMAND_CONNECT = "sts/livedata/connect";
public static final String COMMAND_REFRESH = "sts/livedata/refresh";
public static final String COMMAND_DISCONNECT = "sts/livedata/disconnect";
private final String processKey;
private final String label;
private final String action;
public LiveProcessCommandElement(String processKey, String label, String action) {
super();
this.processKey = processKey;
this.label = label;
this.action = action;
}
@Override
public String getLabel() {
if (COMMAND_REFRESH.equals(action)) {
return "Refresh Live Data for: " + label;
}
else if (COMMAND_CONNECT.equals(action)) {
return "Show live data for: " + label;
}
else if (COMMAND_DISCONNECT.equals(action)) {
return "Disconnect live data from: " + label;
}
else {
// error case
return "No live data action avaiable for: " + label;
}
}
@Override
public ImageDescriptor getImageDescriptor() {
return null;
}
@Override
public String getId() {
return processKey + action;
}
@Override
public void execute() {
System.out.println("EXECUTE THE COMMAND !!!");
List<@NonNull LanguageServer> usedLanguageServers = LanguageServiceAccessor.getActiveLanguageServers(serverCapabilities -> true);
if (usedLanguageServers.isEmpty()) {
return;
}
ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(this.action);
List<Object> arguments = new ArrayList<>();
Map<String, String> argumentMap = new HashMap<>();
argumentMap.put("processKey", this.processKey);
arguments.add(argumentMap);
commandParams.setArguments(arguments);
CompletableFuture.allOf(usedLanguageServers.stream().map(ls ->
ls.getWorkspaceService().executeCommand(commandParams)).toArray(CompletableFuture[]::new)).join();
}
}

View File

@@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2019 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.quickaccess.IQuickAccessComputer;
import org.eclipse.ui.quickaccess.IQuickAccessComputerExtension;
import org.eclipse.ui.quickaccess.QuickAccessElement;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class LiveProcessCommandsQuickAccessProvider implements IQuickAccessComputer, IQuickAccessComputerExtension {
private List<@NonNull LanguageServer> usedLanguageServers;
@Override
public QuickAccessElement[] computeElements() {
return new QuickAccessElement[0];
}
@Override
public void resetState() {
}
@Override
public boolean needsRefresh() {
return this.usedLanguageServers == null;
}
@Override
public QuickAccessElement[] computeElements(String query, IProgressMonitor monitor) {
System.out.println("COMPUTE QUICK ACCESS ELEMENTS !!!");
this.usedLanguageServers = LanguageServiceAccessor.getActiveLanguageServers(serverCapabilities -> true);
if (usedLanguageServers.isEmpty()) {
return new QuickAccessElement[0];
}
ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(LiveProcessCommandElement.COMMAND_LIST_PROCESSES);
List<QuickAccessElement> res = Collections.synchronizedList(new ArrayList<>());
CompletableFuture.allOf(usedLanguageServers.stream().map(ls ->
ls.getWorkspaceService().executeCommand(commandParams).thenAcceptAsync(commandResult ->
createCommandItems(res, commandResult))).toArray(CompletableFuture[]::new)).join();
System.out.println("quick access elements computed: " + res.size());
for (QuickAccessElement quickAccessElement : res) {
System.out.println("generated element: " + quickAccessElement.getLabel());
}
return res.toArray(new QuickAccessElement[res.size()]);
}
private void createCommandItems(List<QuickAccessElement> res, Object commandResult) {
System.out.println(commandResult);
if (commandResult instanceof List<?>) {
List<?> allCommands = (List<?>) commandResult;
for (Object command : allCommands) {
if (command instanceof Map<?, ?>) {
res.add(createCommandItem((Map<?, ?>)command));
}
}
}
}
private LiveProcessCommandElement createCommandItem(Map<?, ?> command) {
String processKey = (String) command.get("processKey");
String label = (String) command.get("label");
String action = (String) command.get("action");
return new LiveProcessCommandElement(processKey, label, action);
}
}