For MicroProfile tools for vscode (https://github.com/redhat-developer/vscode-microprofile) we require that the java language server is started in standard mode, and we want to display a warning / prompt users to switch to standard if they are in lightweight. We want to do this when MicroProfile tools activates before it launches its own language server that depends on vscode-java.
I am wondering the best way to do this.
Looking at the serverMode from vscode-java's api (https://github.com/redhat-developer/vscode-java/blob/master/src/extension.api.ts#L103). Before a project has been imported serverMode is returned as LightWeight initially and then switches over to Standard later if the user selects to import the project. So if i am checking for LightWeight while MicroProfile tools is starting up and display a warning, the user gets an unnecessary warning while the language server is starting up. Because MicroProfile tools will see that the user is in LightWeight mode and display a warning to switch to Standard when really the Standard mode server is in the process of being launched.
I also looked at using the java.server.launchMode setting to see if it is set to lightweight, since for the most part if it is set to Hybrid or Standard the language server will eventually end up in standard mode. The one problem I see with this is that before a project is imported if someone has their launch mode set to hybrid, and they decide to click import later i think the server will stay in lightweight mode. So vscode-microprofile will not work and they would not get an error message in that case since the java.server.launchMode is set to Hybrid
Is there a way to detect if the java language server has launched in standard more or is in the process of launching in standard mode so I do not need to display a warning to the user.
@fbricon mentioned that @testforstephen, @jdneo and @Eskibear may be able to provide some guidance
Let's say if the user set the launch mode to Hybrid, and for that moment, lightweight server is ready and standard server is still activating. you will get a notification that serverMode is in hybrid:
https://github.com/redhat-developer/vscode-java/blob/master/src/extension.ts#L274-L276
Once the standard server is ready, another notification is emitted that serverMode changes to standard:
So I think you can get the initial value of the serverMode in the resolved API. And listen to the onDidServerModeChange event. Only activate the features of your MicroProfile tools when it's standard.
Feel free to let us know if you have more question. :)
Yes i am doing something like that right now. The problem I am seeing that if someone is using Hybrid the first time someone opens a project / before a project has been imported they are asked by vscode-java if they want to import the project. If someone clicks Yes to import the project and to start the standard language server, vscode-java seems to return lightweight initially, so an extra warning is displayed. I would like to avoid displaying this extra warning that is not needed if it is possible.
For example this sample extension here: https://github.com/rzgry/vscode-java-api-test/blob/master/src/extension.ts
If i open a new java project, I get a prompt from vscode-java to import project and also one from vscode-microprofile to switch language server to Standard while vscode-java is in the process of starting up server in standard mode

I see. Take a look at the implementation. It won't emit Hybrid in this case:
https://github.com/redhat-developer/vscode-java/blob/master/src/extension.ts#L315
That seems an issue that we need to fix.
BTW, I have another question about this: suppose that the Hybrid is emitted after user clicks yes. How will MicroProfile responses to it, given that currently it's a one time check? The event might be emitted after this message pops up right?
So you are saying for a new java project vscode-java starts in Lightweight then will switch to Hybrid after they click Yes to import the project and then to Standard once the standard java ls has started?
You are right that might not fix the problem because the event might be emitted after the message pops up. Do you have any thoughts on a better way to implement this sort of check in vscode-microprofile so that the warning would not be displayed after they click yes to import a project?
Hmm... I can show some examples in our extension. we leverage some UI entries to present this information to our user. For examples:
Project Manager for Java:

Same for Java Test Runner:

And for Debugger for Java, it will check the server mode when the user is trying to launch the program and ask the user to switch the mode.

Basically it's something like: only show the hint when the user do want to use such features.
Yes the problem for vscode-microprofile is that we need to detect the mode and display a warning when the extension is activated since we need the standard java language server for our language server to work.
For example: I think Debugger for Java has the same sort of problem, it is just less noticeable since it is not doing the check when the extension is activated. If I try to use debugger for java, while the Java language server is starting up after importing a new project I get an extra warning message that is not needed because the standard language server is in the process of starting

Then we go back to the origin problem - I can raise a PR to make sure the Hybrid is emitted after the yes is clicked.
So let's focus on: suppose hybrid is emitted after the yes is clicked, how MicroProfile can response to properly. Is it possible to avoid one time check but checking when needed for MicroProfile?
I am not sure if it is possible to avoid the one time check. Because vscode-microprofile starts up its own language server immediately after activation. This language server communicates with the java language server so vscode-java is required in standard mode right after activation of vscode-microprofile.
See: connectToLS in the activate function: https://github.com/redhat-developer/vscode-microprofile/blob/master/src/extension.ts#L35
Maybe I could do something like only check the Java language server mode after a user has opened a file or something. Will have to do some testing.
Great, and please let us know if you have any other request about the API.
@rzgry you can try https://download.jboss.org/jbosstools/jdt.ls/staging/java-0.66.0-2398.vsix, which contains the fix from #1581