Re-work java services registration for VSCode
This commit is contained in:
@@ -66,9 +66,9 @@ public class ClasspathListenerManager {
|
||||
JsonArray event = (JsonArray) arg;
|
||||
|
||||
String projectUri = event.get(0).getAsString();
|
||||
log.debug("projectUri = {}", event);
|
||||
log.debug("projectUri = {}", projectUri);
|
||||
String name = event.get(1).getAsString();
|
||||
log.debug("name = {}", event);
|
||||
log.debug("name = {}", name);
|
||||
boolean deleted = event.get(2).getAsBoolean();
|
||||
log.debug("deleted = {}", deleted);
|
||||
|
||||
@@ -88,9 +88,9 @@ public class ClasspathListenerManager {
|
||||
// that don't provide batched event support (e.g. IDEA client may only adopt this
|
||||
// later, or not adopt it at all).
|
||||
String projectUri = ((JsonElement) args.get(0)).getAsString();
|
||||
log.debug("projectUri = {}", args);
|
||||
log.debug("projectUri = {}", projectUri);
|
||||
String name = ((JsonElement) args.get(1)).getAsString();
|
||||
log.debug("name = {}", args);
|
||||
log.debug("name = {}", name);
|
||||
boolean deleted = ((JsonElement)args.get(2)).getAsBoolean();
|
||||
log.debug("deleted = {}", deleted);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018, 2022 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2023 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
|
||||
@@ -55,6 +55,8 @@ import reactor.core.Disposables;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class JdtLsProjectCache implements InitializableJavaProjectsService, ServerCapabilityInitializer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JdtLsProjectCache.class);
|
||||
|
||||
private static final String CMD_SPRING_BOOT_ENABLE_CLASSPATH_LISTENING = "sts.vscode-spring-boot.enableClasspathListening";
|
||||
|
||||
@@ -65,7 +67,6 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService, Serv
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
private Map<String, IJavaProject> table = new HashMap<String, IJavaProject>();
|
||||
private Logger log = LoggerFactory.getLogger(JdtLsProjectCache.class);
|
||||
private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
final private ClasspathListener CLASSPATH_LISTENER = new JstLsClasspathListener();
|
||||
|
||||
@@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -52,6 +53,7 @@ public class ProjectGenerationsValidationTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void testProjectsInfoFromSpringIo() throws Exception {
|
||||
String url = "https://spring.io/api/projects";
|
||||
SpringProjectsClient client = new SpringProjectsClient(url);
|
||||
|
||||
@@ -12,11 +12,6 @@ export function registerClasspathService(client : LanguageClient) : void {
|
||||
const javaExt = VSCode.extensions.getExtension('redhat.java');
|
||||
const javaApi = javaExt?.exports;
|
||||
|
||||
if (javaApi) {
|
||||
VSCode.commands.executeCommand(CMD_STS_ENABLE_CLASSPATH_LISTENER, javaApi.serverMode === JDT_SERVER_STANDARD_MODE);
|
||||
javaApi.onDidServerModeChange(e => VSCode.commands.executeCommand(CMD_STS_ENABLE_CLASSPATH_LISTENER, javaApi.serverMode === JDT_SERVER_STANDARD_MODE));
|
||||
}
|
||||
|
||||
let addRequest = new RequestType<ClasspathListenerParams, ClasspathListenerResponse, void>("sts/addClasspathListener");
|
||||
client.onRequest(addRequest, async (params: ClasspathListenerParams) => {
|
||||
if (javaApi?.serverMode === 'LightWeight') {
|
||||
@@ -30,6 +25,11 @@ export function registerClasspathService(client : LanguageClient) : void {
|
||||
return <ClasspathListenerResponse> await VSCode.commands.executeCommand("java.execute.workspaceCommand", "sts.java.removeClasspathListener", params.callbackCommandId);
|
||||
});
|
||||
|
||||
if (javaApi) {
|
||||
VSCode.commands.executeCommand(CMD_STS_ENABLE_CLASSPATH_LISTENER, javaApi.serverMode === JDT_SERVER_STANDARD_MODE);
|
||||
javaApi.onDidServerModeChange(e => VSCode.commands.executeCommand(CMD_STS_ENABLE_CLASSPATH_LISTENER, javaApi.serverMode === JDT_SERVER_STANDARD_MODE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface ClasspathListenerParams {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import {activate, ActivatorOptions} from './launch-util';
|
||||
import {JVM} from '@pivotal-tools/jvm-launch-utils';
|
||||
import { registerClasspathService } from './classpath';
|
||||
import {registerJavaDataService} from "./java-data";
|
||||
|
||||
export {activate, JVM, ActivatorOptions};
|
||||
export {activate, JVM, ActivatorOptions, registerClasspathService, registerJavaDataService};
|
||||
|
||||
@@ -18,9 +18,7 @@ import * as P2C from 'vscode-languageclient/lib/common/protocolConverter';
|
||||
import {HighlightService, HighlightParams} from './highlight-service';
|
||||
import { log } from 'util';
|
||||
import { JVM, findJvm, findJdk } from '@pivotal-tools/jvm-launch-utils';
|
||||
import { registerClasspathService } from './classpath';
|
||||
import {HighlightCodeLensProvider} from "./code-lens-service";
|
||||
import {registerJavaDataService} from "./java-data";
|
||||
|
||||
const p2c = P2C.createConverter(undefined, false, false);
|
||||
|
||||
@@ -42,7 +40,6 @@ export interface ActivatorOptions {
|
||||
highlightCodeLensSettingKey?: string;
|
||||
explodedLsJarData?: ExplodedLsJarData;
|
||||
vmArgs?: string[];
|
||||
requiresJavaLs?: boolean;
|
||||
}
|
||||
|
||||
export interface ExplodedLsJarData {
|
||||
@@ -392,10 +389,6 @@ function setupLanguageClient(context: VSCode.ExtensionContext, createServer: Ser
|
||||
}
|
||||
return {applied: true};
|
||||
});
|
||||
if (options.requiresJavaLs) {
|
||||
registerClasspathService(client);
|
||||
registerJavaDataService(client);
|
||||
}
|
||||
return Promise.resolve(client);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import * as rewrite from './rewrite';
|
||||
import { startDebugSupport } from './debug-config-provider';
|
||||
import { ApiManager } from "./apiManager";
|
||||
import { ExtensionAPI } from "./api";
|
||||
import {registerClasspathService} from "@pivotal-tools/commons-vscode/lib/classpath";
|
||||
import {registerJavaDataService} from "@pivotal-tools/commons-vscode/lib/java-data";
|
||||
|
||||
const PROPERTIES_LANGUAGE_ID = "spring-boot-properties";
|
||||
const YAML_LANGUAGE_ID = "spring-boot-properties-yaml";
|
||||
@@ -114,11 +116,13 @@ export function activate(context: VSCode.ExtensionContext): Thenable<ExtensionAP
|
||||
},
|
||||
initializationOptions: () => ({
|
||||
workspaceFolders: workspace.workspaceFolders ? workspace.workspaceFolders.map(f => f.uri.toString()) : null,
|
||||
enableJdtClasspath: true
|
||||
// Do not enable JDT classpath listeners at the startup - classpath service would enable it later if needed based on the Java extension mode
|
||||
// Classpath service registration requires commands to be registered and Boot LS needs to register classpath
|
||||
// listeners when client has callbacks for STS4 extension java related messages registered via JDT classpath and Data Service registration
|
||||
enableJdtClasspath: false
|
||||
})
|
||||
},
|
||||
highlightCodeLensSettingKey: 'boot-java.highlight-codelens.on',
|
||||
requiresJavaLs: true
|
||||
highlightCodeLensSettingKey: 'boot-java.highlight-codelens.on'
|
||||
};
|
||||
|
||||
// Register launch config contributior to java debug launch to be able to connect to JMX
|
||||
@@ -127,6 +131,8 @@ export function activate(context: VSCode.ExtensionContext): Thenable<ExtensionAP
|
||||
return commons.activate(options, context).then(client => {
|
||||
VSCode.commands.registerCommand('vscode-spring-boot.ls.start', () => client.start().then(() => {
|
||||
// Boot LS is fully started
|
||||
registerClasspathService(client);
|
||||
registerJavaDataService(client);
|
||||
|
||||
// Force classpath listener to be enabled. Boot LS can only be launched iff classpath is available and there Spring-Boot on the classpath somewhere.
|
||||
VSCode.commands.executeCommand('sts.vscode-spring-boot.enableClasspathListening', true);
|
||||
|
||||
Reference in New Issue
Block a user