Skip to content

Better handle non-java sources #4738

@fbricon

Description

@fbricon

As I found in eclipse-jdtls/eclipse.jdt.ls#3666, in JDT.LS, when attaching a source jar to a classpath jar, if that source jar doesn't contain at least 1 java file, then the jar is not recognized as containing sources. This is due to JDT's SourceMapper.computeAllRootPaths() calling isJavaLikeFileName. Java-like extensions are loaded by getJavaLikeExtensions via an extension point.

If a source jar file (like presto-jdbc-sources.jar), containing a mix of java and kotlin files is referenced, then JDT.LS gets the kt content back, as expected, even though Eclipse IDE (JDT.UI) doesn't show it for some reason.

Now if we register kt as a java like name with:

   <extension point="org.eclipse.core.contenttype.contentTypes">
    <file-association
        content-type="org.eclipse.jdt.core.javaSource"
        file-extensions="kt"/>
    </extension>

Then a pure kotlin source jar file like okhttp-jvm-sources.jar gets its sources found in JDT.LS. The problem then becomes: any .kt file found in a source folder is now compiled as a java file and then you get plenty of compilation errors.

So basically, what we (JDT.LS) would need, is a way to declare a file association but only for readonly content. Or we could use heuristics and just declare a filename containing "-source" is an actual source file.

Here's an eclipse project, kotlin-sources.zip, that has the 2 aforementioned sources jars, if it helps.

cc @jjohnstn

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions