Signed-off-by: aboyko <alex.boyko@broadcom.com>
This commit is contained in:
aboyko
2025-04-09 10:56:17 -04:00
parent e7e2015ac4
commit 260e9c9d49
5 changed files with 44 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* Copyright (c) 2024, 2025 Broadcom, 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
@@ -12,6 +12,8 @@ package org.springframework.ide.vscode.boot.app;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.java.commands.SpringIndexCommands;
import org.springframework.ide.vscode.boot.java.commands.WorkspaceBootExecutableProjects;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
@@ -22,5 +24,10 @@ public class CommandsConfig {
@Bean WorkspaceBootExecutableProjects workspaceBootProjects(SimpleLanguageServer server, JavaProjectFinder projectFinder, SpringSymbolIndex symbolIndex) {
return new WorkspaceBootExecutableProjects(server, projectFinder, symbolIndex);
}
@Bean SpringIndexCommands springIndexCommands(SimpleLanguageServer server, JavaProjectFinder projectFinder, SpringMetamodelIndex symbolIndex) {
return new SpringIndexCommands(server, symbolIndex, projectFinder);
}
}

View File

@@ -0,0 +1,27 @@
package org.springframework.ide.vscode.boot.java.commands;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import com.google.gson.JsonElement;
public class SpringIndexCommands {
private static final String PROJECT_BEANS_CMD = "sts/spring-boot/beans";
public SpringIndexCommands(SimpleLanguageServer server, SpringMetamodelIndex metamodelIndex, JavaProjectFinder projectFinder) {
server.onCommand(PROJECT_BEANS_CMD, params -> {
String projectUri = ((JsonElement) params.getArguments().get(0)).getAsString();
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(projectUri)).orElse(null);
return project == null ? CompletableFuture.completedFuture(List.of())
: server.getAsync().execute(() -> metamodelIndex.getBeansOfProject(project.getElementName()));
});
}
}

View File

@@ -52,8 +52,8 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
],
checkjvm: (context: ExtensionContext, jvm: commons.JVM) => {
let version = jvm.getMajorVersion();
if (version < 17) {
throw Error(`Spring Tools Language Server requires Java 17 or higher to be launched. Current Java version is ${version}`);
if (version < 21) {
throw Error(`Spring Tools Language Server requires Java 21 or higher to be launched. Current Java version is ${version}`);
}
if (!jvm.isJdk()) {

View File

@@ -1,4 +1,4 @@
import { Event } from "vscode";
import { Event, Uri } from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { LiveProcess } from "./notification";
import {Location} from "vscode-languageclient";
@@ -109,6 +109,7 @@ interface InjectionPoint {
interface SpringIndex {
readonly beans: (params: BeansParams) => Promise<Bean[]>;
readonly getBeans: (uri: Uri) => Promise<Bean[]>;
readonly onSpringIndexUpdated: Event<void>;
}

View File

@@ -55,6 +55,9 @@ 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));
@@ -70,7 +73,8 @@ export class ApiManager {
const getSpringIndex = () => ({
onSpringIndexUpdated,
beans
beans,
getBeans
})
this.api = {