Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for val in lombok #2983

Closed
FunctionDJ opened this issue Mar 6, 2023 · 25 comments
Closed

Support for val in lombok #2983

FunctionDJ opened this issue Mar 6, 2023 · 25 comments

Comments

@FunctionDJ
Copy link

Lombok's val doesn't seem to be supported. The type of the variable isn't inferred and becomes Object when referenced.

Environment
  • Operating System: Windows 10 21H2
  • JDK version: Java 17
  • Visual Studio Code version: 1.76.0
  • Java extension version: v1.15.0
Steps To Reproduce
  1. Import and use lombok.val
Current Result

image

Expected Result

The type is properly recognized. Similar behavior to final var.

@fbricon fbricon added the Lombok label Mar 7, 2023
@fbricon
Copy link
Collaborator

fbricon commented Mar 7, 2023

Might be an Eclipse JDT bug upstream. Can you check if it works in a lombokified Eclipse IDE?

@FunctionDJ
Copy link
Author

@fbricon I followed those instructions and it works in Eclipse. Hovering over the created variable shows the correct type.

@fbricon
Copy link
Collaborator

fbricon commented Mar 7, 2023

@FunctionDJ thanks for checking. So it must be a jdt.ls issue then. @snjeza can you please take a look?

@fbricon
Copy link
Collaborator

fbricon commented Mar 7, 2023

@FunctionDJ does completion work too in Eclipse, with the expected methods from the inferred type?

@FunctionDJ
Copy link
Author

I think this is what you mean and yes, it works:
image

@FunctionDJ
Copy link
Author

Also lombok.var has the same issue. The Java built-in var makes it less useful (or maybe even deprecated?) but i've come across it because of automatic wildcard package imports of Lombok which then "take over" vanilla vars.

@snjeza
Copy link
Contributor

snjeza commented Mar 7, 2023

@FunctionDJ Which version of Eclipse have you tested?

@snjeza snjeza added the upstream label Mar 7, 2023
@snjeza
Copy link
Contributor

snjeza commented Mar 7, 2023

This is an upstream lombok issue. See

@FunctionDJ Could you check lombok-1.18.27
It includes projectlombok/lombok#3347
You should set the following properties

"java.jdt.ls.lombokSupport.enabled": false,
"java.jdt.ls.vmargs": " -javaagent:<path_to_lombok-1.18.27.jar> <your_arguments>",

@FunctionDJ
Copy link
Author

@snjeza I did those changes and it seems to have fixed lombok.var but not val.

@snjeza
Copy link
Contributor

snjeza commented Mar 8, 2023

@FunctionDJ Could you try to clean the workspace directory?
lombokval

@FunctionDJ
Copy link
Author

FunctionDJ commented Mar 9, 2023

@snjeza Unfortunately, same result. I also checked "java.trace.server": "verbose" and it looks the same there.

[Trace - 10:01:06 AM] Received response 'textDocument/hover - (54)' in 51ms.
Result: {
    "contents": {
        "language": "java",
        "value": "Object foo - com.example.foo"
    }
}

@snjeza
Copy link
Contributor

snjeza commented Mar 9, 2023

@FunctionDJ Could you show your user and workspace settings.json?

@FunctionDJ
Copy link
Author

Sure. I've limited the entries to the ones that contain "java" somewhere.
I guess the vmargs of the user settings look suspicious, but they're being overwritten by the workspace settings.

User settings.json:

{
	"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -javaagent:\"c:\\Users\\some-user\\.vscode\\extensions\\gabrielbb.vscode-lombok-1.0.1\\server\\lombok.jar\"",
	"java.configuration.runtimes": [
		{
			"path": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.3.7-hotspot",
			"name": "JavaSE-17"
		}
	],
	"java.format.settings.url": "C:/local/foo.xml",
	"java.autobuild.enabled": true,
	"boot-java.live-information.fetch-data.max-retries": 20,
	"boot-java.live-information.fetch-data.retry-delay-in-seconds": 5,
	"java.debug.settings.showLogicalStructure": true,
	"java.debug.settings.showToString": true,
	"java.debug.settings.showQualifiedNames": false,
	"java.debug.settings.showStaticVariables": false,
	"java.debug.settings.showHex": false,
	"boot-java.rewrite.reconcile": true,
	"[java]": {
		"editor.defaultFormatter": "redhat.java"
	},
	"java.inlayHints.parameterNames.enabled": "none",
	"java.sources.organizeImports.starThreshold": 3,
	"java.sources.organizeImports.staticStarThreshold": 3,
}

