Some tweaks to PR 751

This commit is contained in:
Kris De Volder
2022-04-05 15:52:11 -07:00
parent f332ae4e69
commit 37e495f20c
9 changed files with 53 additions and 18 deletions

View File

@@ -36,6 +36,16 @@ import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
*/
public interface STS4LanguageClient extends LanguageClient {
@JsonNotification("sts/liveprocess/connected")
void liveProcessConnected(String processKey);
@JsonNotification("sts/liveprocess/disconnected")
void liveProcessDisconnected(String processKey);
@JsonNotification("sts/liveprocess/updated")
void liveProcessDataUpdated(String processKey);
@JsonNotification("sts/highlight")
void highlight(HighlightParams highlights);
@@ -76,5 +86,6 @@ public interface STS4LanguageClient extends LanguageClient {
@JsonRequest("sts/javaCodeComplete")
CompletableFuture<List<JavaCodeCompleteData>> javaCodeComplete(JavaCodeCompleteParams params);
}

View File

@@ -296,7 +296,6 @@ public class LanguageServerHarness {
@Override
public void showMessage(MessageParams messageParams) {
// TODO Auto-generated method stub
}
@Override
@@ -406,6 +405,17 @@ public class LanguageServerHarness {
return CompletableFuture.completedFuture(Collections.emptyList());
}
@Override
public void liveProcessConnected(String processKey) {
}
@Override
public void liveProcessDisconnected(String processKey) {
}
@Override
public void liveProcessDataUpdated(String processKey) {
}
});
}

View File

@@ -125,8 +125,8 @@ public class BootLanguageServerBootApp {
}
@Bean
SpringProcessLiveDataProvider liveDataProvider() {
return new SpringProcessLiveDataProvider();
SpringProcessLiveDataProvider liveDataProvider(SimpleLanguageServer server) {
return new SpringProcessLiveDataProvider(server);
}
@Bean

View File

@@ -229,8 +229,8 @@ public class SpringProcessConnectorLocal {
}
}
public boolean isConnected(String processKey) {
return this.processConnectorService.isConnected(processKey);
public boolean isKnownProcessKey(String processKey) {
return this.processConnectorService.isKnownProcessKey(processKey);
}
private String getProcessID(VirtualMachineDescriptor descriptor) {

View File

@@ -45,7 +45,6 @@ public class SpringProcessConnectorService {
private int progressIdKey = 0;
private int maxRetryCount;
private int retryDelayInSeconds;
public SpringProcessConnectorService(SimpleLanguageServer server, SpringProcessLiveDataProvider liveDataProvider) {
this.liveDataProvider = liveDataProvider;
@@ -135,7 +134,7 @@ public class SpringProcessConnectorService {
.filter((connector) -> connectedSuccess.get(connector.getProcessKey())).toArray(SpringProcessConnector[]::new);
}
public boolean isConnected(String processKey) {
public boolean isKnownProcessKey(String processKey) {
return this.connectors.containsKey(processKey);
}
@@ -162,13 +161,13 @@ public class SpringProcessConnectorService {
catch (Exception e) {
log.info("problem occured during process connect", e);
if (retryNo < maxRetryCount && isConnected(processKey)) {
if (retryNo < maxRetryCount && isKnownProcessKey(processKey)) {
scheduleConnect(progressTask, processKey, connector, retryDelayInSeconds, TimeUnit.SECONDS, retryNo + 1);
} else {
progressTask.progressDone();
// Send message to client if maximum retries reached on error
if (isConnected(processKey)) {
if (isKnownProcessKey(processKey)) {
diagnosticService.diagnosticEvent(ShowMessageException
.error("Failed to connect to process " + processKey + " after retries: " + retryNo, e));
}
@@ -229,7 +228,7 @@ public class SpringProcessConnectorService {
log.info("problem occured during process live data refresh", e);
if (retryNo < maxRetryCount && isConnected(processKey)) {
if (retryNo < maxRetryCount && isKnownProcessKey(processKey)) {
scheduleRefresh(progressTask, processKey, connector, retryDelayInSeconds, TimeUnit.SECONDS,
retryNo + 1);
}
@@ -237,7 +236,7 @@ public class SpringProcessConnectorService {
progressTask.progressDone();
// Send message to client if maximum retries reached on error
if (isConnected(processKey)) {
if (isKnownProcessKey(processKey)) {
diagnosticService.diagnosticEvent(ShowMessageException
.error("Failed to refresh live data from process " + processKey + " after retries: " + retryNo, e));

View File

@@ -16,6 +16,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
/**
* @author Martin Lippert
*/
@@ -23,8 +25,10 @@ public class SpringProcessLiveDataProvider {
private final ConcurrentMap<String, SpringProcessLiveData> liveData;
private final List<SpringProcessLiveDataChangeListener> listeners;
private final SimpleLanguageServer server;
public SpringProcessLiveDataProvider() {
public SpringProcessLiveDataProvider(SimpleLanguageServer server) {
this.server = server;
this.liveData = new ConcurrentHashMap<>();
this.listeners = new CopyOnWriteArrayList<>();
}
@@ -40,25 +44,25 @@ public class SpringProcessLiveDataProvider {
*/
public boolean add(String processKey, SpringProcessLiveData liveData) {
SpringProcessLiveData oldData = this.liveData.putIfAbsent(processKey, liveData);
if (oldData == null) {
announceChangedLiveData();
server.getClient().liveProcessConnected(processKey);
}
return oldData == null;
}
public void remove(String processKey) {
SpringProcessLiveData removed = this.liveData.remove(processKey);
if (removed != null) {
announceChangedLiveData();
server.getClient().liveProcessDisconnected(processKey);
}
}
public void update(String processKey, SpringProcessLiveData liveData) {
this.liveData.put(processKey, liveData);
announceChangedLiveData();
server.getClient().liveProcessDataUpdated(processKey);
}
@@ -73,7 +77,6 @@ public class SpringProcessLiveDataProvider {
private void announceChangedLiveData() {
SpringProcessLiveData[] latestLiveData = getLatestLiveData();
SpringProcessLiveDataChangeEvent event = new SpringProcessLiveDataChangeEvent(latestLiveData);
for (SpringProcessLiveDataChangeListener listener : this.listeners) {
listener.liveDataChanged(event);
}

View File

@@ -14,11 +14,15 @@ export interface ExtensionAPI {
*/
readonly onDidLiveProcessDisconnect: Event<string>
/**
* An event which fires on live process data change. Payload is processKey.
*/
readonly onDidLiveProcessUpdate: Event<string>
/**
* A command to get live process data.
*/
readonly getLiveProcessData: (query: SimpleQuery | BeansQuery) => Promise<any>
}
interface LiveProcessDataQuery {

View File

@@ -1,16 +1,18 @@
import { commands, Uri } from "vscode";
import { Emitter, LanguageClient } from "vscode-languageclient/node";
import { ExtensionAPI } from "./api";
import { LiveProcessConnectedNotification, LiveProcessDisconnectedNotification } from "./notification";
import { LiveProcessConnectedNotification, LiveProcessDisconnectedNotification, LiveProcessUpdatedNotification } from "./notification";
export class ApiManager {
public api: ExtensionAPI;
private onDidLiveProcessConnectEmitter: Emitter<string> = new Emitter<string>();
private onDidLiveProcessDisconnectEmitter: Emitter<string> = new Emitter<string>();
private onDidLiveProcessUpdateEmitter: Emitter<string> = new Emitter<string>();
public constructor(private client: LanguageClient) {
const onDidLiveProcessConnect = this.onDidLiveProcessConnectEmitter.event;
const onDidLiveProcessDisconnect = this.onDidLiveProcessDisconnectEmitter.event;
const onDidLiveProcessUpdate = this.onDidLiveProcessUpdateEmitter.event;
const COMMAND_LIVEDATA_GET = "sts/livedata/get";
const getLiveProcessData = async (query) => {
@@ -20,11 +22,13 @@ export class ApiManager {
// TODO: STS server should send corresponding notification back.
client.onNotification(LiveProcessConnectedNotification.type, (processKey: string) => this.onDidLiveProcessConnectEmitter.fire(processKey));
client.onNotification(LiveProcessDisconnectedNotification.type, (processKey: string) => this.onDidLiveProcessDisconnectEmitter.fire(processKey));
client.onNotification(LiveProcessUpdatedNotification.type, (processKey: string) => this.onDidLiveProcessUpdateEmitter.fire(processKey));
this.api = {
client,
onDidLiveProcessConnect,
onDidLiveProcessDisconnect,
onDidLiveProcessUpdate,
getLiveProcessData
};
}

View File

@@ -7,3 +7,7 @@ export namespace LiveProcessConnectedNotification {
export namespace LiveProcessDisconnectedNotification {
export const type = new NotificationType<string>('sts/liveprocess/disconnected');
}
export namespace LiveProcessUpdatedNotification {
export const type = new NotificationType<string>('sts/liveprocess/updated');
}