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

Module path: Import and code completion suggestions include inaccessible classes

Open mrcjkb opened this issue 3 years ago • 1 comments

Given a modular (Java 11) Gradle 7 project with the eclipse plugin And the following dependency: com.google.protobuf:protobuf-java:3.17.1 And a module-info.java When I run the eclipse Gradle task And I open a java project file (in my case in NeoVim 0.5 nightly) that does not import the java.util.Optional class. And start jdt.ls And I start typing Optional

Expected behaviour

Then the autocomplete suggestions include only classes that are accessible (e.g. required in the module-info.java) And the same applies to the "import" code action's suggestions

Current behaviour

Then the autocomplete suggestions and "import" code action suggestions include all classes from every Jar in the generated .classpath file; for example com.google.common.base.Optional, which is not exported transitively by the google protobuf,java module. And if I confirm the com.google.common.base.Optional import suggestion Then a diagnostic error message is published telling me that the imported class is not accessible

This tells me that the language server is capable of analysing the module path for diagnostics, but it fails to do so for autocomplete and code actions.

Is there a way I can tell the language server which JARs to include in suggestions?

mrcjkb avatar Jun 09 '21 22:06 mrcjkb

It looks like I may somewhat be able to work around this issue with the org.eclipse.jdt.core.classpath.exclusionPatterns property.

mrcjkb avatar Jun 11 '21 14:06 mrcjkb