Skip to content

feat: have class URIs use their original source name#3666

Merged
fbricon merged 1 commit intoeclipse-jdtls:mainfrom
fbricon:better-class-uris
Feb 11, 2026
Merged

feat: have class URIs use their original source name#3666
fbricon merged 1 commit intoeclipse-jdtls:mainfrom
fbricon:better-class-uris

Conversation

@fbricon
Copy link
Contributor

@fbricon fbricon commented Jan 8, 2026

Fixes redhat-developer/vscode-java#4297

Draft until I go over all failing tests

@fbricon fbricon force-pushed the better-class-uris branch 2 times, most recently from f98f6f7 to 49b59ba Compare January 8, 2026 15:36
@fbricon fbricon marked this pull request as ready for review January 8, 2026 15:45
@fbricon fbricon added this to the End January 2026 milestone Jan 8, 2026
@fbricon
Copy link
Contributor Author

fbricon commented Jan 8, 2026

@datho7561 could you test this PR on non-vscode clients pretty please? Hopefully it should work everywhere

@fbricon fbricon marked this pull request as draft January 8, 2026 16:30
@fbricon
Copy link
Contributor Author

fbricon commented Jan 8, 2026

There's an issue when opening module-info.class, when it works without this PR
Screenshot 2026-01-08 at 17 31 24

I need to investigate

@fbricon fbricon force-pushed the better-class-uris branch from 49b59ba to 6d2a8ff Compare January 9, 2026 08:43
@datho7561
Copy link
Contributor

It doesn't seem to be working for me outside of VS Code, here's what I tried:

  1. Make a Maven project with okhttp3 as a dependency
  2. In one of the Java files, make an instanceof of OkHttpClient, then trigger go-to-definition on it
  3. I get a .class file with Java code instead of the .kt file

I'll double check that it works for me in VS Code as well, though

@fbricon
Copy link
Contributor Author

fbricon commented Jan 9, 2026

okhttp3 is a different problem I was looking at this morning. Eclipse fails to open the kotlin sources because the jar file doesn't contain any .java file. This is due to JDT's SourceMapper.computeAllRootPaths() calling isJavaLikeFileName. Java-like extensions are loaded by getJavaLikeExtensions via an extension point.

I tried registering kotlin via :

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

And then it works! But with a big caveat: any .kt file found in a source folder is now compiled as a java file and then you get plenty of compilation errors.

Sooo. This is an issue that needs to be handled in a separate ticket.

For now presto-jdbc sources work

@datho7561
Copy link
Contributor

For now presto-jdbc sources work

Okay, I'll check that and get back to you

@fbricon
Copy link
Contributor Author

fbricon commented Jan 9, 2026

You can try

<dependency>
      <groupId>com.facebook.presto</groupId>
      <artifactId>presto-jdbc</artifactId>
      <version>0.296</version>
</dependency>
<dependency>
      <groupId>com.typesafe.akka</groupId>
      <artifactId>akka-actor_2.13</artifactId>
      <version>2.8.8</version>
</dependency>

@datho7561
Copy link
Contributor

datho7561 commented Jan 9, 2026

