Beans model extension API for VSCode
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2023 VMware, 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:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.spring;
|
||||
|
||||
public class BeansParams {
|
||||
|
||||
private String projectName;
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,11 +14,13 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
|
||||
|
||||
@JsonSegment("spring")
|
||||
public interface SpringModelService {
|
||||
|
||||
@JsonRequest
|
||||
default CompletableFuture<List<Bean>> beans(String project) {
|
||||
default CompletableFuture<List<Bean>> beans(BeansParams params) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguage
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.BeansParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.SpringModelService;
|
||||
import org.springframework.ide.vscode.commons.util.Futures;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
@@ -706,7 +707,8 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<Bean>> beans(String projectName) {
|
||||
public CompletableFuture<List<Bean>> beans(BeansParams params) {
|
||||
String projectName = params.getProjectName();
|
||||
CompletableFuture<Void> latestTask = this.latestScheduledTaskByProject.get(projectName);
|
||||
|
||||
if (latestTask != null) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
||||
import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.BeansParams;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
@@ -65,7 +66,9 @@ public class SpringModelServiceTest {
|
||||
|
||||
@Test
|
||||
void testSpringModelServiceBeansForNonExistingProject() throws Exception {
|
||||
CompletableFuture<List<Bean>> result = indexer.beans("random-project");
|
||||
BeansParams params = new BeansParams();
|
||||
params.setProjectName("random-project");
|
||||
CompletableFuture<List<Bean>> result = indexer.beans(params);
|
||||
|
||||
List<Bean> list = result.get();
|
||||
assertNull(list);
|
||||
@@ -73,7 +76,9 @@ public class SpringModelServiceTest {
|
||||
|
||||
@Test
|
||||
void testBeansNameAndTypeFromBeanAnnotatedMethod() throws Exception {
|
||||
CompletableFuture<List<Bean>> result = indexer.beans("test-spring-indexing");
|
||||
BeansParams params = new BeansParams();
|
||||
params.setProjectName("test-spring-indexing");
|
||||
CompletableFuture<List<Bean>> result = indexer.beans(params);
|
||||
|
||||
List<Bean> beans = result.get(5, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Event } from "vscode";
|
||||
import { LanguageClient } from "vscode-languageclient/node";
|
||||
import { LiveProcess } from "./notification";
|
||||
import {Location} from "vscode-languageclient";
|
||||
|
||||
export interface ExtensionAPI {
|
||||
readonly client: LanguageClient;
|
||||
@@ -55,7 +56,16 @@ export interface ExtensionAPI {
|
||||
*
|
||||
* Returns a list of processKeys.
|
||||
*/
|
||||
readonly listConnectedProcesses: () => Promise<LiveProcess[]>
|
||||
readonly listConnectedProcesses: () => Promise<LiveProcess[]>;
|
||||
|
||||
/**
|
||||
* Spring Model capable of computing beans and other static spring related information
|
||||
*
|
||||
* Returns Spring Model object.
|
||||
*/
|
||||
readonly getSpringModel: () => SpringModel;
|
||||
|
||||
readonly onSpringModelUpdated: Event<void>;
|
||||
}
|
||||
|
||||
interface LiveProcessDataQuery {
|
||||
@@ -82,4 +92,26 @@ interface MetricsQuery extends LiveProcessDataQuery {
|
||||
endpoint: "metrics";
|
||||
metricName: string;
|
||||
tags?: string;
|
||||
}
|
||||
|
||||
interface Bean {
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly location: Location;
|
||||
readonly injectionPoints: InjectionPoint[];
|
||||
readonly supertypes: string[];
|
||||
}
|
||||
|
||||
interface InjectionPoint {
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly location: Location;
|
||||
}
|
||||
|
||||
interface SpringModel {
|
||||
readonly beans: (params: BeansParams) => Promise<Bean[]>;
|
||||
}
|
||||
|
||||
interface BeansParams {
|
||||
projectName: string;
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
import { commands, Uri } from "vscode";
|
||||
import { Emitter, LanguageClient } from "vscode-languageclient/node";
|
||||
import { ExtensionAPI } from "./api";
|
||||
import { LiveProcess, LiveProcessConnectedNotification, LiveProcessDisconnectedNotification, LiveProcessUpdatedNotification, LiveProcessGcPausesMetricsUpdatedNotification, LiveProcessMemoryMetricsUpdatedNotification } from "./notification";
|
||||
import {Bean, BeansParams, ExtensionAPI, SpringModel} from "./api";
|
||||
import {
|
||||
LiveProcess,
|
||||
LiveProcessConnectedNotification,
|
||||
LiveProcessDisconnectedNotification,
|
||||
LiveProcessUpdatedNotification,
|
||||
LiveProcessGcPausesMetricsUpdatedNotification,
|
||||
LiveProcessMemoryMetricsUpdatedNotification,
|
||||
SpringModelUpdatedNotification
|
||||
} from "./notification";
|
||||
import VSCode from "vscode";
|
||||
import {RequestType} from "vscode-languageclient";
|
||||
|
||||
export class ApiManager {
|
||||
public api: ExtensionAPI;
|
||||
@@ -10,6 +20,7 @@ export class ApiManager {
|
||||
private onDidLiveProcessUpdateEmitter: Emitter<LiveProcess> = new Emitter<LiveProcess>();
|
||||
private onDidLiveProcessGcPausesMetricsUpdateEmitter: Emitter<LiveProcess> = new Emitter<LiveProcess>();
|
||||
private onDidLiveProcessMemoryMetricsUpdateEmitter: Emitter<LiveProcess> = new Emitter<LiveProcess>();
|
||||
private onSpringModelUpdateEmitter: Emitter<void> = new Emitter<void>();
|
||||
|
||||
public constructor(client: LanguageClient) {
|
||||
const onDidLiveProcessConnect = this.onDidLiveProcessConnectEmitter.event;
|
||||
@@ -17,6 +28,7 @@ export class ApiManager {
|
||||
const onDidLiveProcessUpdate = this.onDidLiveProcessUpdateEmitter.event;
|
||||
const onDidLiveProcessGcPausesMetricsUpdate = this.onDidLiveProcessGcPausesMetricsUpdateEmitter.event;
|
||||
const onDidLiveProcessMemoryMetricsUpdate = this.onDidLiveProcessMemoryMetricsUpdateEmitter.event;
|
||||
const onSpringModelUpdated = this.onSpringModelUpdateEmitter.event;
|
||||
|
||||
const COMMAND_LIVEDATA_GET = "sts/livedata/get";
|
||||
const getLiveProcessData = async (query) => {
|
||||
@@ -49,6 +61,17 @@ export class ApiManager {
|
||||
client.onNotification(LiveProcessGcPausesMetricsUpdatedNotification.type, (process: LiveProcess) => this.onDidLiveProcessGcPausesMetricsUpdateEmitter.fire(process));
|
||||
client.onNotification(LiveProcessMemoryMetricsUpdatedNotification.type, (process: LiveProcess) => this.onDidLiveProcessMemoryMetricsUpdateEmitter.fire(process));
|
||||
|
||||
client.onNotification(SpringModelUpdatedNotification.type, () => this.onSpringModelUpdateEmitter.fire());
|
||||
|
||||
const beansRequestType = new RequestType<BeansParams, Bean[], void>('spring/beans');
|
||||
const beans = (params: BeansParams) => {
|
||||
return client.sendRequest(beansRequestType, params);
|
||||
}
|
||||
|
||||
const getSpringModel = () => ({
|
||||
beans
|
||||
})
|
||||
|
||||
this.api = {
|
||||
client,
|
||||
onDidLiveProcessConnect,
|
||||
@@ -56,11 +79,13 @@ export class ApiManager {
|
||||
onDidLiveProcessUpdate,
|
||||
onDidLiveProcessMemoryMetricsUpdate,
|
||||
onDidLiveProcessGcPausesMetricsUpdate,
|
||||
onSpringModelUpdated,
|
||||
getLiveProcessData,
|
||||
refreshLiveProcessData,
|
||||
getLiveProcessMetricsData,
|
||||
refreshLiveProcessMetricsData,
|
||||
listConnectedProcesses,
|
||||
getSpringModel
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,8 @@ export namespace LiveProcessGcPausesMetricsUpdatedNotification {
|
||||
|
||||
export namespace LiveProcessMemoryMetricsUpdatedNotification {
|
||||
export const type = new NotificationType<LiveProcess>('sts/liveprocess/memory/metrics/updated');
|
||||
}
|
||||
|
||||
export namespace SpringModelUpdatedNotification {
|
||||
export const type = new NotificationType<void>('spring/model/updated');
|
||||
}
|
||||
Reference in New Issue
Block a user