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

Too many codelenses shown in lombok'ed project #137

Closed
fbricon opened this issue Jan 10, 2017 · 9 comments
Closed

Too many codelenses shown in lombok'ed project #137

fbricon opened this issue Jan 10, 2017 · 9 comments

Comments

@fbricon
Copy link
Collaborator

fbricon commented Jan 10, 2017

Opening an @Data annotated class from a lombok-powered project shows multiple codelenses for that annotation

Steps To Reproduce
  1. setup lombok support according to https://github.com/redhat-developer/vscode-java/wiki/Lombok-support
  2. clone https://github.com/springfuse/project-lombok-example
  3. Open https://github.com/springfuse/project-lombok-example/blob/master/src/main/java/com/springfuse/blog/projectlombok/bean/UsingProjectLombok.java

See
capture d ecran 2017-01-10 a 15 49 56

@fbricon fbricon added the bug label Jan 10, 2017
@fbricon
Copy link
Collaborator Author

fbricon commented Jan 11, 2017

So that's an interesting one :-)

Basically, the compilation unit lists all the methods generated by lombok (getters, setters...). For each element, the same sourcerange is returned (at the @Data location), so we generate and return 13 similar codelenses.

So, while we can mitigate the issue by only returning 1 of those codelenses, there's a larger problem here: how should we handle references of methods/variables only existing in the bytecode, but not at the source level? Or, in the case of lombok, how are we supposed to map a variable annotated @Getter or @Setter to actual references of getter and setter. I don't think we can handle that unless providing lombok specific behavior at the server level.

@gorkem ideas?

@fbricon
Copy link
Collaborator Author

fbricon commented Jan 11, 2017

anyways I think we should not even display the codelens when there are 0 references. Not sure if we should do it at the server level.

@fbricon
Copy link
Collaborator Author

fbricon commented Jan 11, 2017

@othomann you wanna take a look at that one?

@othomann
Copy link

@fbricon yes I will as soon as I am in a position to do so. Hopefully today.

@othomann
Copy link

Working on it.

@othomann
Copy link

The source that the parser gets for the unit is:
package com.springfuse.blog.projectlombok.bean;
import lombok.Data;
public @DaTa class UsingProjectLombok {
private String name;
private String firstname;
private int age;
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() {
return this.name;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFirstname() {
return this.firstname;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getAge() {
return this.age;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final String name) {
this.name = name;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFirstname(final String firstname) {
this.firstname = firstname;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setAge(final int age) {
this.age = age;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) {
if ((o == this))
return true;
if ((! (o instanceof UsingProjectLombok)))
return false;
final UsingProjectLombok other = (UsingProjectLombok) o;
if ((! other.canEqual((java.lang.Object) this)))
return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
if (((this$name == null) ? (other$name != null) : (! this$name.equals(other$name))))
return false;
final java.lang.Object this$firstname = this.getFirstname();
final java.lang.Object other$firstname = other.getFirstname();
if (((this$firstname == null) ? (other$firstname != null) : (! this$firstname.equals(other$firstname))))
return false;
if ((this.getAge() != other.getAge()))
return false;
return true;
}
protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) {
return (other instanceof UsingProjectLombok);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() {
final int PRIME = 59;
int result = 1;
final java.lang.Object $name = this.getName();
result = ((result * PRIME) + (($name == null) ? 43 : $name.hashCode()));
final java.lang.Object $firstname = this.getFirstname();
result = ((result * PRIME) + (($firstname == null) ? 43 : $firstname.hashCode()));
result = ((result * PRIME) + this.getAge());
return result;
}
public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() {
return (((((("UsingProjectLombok(name=" + this.getName()) + ", firstname=") + this.getFirstname()) + ", age=") + this.getAge()) + ")");
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") UsingProjectLombok() {
super();
}
}

So I think we need to check for the Generated annotation. Will investigate that.

@othomann
Copy link

So this explains why the source methods are returned even if there is no source inside the actual unit on disk.

@othomann
Copy link

I think this issue should be moved to the java-language-server repo. It is the server that returns too many code lens result. It is not VS Code's issue. Any client that supports lsp with code lens would have the same issue.

@fbricon
Copy link
Collaborator Author

fbricon commented Jan 16, 2017

Fixed with eclipse-jdtls/eclipse.jdt.ls@1935314

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

2 participants