I was looking to see what's necessary to fix issue https://github.com/clojure-lsp/clojure-lsp/issues/2156 which says that in the code
(let [^Future| fut ,,,] ,,,)
"import java.util.concurrent.Future" isn't show as a Code Action. I messed around with add-missing-libspec-test and noted that it seems as if only java.io.File (which is actually being added via a fixture loaded with (h/load-java-path ,,,)) is available. Import for java classes in the JDK doesn't seem to work anywhere, even without the class being in a type hint. For example, with
(Vecto|r.)
I don't see any import options for code fixes.
I did verify that I can jump into the sources for java.util.concurrent.Future and java.util.Vector, etc...
Are import suggestions for Java JDK classes supposed to work or is this a config issue on my part?I tried both changing db.transit.json to version 12 (via opening the file in emacs), and increasing the version to 14 in db.clj. But in both cases db.transit.json was automatically regenerated. I guess the version isn't the issue. I'll keep this in mind, but I'm out of ideas for now
that explains a lot!
It looks like this is due to 1) something removing the ~/.cache/clojure-lsp/db.transit.json file, and 2) running unit tests ( bb test )
It's probably a good idea to isolate the unit tests with a mock or a temporary directory It might also be a good idea to somehow validate db.transit.json, if that's possible without killing performance
The good news is that, if I'm right, this shouldn't be an issue for most users
yeah, I already faced that and saw other people having that, so I wonder if it affect really few users
> db.transit.json seems to be global clj-kondo data about the JDK files (I could be wrong!). Yep, we just save in global cache the jdk analysis as it doesn't make sense to save per repo/project the same analysis all the time, I suspect there is the issue
I doubt the version changed, it's been a while I don't bump version
Hum, not sure actually if could be a version change
Yeah I always forget to ask people to copy the old db.transit 😅
It's funny tho, I never got this issue myself
I saw this again and opened https://github.com/clojure-lsp/clojure-lsp/issues/2285 about it. The local cache data seems to be written to the global cache, overwriting the jdk files.
Interesting, https://github.com/clojure-lsp/clojure-lsp/issues/2156#issuecomment-4264576901
but yes, this comes from java analysis, which we do for jdk if found in user installation in many ways
we do have some inconsistency bug with jdk analysis, which usually is solved removing the global jdk cache in ~/.cache/clojure-lsp/jdk and restarting lsp
You're right! I removed ~/.cache/clojure-lsp/jdk, restart clojure-lsp, and now the import shows up, even in Calva. It seems like https://github.com/clojure-lsp/clojure-lsp/issues/2156 could be closed with this. I wonder what could cause this? Maybe I upgraded my JDK but didn't clear the cache?
yeah TBH this happens since I implemented java analysis, it's some cache issue I never figured it out
Strange. When I diffed the newly rebuilt "jdk" from the ~.cache/clojure-lsp/jdk there were no differences from the jdk directory I had moved away. Maybe just updating the timestamp changes things
yeah I doubt is jdk change, it's something else with kondo anaysis
Very interesting... it seems that there is also a /.cache/clojure-lsp/db.transit.json. I didn't save that (doh!) but it was recreated after I removed /.cache/clojure-lsp/jdk.
I'm guessing it is loaded into (:analysis db) because I now see quite a lot of data there whereas before there wasn't much. (I'm pretty sure about this, although I could be wrong!) Indeed, from the code in add-missing-libspec/find-missing-imports, I can do a get-in of db for [:analysis <jarfile> :java-class-definitions] which is kinda what this is using to do find-missing-imports.
db.transit.json seems to be global clj-kondo data about the JDK files (I could be wrong!).
So maybe db.transit.json was corrupted or it somehow didn't get loaded correctly in db.clj? Or maybe the version changed? (I see the version changed from 12 to 13 recently) I can experiment with that, but otherwise I'll just have to hope I get this corruption again.
Too bad I don't have a copy of db.transit.json!
good test