eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

Go to - wrong - definition on protobuf generated classes

Open BruceWouaigne opened this issue 3 years ago • 3 comments

Hi there, very first time for me posting an issue here so sorry in advance if this is not the right place.

So here's the thing, I'm using vscode 1.59.1 with Java language support v0.81.0 and I ran into something weird when using protobuf.

Let say there’s a proto definition file in my service generating a class named and namespaced exactly the same as one that is in a library that is part of my service deps.

Local definition file:

package bruce.proto.v1;

message Foo {
  string bar = 1;
  string baz = 2;
}

Imported library definition file:

package bruce.proto.v1;

message Foo {
  string bar = 1;
}

When writing var foo = Foo.newBuilder().setBaz(“qux”).build(); my service compiles successfully but vscode (as well as eclipse) complains that setBaz(String) is undefined for the type Foo.Builder.

image

When I cmd+click on Foo class it brings me to the generated class of the library instead of the one generated locally.

The classpath is set correctly and if I remove the library dependency the IDE doesn't complain anymore and Go To Definition works as expected.

If you want to see by yourself

$> git clone [email protected]:BruceWouaigne/test-java-lib.git && mvn -f test-java-lib install
$> git clone [email protected]:BruceWouaigne/test-java-app.git && mvn -f test-java-app compile

Then open test-java-app Java project in vscode or eclipse.

Cheers!

BruceWouaigne avatar Aug 21 '21 11:08 BruceWouaigne

Nobody?!

BruceWouaigne avatar Sep 02 '21 13:09 BruceWouaigne

@BruceWouaigne You can try to add the following plugin:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>addSource</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>${project.basedir}/target/generated-sources/protobuf/java</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

to your test-java-app/pom.xml

See https://github.com/redhat-developer/vscode-java/issues/2058#issuecomment-898044034

snjeza avatar Sep 02 '21 18:09 snjeza

Thanks @snjeza but that doesn't change a thing. Again my project build is passing but IDEs are getting confused.

BruceWouaigne avatar Sep 10 '21 10:09 BruceWouaigne