Export public API in LightWeight mode
See original GitHub issueBackground
We recently introduced LightWeight mode in VS Code Java. The LightWeight mode is used for those who just want to do some ‘easy’ work in VS Code, for example: reading the code…
But the users might find that if they take a certain action (i.e. starting a debug session) in LightWeight mode, nothing happens…
Root Cause
In the activate() method of VS Code Java, we will return the public APIs as a promise, which will only be resolved when the Standard language server is ready. That means the promise will never be resolved if VS Code Java is in LightWeight mode. Thus, the extension will be in an inactivated status (You can tell it by triggerring the command Developer: Show Running Extensions). All the third-party extensions which depend on VS Code Java will then, keep waiting.
Proposed change
Also resolve the public API in whatever server mode, besides that, adding the following new API:
{
serverMode: ServerMode
onDidServerModeChange: Event<ServerMode>
}
Note:
- The APIs like:
getProjectSettings,getClasspaths,isTestFileandonDidClasspathUpdatewill return an empty-like value inLightWeightmode, since so far there is no scenarios shows these APIs need to work inLightWeightmode. (We can change the impelmentation when necessary) - In
LightWeightmode, all the calls to the command:java.execute.workspaceCommandwill just show a warning message in the console and directly return. - It’s recommended for all the the third-party extensions to consume the
serverModefield in the APIs set and change the behavior if it’sLightWeightServiceReady.
How to adopt the new APIs
Check the serverMode when get the resolved extension API, and run properly. For example, you may not want to provide some features when Java Language Server is in lightweight mode.
Also do not forget to register a listener to listen the server mode changing event:
const extension: Extension<any> | undefined = extensions.getExtension('redhat.java');
if (extension && extension.isActive) {
const extensionApi: any = extension.exports;
if (!extensionApi) {
return;
}
if (extensionApi.onDidChangeServerMode) {
const onDidChangeServerMode: Event<string> = extensionApi.onDidChangeServerMode;
context.subscriptions.push(onDidChangeServerMode(async (mode: string) => {
// do something according to current server mode
}));
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (1 by maintainers)

Top Related StackOverflow Question
@jblievremont Yes, so far VS Code Java supports switch from
LightWeightmode toStandardmode without a restart. User can achieve this by for example, click the 🚀 button in the status bar(when the user is in LightWeight).Thank you @jdneo, I can indeed see the server switching to
Hybridand thenStandard.