vscode-lombok icon indicating copy to clipboard operation
vscode-lombok copied to clipboard

Uninstall vscode-lombok extension should clean up the javaagent from java.jdt.ls.vmargs

Open testforstephen opened this issue 5 years ago • 12 comments
trafficstars

Tried latest VS Code 1.47.1 in both Windows 10 and macOS, the uninstall logic doesn't work. The vmargs keeps the same after uninstall vscode-lombok. Fully restart VS Code has the same behavior. This will break the startup of vscode-java extension after i choose to uninstall and remove vscode-lombok extension.

Also, i see some other potential issues with the current implementation:

  • The current uninstall hook doesn't work in the latest VS Code.
  • The current uninstall hook just hard code the settings.json location for Code, it doesn't cover Code - Insiders.
  • The scope of "java.jdt.ls.vmargs" is window scope, that means it can be shared with remote machine for remote scenarios. But actually the javaagent is a machine specific location, that doesn't work in remote machine.

Modifying vmargs looks some kind of hack, an ideal way is probably passing the javaagent args to Java Language Server dynamically. For example, define the location in package.json, and tell vscode-java to read the args before activating.

testforstephen avatar Jul 17 '20 07:07 testforstephen

@GabrielBB What do you think about it?

testforstephen avatar Jul 21 '20 05:07 testforstephen

Agh, I knew these uninstall issues were going to show up. I opened an issue to vscode almost 2 years ago because there is not a proper way to remove settings on extension uninstall -> https://github.com/microsoft/vscode/issues/45474 . Anyway, the problem I see now in my Mac is that the uninstall hook is getting called only when I force quit vscode. According to this comment they do it this way because the extension might be running in other vscode windows, so they wait until all instances are closed to do cleanups. That really sucks, although I understand the problem.

GabrielBB avatar Jul 21 '20 06:07 GabrielBB

For example, define the location in package.json, and tell vscode-java to read the args before activating.

@testforstephen Interesting. But I don't understand how vscode-java will read that without being in the vmargs. How is going to read from my package.json? I'm not quite getting your example, it seems

GabrielBB avatar Jul 21 '20 07:07 GabrielBB

It needs vscode-java to expose some kind of contribution point for you to add a javaagent.

For example, currently Debugger for Java extensions also works as an extension of vscode-java. And debugger will add a config in package.json as below, and vscode-java will collect such contributions dynamically before starting.

"javaExtensions": [
      "./server/com.microsoft.java.debug.plugin-0.27.0.jar"
],

testforstephen avatar Jul 21 '20 07:07 testforstephen

It needs vscode-java to expose some kind of contribution point for you to add a javaagent.

For example, currently Debugger for Java extensions also works as an extension of vscode-java. And debugger will add a config in package.json as below, and vscode-java will collect such contributions dynamically before starting.

"javaExtensions": [
      "./server/com.microsoft.java.debug.plugin-0.27.0.jar"
],

That would be great!! So are you guys already working on this "javaExtensions" feature?

GabrielBB avatar Jul 21 '20 07:07 GabrielBB

The javaExtensions is already there, but currently it just supports OSGI bundle and loading them as a bundle not a javaagent. Since javaagent is required to added into vmArgs, that's different and needs extra support from vscode-java. Is it possible to make lombok.jar to be a OSGI bundle instead of a javaagent?

testforstephen avatar Jul 21 '20 07:07 testforstephen

The javaExtensions is already there, but currently it just supports OSGI bundle and loading them as a bundle not a javaagent. Since javaagent is required to added into vmArgs, that's different and needs extra support from vscode-java. Is it possible to make lombok.jar to be a OSGI bundle instead of a javaagent?

I'll see what I can do and test it

GabrielBB avatar Jul 21 '20 08:07 GabrielBB

@testforstephen

I created a bundle this way: https://github.com/GabrielBB/vscode-lombok/blob/4079ecd1236d1bca45dd71daa8ecad93e0166e14/package.json#L40

I added javaExtensions like this: https://github.com/GabrielBB/vscode-lombok/blob/4079ecd1236d1bca45dd71daa8ecad93e0166e14/package.json#L32

This is the generated extension, inside you will find the bundle: https://drive.google.com/file/d/1E_krdLaxpbDzR3gb5qy94EMH3im_b4Ig/view?usp=sharing

But it's not working. I'm not sure if vscode-java is picking it up or not. How can I know? You can install the extension I linked if you want to try it :)

GabrielBB avatar Jul 23 '20 15:07 GabrielBB

Oh, it should be picked up by vscode-java. Since the new lombok-bundle.jar is not a real Eclipse plugin, vscode-java won't execute it.

If you want to convert it to an Eclipse OSGI bundle, you need follow the Eclipse plugin style, see how to create an Eclipse plugin.

Also, in current implementation, the lombok.jar is added to vmArgs via -javaagent:jarpath, which will be executed before JVM startup. If you change it to an Eclipse plugin, you might need manually start the lombok agent within your Eclipse plugin activator. This kind of approach is to start a Java agent after JVM startup. See the different approaches to start the agent. https://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html

testforstephen avatar Jul 24 '20 05:07 testforstephen

Oh, it should be picked up by vscode-java. Since the new lombok-bundle.jar is not a real Eclipse plugin, vscode-java won't execute it.

If you want to convert it to an Eclipse OSGI bundle, you need follow the Eclipse plugin style, see how to create an Eclipse plugin.

Also, in current implementation, the lombok.jar is added to vmArgs via -javaagent:jarpath, which will be executed before JVM startup. If you change it to an Eclipse plugin, you might need manually start the lombok agent within your Eclipse plugin activator. This kind of approach is to start a Java agent after JVM startup. See the different approaches to start the agent. https://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html

@rzwitserloot Can you help us, here? We want to use Lombok as a OSGI bundle, this is for the VSCode extension. Would that be possible?

GabrielBB avatar Jul 27 '20 13:07 GabrielBB

@testforstephen If this comment from @rzwitserloot still holds true, then it looks this won't be possible -> https://groups.google.com/d/msg/project-lombok/3RLYvgobEv8/QSMZK8m0exIJ

GabrielBB avatar Jul 27 '20 13:07 GabrielBB

Interesting. But looks like lombok-intellij plugin is not injected via vmArgs, but by the extension way. Not sure how they did that.

testforstephen avatar Jul 31 '20 08:07 testforstephen

In the latest version 1.1.0, the lombok agent in this extension is removed because RedHat Java extension has built-in lombok support by default. This lombok extension no longer injects lombok agent to 'java.jdt.ls.vmargs'.

testforstephen avatar Sep 26 '22 04:09 testforstephen