SpringIndexElement serialization. Initial Structure view in VSCode
Signed-off-by: aboyko <alex.boyko@broadcom.com>
This commit is contained in:
@@ -27,6 +27,8 @@ import * as springBootAgent from './copilot/springBootAgent';
|
||||
import { applyLspEdit } from "./copilot/guideApply";
|
||||
import { isLlmApiReady } from "./copilot/util";
|
||||
import CopilotRequest, { logger } from "./copilot/copilotRequest";
|
||||
import { ExplorerTreeProvider } from "./explorer/explorer-tree-provider";
|
||||
import { StructureManager } from "./explorer/structure-tree-manager";
|
||||
|
||||
const PROPERTIES_LANGUAGE_ID = "spring-boot-properties";
|
||||
const YAML_LANGUAGE_ID = "spring-boot-properties-yaml";
|
||||
@@ -149,7 +151,39 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
|
||||
context.subscriptions.push(startDebugSupport());
|
||||
|
||||
return commons.activate(options, context).then(client => {
|
||||
commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
|
||||
|
||||
// Spring structure tree in the Explorer view
|
||||
/*
|
||||
Requires the following code to be added in the `package.json` to
|
||||
1. Declare view:
|
||||
"views": {
|
||||
"explorer": [
|
||||
{
|
||||
"id": "explorer.spring",
|
||||
"name": "Spring",
|
||||
"when": "java:serverMode || workbenchState==empty",
|
||||
"contextualTitle": "Spring",
|
||||
"icon": "resources/logo.png"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
2. Menu item (toolbar action) on the explorer view delegating to the command
|
||||
"view/title": [
|
||||
{
|
||||
"command": "vscode-spring-boot.structure.refresh",
|
||||
"when": "view == explorer.spring",
|
||||
"group": "navigation@5"
|
||||
}
|
||||
],
|
||||
|
||||
*/
|
||||
// const structureManager = new StructureManager();
|
||||
// const explorerTreeProvider = new ExplorerTreeProvider(structureManager);
|
||||
// context.subscriptions.push(window.createTreeView('explorer.spring', { treeDataProvider: explorerTreeProvider, showCollapseAll: true }));
|
||||
// context.subscriptions.push(commands.registerCommand("vscode-spring-boot.structure.refresh", () => structureManager.refresh()));
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
|
||||
// Boot LS is fully started
|
||||
registerClasspathService(client);
|
||||
registerJavaDataService(client);
|
||||
@@ -162,8 +196,8 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
|
||||
// Register TestJars launch support
|
||||
context.subscriptions.push(startTestJarSupport());
|
||||
|
||||
}));
|
||||
commands.registerCommand('vscode-spring-boot.ls.stop', () => client.stop());
|
||||
})));
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-boot.ls.stop', () => client.stop()));
|
||||
liveHoverUi.activate(client, options, context);
|
||||
rewrite.activate(client, options, context);
|
||||
setLogLevelUi.activate(client, options, context);
|
||||
@@ -175,9 +209,13 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
|
||||
|
||||
registerMiscCommands(context);
|
||||
|
||||
commands.registerCommand('vscode-spring-boot.agent.apply', applyLspEdit);
|
||||
context.subscriptions.push(commands.registerCommand('vscode-spring-boot.agent.apply', applyLspEdit));
|
||||
|
||||
return new ApiManager(client).api;
|
||||
const api = new ApiManager(client).api
|
||||
|
||||
// context.subscriptions.push(api.getSpringIndex().onSpringIndexUpdated(e => structureManager.refresh()));
|
||||
|
||||
return api;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ interface InjectionPoint {
|
||||
|
||||
interface SpringIndex {
|
||||
readonly beans: (params: BeansParams) => Promise<Bean[]>;
|
||||
readonly getBeans: (uri: Uri) => Promise<Bean[]>;
|
||||
readonly onSpringIndexUpdated: Event<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { commands, Uri } from "vscode";
|
||||
import { commands } from "vscode";
|
||||
import { Emitter, LanguageClient } from "vscode-languageclient/node";
|
||||
import {Bean, BeansParams, ExtensionAPI, SpringIndex} from "./api";
|
||||
import {Bean, BeansParams, ExtensionAPI} from "./api";
|
||||
import {
|
||||
LiveProcess,
|
||||
LiveProcessConnectedNotification,
|
||||
@@ -55,9 +55,6 @@ export class ApiManager {
|
||||
return await commands.executeCommand(COMMAND_LIVEDATA_REFRESH_METRICS, query);
|
||||
}
|
||||
|
||||
const COMMAND_BEANS = "sts/spring-boot/beans";
|
||||
const getBeans: (Uri) => Promise<Bean[]> = async (projectUri: Uri) => await commands.executeCommand(COMMAND_BEANS, projectUri.toString());
|
||||
|
||||
client.onNotification(LiveProcessConnectedNotification.type, (process: LiveProcess) => this.onDidLiveProcessConnectEmitter.fire(process));
|
||||
client.onNotification(LiveProcessDisconnectedNotification.type, (process: LiveProcess) => this.onDidLiveProcessDisconnectEmitter.fire(process));
|
||||
client.onNotification(LiveProcessUpdatedNotification.type, (process: LiveProcess) => this.onDidLiveProcessUpdateEmitter.fire(process));
|
||||
@@ -73,8 +70,7 @@ export class ApiManager {
|
||||
|
||||
const getSpringIndex = () => ({
|
||||
onSpringIndexUpdated,
|
||||
beans,
|
||||
getBeans
|
||||
beans
|
||||
})
|
||||
|
||||
this.api = {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { CancellationToken, commands, Event, EventEmitter, ProviderResult, TreeDataProvider, TreeItem, TreeItemCollapsibleState } from "vscode";
|
||||
import { StructureManager } from "./structure-tree-manager";
|
||||
import { DocumentNode, ProjectNode, SpringNode } from "./nodes";
|
||||
import * as Path from "path";
|
||||
|
||||
export class ExplorerTreeProvider implements TreeDataProvider<SpringNode> {
|
||||
|
||||
private emitter: EventEmitter<undefined | SpringNode | SpringNode[]>;
|
||||
public readonly onDidChangeTreeData: Event<undefined | SpringNode | SpringNode[]>;
|
||||
|
||||
constructor(private manager: StructureManager) {
|
||||
this.emitter = new EventEmitter<undefined | SpringNode | SpringNode[]>();
|
||||
this.onDidChangeTreeData = this.emitter.event;
|
||||
this.manager.onDidChange(e => this.emitter.fire(e));
|
||||
}
|
||||
|
||||
getTreeItem(element: SpringNode): TreeItem | Thenable<TreeItem> {
|
||||
return element.getTreeItem();
|
||||
}
|
||||
|
||||
getChildren(element?: SpringNode): ProviderResult<SpringNode[]> {
|
||||
if (element) {
|
||||
return element.children;
|
||||
}
|
||||
return this.getRootElements();
|
||||
}
|
||||
|
||||
getRootElements(): ProviderResult<SpringNode[]> {
|
||||
return this.manager.rootElements;
|
||||
}
|
||||
|
||||
// getParent?(element: SpringNode): ProviderResult<SpringNode> {
|
||||
// throw new Error("Method not implemented.");
|
||||
// }
|
||||
|
||||
// resolveTreeItem?(item: TreeItem, element: SpringNode, token: CancellationToken): ProviderResult<TreeItem> {
|
||||
// throw new Error("Method not implemented.");
|
||||
// }
|
||||
|
||||
}
|
||||
222
vscode-extensions/vscode-spring-boot/lib/explorer/nodes.ts
Normal file
222
vscode-extensions/vscode-spring-boot/lib/explorer/nodes.ts
Normal file
@@ -0,0 +1,222 @@
|
||||
import { ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
|
||||
import { Location, Range } from "vscode-languageclient";
|
||||
|
||||
export class SpringNode {
|
||||
constructor(readonly children: SpringNode[]) {}
|
||||
getTreeItem(): TreeItem {
|
||||
return new TreeItem("<node>", this.computeState(TreeItemCollapsibleState.Expanded));
|
||||
}
|
||||
computeState(defaultState: TreeItemCollapsibleState.Collapsed | TreeItemCollapsibleState.Expanded): TreeItemCollapsibleState {
|
||||
return Array.isArray(this.children) && this.children.length ? defaultState : TreeItemCollapsibleState.None;
|
||||
}
|
||||
}
|
||||
|
||||
export class ProjectNode extends SpringNode {
|
||||
constructor(readonly name: string, children: SpringNode[]) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.name;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class DocumentNode extends SpringNode {
|
||||
constructor(readonly docURI: Uri, children: SpringNode[]) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = undefined; // let VSCode derive the label from the resource URI
|
||||
item.resourceUri = this.docURI;
|
||||
item.iconPath = ThemeIcon.File;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class AotProcessorNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly type: string,
|
||||
readonly docUri: Uri
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.type;
|
||||
item.resourceUri = this.docUri;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class BeanMethodContainerNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly type: string,
|
||||
readonly location: Location,
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.type;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class BeanRegistrarNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly name: string,
|
||||
readonly type: string,
|
||||
readonly location: Location,
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.name;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class ConfigPropertyNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly name: string,
|
||||
readonly type: string,
|
||||
readonly range: Range
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.name;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class EventListenerNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly eventType: string,
|
||||
readonly location: Location,
|
||||
readonly containerBeanType: string,
|
||||
readonly annotations: AnnotationMetadata[]
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.eventType;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class EventPublisherNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly eventType: string,
|
||||
readonly location: Location,
|
||||
readonly eventTypesFromHierarchy: string[]
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.eventType;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class QueryMethodNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly methodName: string,
|
||||
readonly queryString: string,
|
||||
readonly range: Range
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.methodName;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class RequestMappingNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly path: string,
|
||||
readonly httpMethods: string[],
|
||||
readonly contentTypes: string[],
|
||||
readonly acceptTypes: string[],
|
||||
readonly symbolLabel: string,
|
||||
readonly range: Range
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.path;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export class WebfluxRoutesNode extends RequestMappingNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
path: string,
|
||||
httpMethods: string[],
|
||||
contentTypes: string[],
|
||||
acceptTypes: string[],
|
||||
symbolLabel: string,
|
||||
range: Range,
|
||||
readonly ranges: Range[]
|
||||
) {
|
||||
super(children, path, httpMethods, contentTypes, acceptTypes, symbolLabel, range);
|
||||
}
|
||||
}
|
||||
|
||||
export class BeanNode extends SpringNode {
|
||||
constructor(
|
||||
children: SpringNode[],
|
||||
readonly name: string,
|
||||
readonly type: string,
|
||||
readonly location: Location,
|
||||
readonly injectionPoints: InjectionPoint[],
|
||||
readonly supertypes: string[],
|
||||
readonly annotations: AnnotationMetadata[],
|
||||
readonly isConfiguration: boolean,
|
||||
readonly symbolLabel: string
|
||||
) {
|
||||
super(children);
|
||||
}
|
||||
getTreeItem(): TreeItem {
|
||||
const item = super.getTreeItem();
|
||||
item.label = this.name;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
export interface InjectionPoint {
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly location: Location;
|
||||
readonly annotations: AnnotationMetadata[];
|
||||
}
|
||||
|
||||
export interface AnnotationMetadata {
|
||||
readonly annotationType: string;
|
||||
readonly isMetaAnnotation: boolean;
|
||||
readonly location: Location;
|
||||
readonly attributes: {[key: string]: AnnotationAttributeValue[]};
|
||||
}
|
||||
|
||||
export interface AnnotationAttributeValue {
|
||||
readonly name: string;
|
||||
readonly location: Location;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import { commands, EventEmitter, Event, Uri } from "vscode";
|
||||
import { AotProcessorNode, BeanMethodContainerNode, BeanNode, BeanRegistrarNode, ConfigPropertyNode, DocumentNode, EventListenerNode, EventPublisherNode, ProjectNode, QueryMethodNode, RequestMappingNode, SpringNode, WebfluxRoutesNode } from "./nodes";
|
||||
|
||||
const SPRING_STRUCTURE_CMD = "sts/spring-boot/structure";
|
||||
|
||||
export class StructureManager {
|
||||
|
||||
private _rootElements: Thenable<SpringNode[]>
|
||||
private _onDidChange: EventEmitter<SpringNode | undefined> = new EventEmitter<SpringNode | undefined>();
|
||||
|
||||
get rootElements(): Thenable<SpringNode[]> {
|
||||
return this._rootElements;
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this._rootElements = commands.executeCommand(SPRING_STRUCTURE_CMD).then(json => {
|
||||
const nodes = this.parseArray(json);
|
||||
this._onDidChange.fire(undefined);
|
||||
return nodes;
|
||||
});
|
||||
}
|
||||
|
||||
private parseNode(json: any): SpringNode | undefined {
|
||||
if (typeof (json._internal_node_type) === 'string') {
|
||||
switch (json._internal_node_type) {
|
||||
case "ProjectElement":
|
||||
return new ProjectNode(json.projectName as string, this.parseArray(json.children));
|
||||
case "DocumentElement":
|
||||
return new DocumentNode(Uri.parse(json.docURI as string), this.parseArray(json.children));
|
||||
case "Bean":
|
||||
return new BeanNode(
|
||||
this.parseArray(json.children),
|
||||
json.name,
|
||||
json.type,
|
||||
json.location,
|
||||
json.injectionPoints,
|
||||
json.supertypes,
|
||||
json.annotations,
|
||||
json.isConfiguration,
|
||||
json.symbolLabel
|
||||
);
|
||||
case "AotProcessorElement":
|
||||
return new AotProcessorNode(
|
||||
this.parseArray(json.children),
|
||||
json.name,
|
||||
Uri.parse(json.docUri)
|
||||
);
|
||||
case "BeanMethodContainerElement":
|
||||
return new BeanMethodContainerNode(
|
||||
this.parseArray(json.children),
|
||||
json.type,
|
||||
json.location
|
||||
);
|
||||
case "BeanRegistrarElement":
|
||||
return new BeanRegistrarNode(
|
||||
this.parseArray(json.children),
|
||||
json.name,
|
||||
json.type,
|
||||
json.location
|
||||
|
||||
);
|
||||
case "ConfigPropertyIndexElement":
|
||||
return new ConfigPropertyNode(
|
||||
this.parseArray(json.children),
|
||||
json.name,
|
||||
json.type,
|
||||
json.range
|
||||
);
|
||||
case "EventListenerIndexElement":
|
||||
return new EventListenerNode(
|
||||
this.parseArray(json.children),
|
||||
json.eventType,
|
||||
json.location,
|
||||
json.containerBeanType,
|
||||
json.annotations
|
||||
);
|
||||
case "EventPublisherIndexElement":
|
||||
return new EventPublisherNode(
|
||||
this.parseArray(json.children),
|
||||
json.eventType,
|
||||
json.location,
|
||||
json.eventTypesFromHierarchy,
|
||||
);
|
||||
case "QueryMethodIndexElement":
|
||||
return new QueryMethodNode(
|
||||
this.parseArray(json.children),
|
||||
json.methodName,
|
||||
json.queryString,
|
||||
json.range
|
||||
);
|
||||
case "RequestMappingIndexElement":
|
||||
return new RequestMappingNode(
|
||||
this.parseArray(json.children),
|
||||
json.path,
|
||||
json.httpMethods,
|
||||
json.contentTypes,
|
||||
json.acceptTypes,
|
||||
json.symbolLabel,
|
||||
json.range
|
||||
);
|
||||
case "WebfluxRouteElementRangesIndexElement":
|
||||
return new WebfluxRoutesNode(
|
||||
this.parseArray(json.children),
|
||||
json.path,
|
||||
json.httpMethods,
|
||||
json.contentTypes,
|
||||
json.acceptTypes,
|
||||
json.symbolLabel,
|
||||
json.range,
|
||||
json.ranges
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private parseArray(json: any): SpringNode[] {
|
||||
return Array.isArray(json) ? (json as []).map(j => this.parseNode(j)).filter(e => !!e) : [];
|
||||
}
|
||||
|
||||
public get onDidChange(): Event<SpringNode | undefined> {
|
||||
return this._onDidChange.event;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user