Okay, I get Kotlin sources now, but the file extension is still listed as .class (Maybe that's just how it works for this neovim setup though) so I have to change the language over to Kotlin manually.

update: yeah works fine in VS Code, so I'm guessing it's something to do with the client code in neovim.

update: specifically something in https://codeberg.org/mfussenegger/nvim-jdtls, since go-to-definition doesn't work without it

@fbricon
Copy link
Contributor Author

fbricon commented Jan 9, 2026

That's weird. jdt.ls used to send the kotlin content before as well, the only difference is now the URI path ends with .kt instead of .class

@datho7561
Copy link
Contributor

Here's the client code where the classfile loading is being handled I think: https://codeberg.org/mfussenegger/nvim-jdtls/src/commit/f73731b543f5971e0da9665eb1d7ceffe1fde71f/lua/jdtls.lua#L1214

Notably, it sets the filetype to Java. This might cause problems?

@fbricon
Copy link
Contributor Author

fbricon commented Jan 14, 2026

@mfussenegger any idea why nvim-jdtls would still list the source content as .class instead of .kt?

@datho7561 we need eclipse-jdt/eclipse.jdt.core#4738 to be fixed in order to see .kt files from source jars not containing .java files.

@fbricon fbricon marked this pull request as ready for review January 15, 2026 10:31
@mfussenegger
Copy link
Contributor

mfussenegger commented Jan 21, 2026

@mfussenegger any idea why nvim-jdtls would still list the source content as .class instead of .kt?

nvim-jdtls should show the jdt:// as returned by the server without any modification unless users customized the display.
Neovim has no general hook for URI pretty-printing.

But looks like I'll need to adapt the logic in nvim-jdtls that calls java.decompile or java/classFileContents, currently it assumes the response will be java code. Should the client parse the URI and determine the filetype based on a .kt|.class or is there a better option?

--

Other question: Can eclipse.jdt.ls then handle if the LSP client attaches to those kotlin sources (didOpen, etc.) loaded via java/classFileContents? I so far assumed that eclipse.jdt.ls can only handle java sources.

@fbricon
Copy link
Contributor Author

fbricon commented Jan 21, 2026

@mfussenegger yes you'll need to parse the url path, the actual file extension will be sent back. If for some reason you receive .class, it should be treated as .java

"java/classFileContents" should just be used to display source content. You're not supposed to call jdt.ls didOpen on it.

@mfussenegger
Copy link
Contributor

"java/classFileContents" should just be used to display source content. You're not supposed to call jdt.ls didOpen on it.

Is there an issue doing it? So far I never noticed any problem. And it is currently required due to how the neovim lsp client works. To use other textDocument/ related LSP functionality like fetching symbols or goto-definition the client must be attached to a buffer, and attaching to a buffer automatically sends a textDocument/didOpen notification - which seems in line with the spec?

@fbricon
Copy link
Contributor Author

fbricon commented Jan 21, 2026

OK so I double checked in vscode-java, didOpen is not called when opening a .kt source via "java/classFileContents", but .java content does it, so I guess you don't need to change anything there.

@fbricon
Copy link
Contributor Author

fbricon commented Jan 27, 2026

We need eclipse-jdt/eclipse.jdt.core#4769 to be merged upstream to be able to get kotlin sources from kotlin-only jars

@fbricon
Copy link
Contributor Author

fbricon commented Feb 10, 2026

Upstream fix has been merged and is available for jt.ls to consume, tested with any class from

<dependency>
  <groupId>com.facebook.presto</groupId>
  <artifactId>presto-jdbc</artifactId>
  <version>0.296</version>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp-jvm</artifactId>
  <version>5.3.2</version>
</dependency>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-actor_2.13</artifactId>
  <version>2.8.8</version>
</dependency>

@mfussenegger any chance you can test this PR?

@mfussenegger
Copy link
Contributor

mfussenegger commented Feb 10, 2026

On a quick test it seems to work.
With https://codeberg.org/mfussenegger/nvim-jdtls/pulls/19 the filetype is also set correctly to kotlin.

Can eclipse.jdt.ls also provide sources for other JVM languages - like scalar or clojure or is it only kotlin for now?

@fbricon
Copy link
Contributor Author

fbricon commented Feb 10, 2026

I've added groovy, kotlin and scala for now, just need to update the extension point in plugin.xml to add more languages. Do you know any lib written in clojure?

@fbricon
Copy link
Contributor Author

fbricon commented Feb 10, 2026

I added clojure as well.

mfussenegger added a commit to mfussenegger/nvim-jdtls that referenced this pull request Feb 10, 2026
@fbricon fbricon merged commit 25d3d78 into eclipse-jdtls:main Feb 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After opening the Kotlin class of the downloaded Maven dependency source code, I see a .class file instead of a .kt file

3 participants