Workspace settings.json:

{
	"java.dependency.packagePresentation": "hierarchical",
	"java.jdt.ls.lombokSupport.enabled": false,
	"java.jdt.ls.vmargs": "-javaagent:C:\\Users\\some-user\\Downloads\\lombok-1.18.27.jar -Xlog:jni+resolve=off",
	"java.configuration.updateBuildConfiguration": "automatic",
	"debug.console.wordWrap": false,
	"java.compile.nullAnalysis.mode": "automatic",
}

@snjeza
Copy link
Contributor

snjeza commented Mar 9, 2023

@FunctionDJ I have tested with your settings. It works fine.

lombokval2

Could you show an example reproducing the error?

@snjeza
Copy link
Contributor

snjeza commented Mar 9, 2023

@FunctionDJ Could you remove

-javaagent:\"c:\\Users\\some-user\\.vscode\\extensions\\gabrielbb.vscode-lombok-1.0.1\\server\\lombok.jar\"

from your settings.java as well as the gabrielbb.vscode-lombok extension? This extension is deprecated.

@michael-emmi
Copy link

michael-emmi commented Mar 9, 2023

Just in case anybody wants a third data point here: I had the same problem as @FunctionDJ.

@snjeza’s proposed workaround of disabling LS Lombok support and adding 1.18.27 jar as agent works for me.

@FunctionDJ
Copy link
Author

@snjeza Indeed it works with a fresh Spring Boot project (both Maven, both Java 17, almost the same Spring version).
I'm unsure how to proceed because i can't provide the repository where the issue is because it's company code.
Do you have any advice? Thank you very much for your support so far!

@FunctionDJ
Copy link
Author

I've spent a lot of time and work getting to a minimal reproduction state.
Here's the repository: https://github.com/FunctionDJ/lombok-var-reproduction
Reproduction:

  • open with VSCode with the Java extension (i have 1.16.0 installed)
  • i use Adoptium jdk-17.0.3.7-hotspot as the Java runtime and -javaagent:somepath\\lombok-1.18.27.jar -Xlog:jni+resolve=off for vmargs
  • problems view will show The method bat() is undefined for the type Object in Application.java because node is interpreted as Object
  • the error doesn't come up in Eclipse

There are a couple of things that will magically fix this, like removing the static property on Foo or removing <java.version>17</java.version> from the pom.xml.

@snjeza
Copy link
Contributor

snjeza commented Mar 16, 2023

@FunctionDJ I can reproduce it in Eclipse 4.27. Which version of Eclipse are you using?

A related issue - projectlombok/lombok#3332

@Rawi01
Copy link

Rawi01 commented Mar 16, 2023

Since version 1.18.22 lombok uses the Java native version of var, or at least tries to do that. It also converts val to final var on Java 10+. I think we have not covered the case that someone imports lombok.var if there is also native support for it.

@FunctionDJ
Copy link
Author

@snjeza I used 4.26.0 but i've installed 4.27.0 and made sure to add the same Adoptium JDK as i use in VSCode and it seems to ignore the lombok import for some reason.
image

@FunctionDJ
Copy link
Author

@Rawi01 Yeah it came up by coincidence because we want to turn more than 3 imports from the same package into a wildcard import. That's how i initially ran into this issue because lombok.var got implicitly imported from a wildcard, even though we can easily use native var. At the time i thought that val was the issue (as seen in the first screenshot of this issue).
Maybe i should check out lombok 1.18.21 where lombok doesn't use the native keywords yet and see if that makes a difference.

@FunctionDJ
Copy link
Author

The lombok version before 22 that i could obtain was 1.18.20 and while it doesn't show any errors with val or var imported and used, it also doesn't look right (toReportList is Object on hover).
image
This is probably similar to my initial issue after which snjeza advised me to update my lombok version, so this result might not be very meaningful to this issue.

@snjeza
Copy link
Contributor

snjeza commented Mar 17, 2023

@FunctionDJ I used 4.26.0 but i've installed 4.27.0 and made sure to add the same Adoptium JDK as i use in VSCode and it seems to ignore the lombok import for some reason.

It is an upstream lombok issue. See #2983 (comment)

@FunctionDJ
Copy link
Author

Fixed upstream (edge release is working for me): projectlombok/lombok#3332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants