Fork me on GitHub
#lsp
<
2022-03-31
>
ericdallo16:03:02

clojure-lsp Released clojure-lsp 2022.03.31-14.21.14 with a long waited feature: Java support 🎉 🚀 • Add java class find-definition support, decompiling .class files when available. https://github.com/clojure-lsp/clojure-lsp/issues/762 • Add JDK source discoverability feature, searching for installed JDK for later analyze with clj-kondo and support java classes interop. • Add :java :download-jdk-source? setting to download JDK source after startup if not cached before globally or found locally. Disabled by default. • Avoid high CPU usage and freezes by more efficiently finding referenced files to notify on file change. https://github.com/clojure-lsp/clojure-lsp/issues/844 https://github.com/mainej • Bump clj-kondo to 2022.03.10-20220331.135739-32 improving java analysis and fixing a critical regression for re-frame. https://github.com/clojure-lsp/clojure-lsp/issues/888 This is a release with few but huge features/improvements, we now support find definition of all types java classes: • Java classes with source, going to top of the .java file • Java classes without source, making clojure-lsp decompile the .class into a cache folder and then going to that decompiled .class • JDK classes, clojure-lsp will try to find the source in the installed system's JRE, otherwise download OpenJDK source if a setting is enabled, Check https://clojure-lsp.io/settings/#java-support For now , we support java classes only and not methods, soon we intend to add support for completion, documentation and methods support 🤞 Also, Thank you @borkdude for the help on clj-kondo side! Besides that we had huge performance improvements on the way we analyze changed files, improving huge files/projects like https://github.com/Clojure2D/clojure2d This release was supported by https://www.clojuriststogether.org/ clojurists-together gratitude

🎉 13
👏 5
clj-kondo 2
ahungry17:03:35

Hi all - after the announcement of the new version, I installed clojure-lsp from this guide via emacs https://emacs-lsp.github.io/lsp-mode/tutorials/clojure-guide/ - I tried to jump to definition for a Thread/sleep call and it didn't seem to work - what's the way to check the version of clojure-lsp and see if I have the one required for this functionality?

ericdallo17:03:20

clojure-lsp --version

borkdude17:03:12

I get this:

$ bash <(curl -s ) --dir ~/Dropbox/bin
Downloading  to /var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/tmp.F7hhsRuJ
Moving /Users/borkdude/Dropbox/bin/clojure-lsp to /Users/borkdude/Dropbox/bin/clojure-lsp.old
$ clojure-lsp --version
clojure-lsp 2022.03.31-14.21.14
clj-kondo 2022.03.10-SNAPSHOT

👍 1
ahungry17:03:00

Hmm, no binary found on path - assuming clojure-lsp --version should be called from a standard shell - maybe the Emacs installed one does some fiddling with paths to install an emacs visible only one? I guess I can try doing the bash install and set lsp-clojure-custom-server-command ?

ericdallo17:03:12

I suggest you follow the installation instructions https://clojure-lsp.io/installation/

ericdallo17:03:01

if you installed via emacs with lsp-install-server, you can try lsp-clojure-server-info to get the info if clojure-lsp is already running in that project

ahungry17:03:28

Thanks - I added the cli install and see the 3.31 version, much appreciated 😄

ahungry17:03:52

is there any emacs-side settings required to enable the java support? I see a note in the release about a :java key - not sure if that belongs in a clojure-lsp rc file or something? or in emacs

borkdude17:03:07

@UKFSJSM38 Thread/sleep also doesn't navigate to anything for me btw, have you implemented that Java source download?

borkdude17:03:19

or should I set JAVA_HOME somewhere?

ericdallo17:03:56

but if you have JRE with src.zip on it it should work without downloading anything

borkdude17:03:51

I'm pretty sure java is on my PATH but no nav

ericdallo17:03:14

Check what is printed on server logs

borkdude17:03:35

please specify server logs

borkdude17:03:46

[1;31mjava.nio.file.NoSuchFileException[m: [3m/private/tmp/project/https:/raw.githubusercontent.com/clojure-lsp/jdk-source/main/openjdk-19/reduced/source.zip[m

borkdude17:03:53

That looks like a problem

ericdallo17:03:08

yeah, sounds like a corner case

ericdallo17:03:32

what is in your JAVA_HOME ?

borkdude17:03:53

also I did not configure lsp to download it - you said it defaults to not downloading - so why is that appearing in the logs? ;)

borkdude17:03:01

I haven't set JAVA_HOME

borkdude17:03:13

could try that first

borkdude17:03:37

another minor point, why didn't you use XDG_CACHE instead of XDG_CONFIG for this cached file?

ericdallo17:03:23

not sure, We already have XDG_CONFIG use for other configs, I thought it would be a good place

ericdallo17:03:30

but XDG_CACHE sounds better

ericdallo17:03:57

anyway, it should not say it's downloading unless you have :java :download-jdk-source? set

borkdude17:03:29

Can I specify the path to src.zip?

ericdallo17:03:50

yes, via :java :jdk-source-uri

ericdallo17:03:02

but you do you mind help find what issue is that ? 😅

ericdallo17:03:07

other users may have the same

borkdude17:03:25

which issue?

ericdallo17:03:40

I want to understand why that happened

ericdallo17:03:04

could you paste the server logs? after server starts, there should be logs with [JAVA] tag

borkdude17:03:16

well, it seems it tries to download from github right? but it appends my file system path before the url :)

ericdallo17:03:41

but do you have :java :download-jdk-source? enabled so?

borkdude17:03:22

that's why I found it surprising that I saw that. I haven't changed anything to my config

ericdallo17:03:36

Oh, I think I found the issue

ericdallo17:03:08

yeah, a recent commit introduced a bug

ericdallo17:03:25

One more reason I didn't want to release that soon 😂

borkdude17:03:47

I'm sure there is a good workaround for this

ericdallo17:03:46

specifying the URI on the setting should do the tricky, but without that it probably will fail :/

borkdude17:03:16

You can document that workaround and change the docs on the next release maybe?

snoe17:03:40

I think zipfile clojure deps is broken on master (release too prolly) getting jar: scheme back for uri. Could someone else confirm?

ericdallo17:03:07

I don't get it, what is the issue?

snoe17:03:54

When I go to def of a dependency, I'm getting the wrong uri scheme back. I expect zipfile://... but get jar:file://...

ericdallo17:03:19

it's related with the java change

ericdallo17:03:47

will work on that fix and make a hotfix @U0BUV7XSA

ericdallo17:03:48

thanks

👍 1
snoe18:03:05

the external-analysis and project-analysis test in queries_test.clj looks like they aren't actually testing dependency-scheme The code and docs are also pretty confused between whether it should be zip or zipfile (i think it just checks = "jar" so this is less urgent but was confusing to troubleshoot)

👍 1
ericdallo18:03:06

@U0BUV7XSA just to make sure, this happens when you find a definition of a external clojure/java file?

snoe18:03:04

haven't tried java, but clojure yes, like medley

snoe18:03:27

go to def on medley/map-vals

ericdallo18:03:32

@U0BUV7XSA I'll send the fix, but I think java analysis won't work for zipfile users (only vim?) for now 😔 We should think later how to fix that

snoe18:03:04

thanks. yeah, I think only the decompiled would be insurmountable

yes 1
ericdallo18:03:24

Could you please test master again?

👀 1
ericdallo18:03:06

LMK if you have any suggestion regarding the insurmountable decompiled for zipfiles

snoe18:03:29

well I guess you could write to a tempfile and send a uri there

snoe18:03:22

or just say that to use it you need to use that content call

ericdallo18:03:42

yeah, good point, will think a little more about that, meanwhile I'll release the hotfix and leave that for next release which I don't want to delay that much

ericdallo18:03:10

LMK if master fixed the issue so I can hot-release

snoe18:03:39

@UKFSJSM38 master is fixed

snoe18:03:51

thank you!

snoe18:03:34

I guess, for my own workflow. Needing to read java (compared to clojure) sources is very rare. But, method completion and hover (with docs) will be sublime. So I'm not too concerned with zipfile compatibility there.

👍 1
ericdallo18:03:06

yeah, agreed, but I'll try to fix that, vim users use zipfile right? so more people may want to have java support just like other editors

snoe18:03:34

yeah, I see that jdk sources are in .lsp/.cache and that works fine

ericdallo18:03:27

what works fine? are you able to go to definition of that java class definition or you manually opened it from cache?

snoe18:03:48

Yeah I can go to def of clojure.string then go to def of java.util.regex Pattern

🤷 2
ericdallo18:03:10

hahahah 🤯

borkdude18:03:59

hahahahahaha!!!! 👿

snoe18:03:59

just jdk sources are found tho.

borkdude18:03:47

in contrast to what other sources?

ericdallo18:03:23

Oh I know what's happening

ericdallo18:03:35

it will find everything that has source .java

snoe18:03:36

so java.* packages work, cause it's redirecting me to the .cache. but like com.cognitect.* doens't

ericdallo18:03:45

decompile won't work because it pass to that function

👆 1
ericdallo18:03:02

@U0BUV7XSA try some lsp4j classes that also has source code

snoe18:03:21

yup, those do work

ericdallo18:03:22

like InitializeParams

snoe18:03:22

yeah, ok so I had tried transit and it didn't work

ericdallo18:03:35

alright, now things make sense 😂

dharrigan19:03:59

as an aside, I don't have problem to go to a clojure dep

🙏 3
dharrigan19:03:04

Going to try master

dharrigan19:03:42

Ah, now that doesn't work for me anymore

dharrigan19:03:48

java.net.MalformedURLException: unknown protocol: zipfile

dharrigan19:03:01

so, release works, master no more.

ericdallo19:03:12

what code did you try to find definition?

dharrigan19:03:19

a java class

dharrigan19:03:26

a clojure lib is okay

ericdallo19:03:28

that won't work for .class yet

ericdallo19:03:43

for vim users 😔

dharrigan19:03:03

On the relese version it works

ericdallo19:03:22

that's odd, it should work only if the java source is available

ericdallo19:03:52

@U0BUV7XSA I was wondering, would work make vim always use "jar" dependency-scheme? so all clients follow same rules

dharrigan19:03:53

Nope, it definitely decompiled the class and showed me the decompiled source

ericdallo19:03:40

anyway, I intend to investigate that tomorrow or by the weekend, making it work for zipfile too

dharrigan19:03:59

On the released version, I remove the .lsp/.cache directory, open up a file containing a java jar, goto definition and it gets decompiled and opens up for me on vim

dharrigan19:03:29

on master, same process, but [Server] java.net.MalformedURLException: unknown protocol: zipfile

dharrigan19:03:17

I'm using the default dependency scheme of zip (as I haven't set it explicitly)

dharrigan19:03:39

Let me know if I can be of any further help/testing.

👍 1
ericdallo21:03:15

Released the fix, I'll work on zipfile fixes on weekend

Cora (she/her)19:03:25

what does :java :download-jdk-source? mean for the config?

ericdallo19:03:16

As mentioned https://clojure-lsp.io/settings/#java-support, it tells to clojure-lsp to download the source of JDK if not found locally

Cora (she/her)19:03:44

sorry, I meant "what does this mean for the format in the config"

Cora (she/her)19:03:05

I don't understand how two keywords in a row translates into a setting in the config

Cora (she/her)19:03:36

I didn't ask very well 😬

ericdallo19:03:40

{:java {:download-jdk-source? true}}

Cora (she/her)19:03:08

that was my guess after thinking on it for a minute or two

ericdallo19:03:42

writing the full map would make docs a little bit bigger, but maybe clearer?

Cora (she/her)19:03:06

it would certainly make it a lot clearer

👍 1
Cora (she/her)19:03:00

I do wish it was more common to have a list of all the possible options with links out to their documentation

Cora (she/her)19:03:05

I realize that's a lot of work, though

ericdallo19:03:56

maybe we should highlight a littel better that

Cora (she/her)19:03:47

should those all be keywords and not symbols?

ericdallo19:03:10

just like that edn file

Cora (she/her)19:03:22

and having 2+ on a line for name means they're nested

Cora (she/her)19:03:40

oh nice, it links to an edn file too

Cora (she/her)19:03:45

thanks for your patience here, eric

ericdallo19:03:59

suggestions are welcome

Cora (she/her)19:03:11

I wonder if there's a better way to convey nesting. I'll have to think about that

👍 1
ahungry20:03:08

Does all-available-settings.edn translate into something? Like, a ~/.config/clojure-lsp.edn ? Or a per-project file? (if so, what name? Just put in deps.edn?)

Cora (she/her)20:03:55

well, I did something about the things I knew were pretty simple fixes https://github.com/clojure-lsp/clojure-lsp/pull/898

Cora (she/her)20:03:23

there are a couple global locations you can put a global config for clojure-lsp

Cora (she/her)20:03:40

and, obviously, for individual projects as well but those are the global ones

Cora (she/her)20:03:42

hmm maybe something like:

`:java`>`:download-jdk-source?
`

Cora (she/her)20:03:51

or an eql query?

{:java :download-jdk-source?}

Cora (she/her)20:03:55

no, that's more confusing

ericdallo20:03:03

yeah I think it's more confusing

Cora (she/her)20:03:34

well, it's clojure-lsp, we could be cute about it

Cora (she/her)20:03:00

change the column name from "name" to "get-in" and use the get-in syntax for the nested values

ericdallo20:03:13

@U02N27RK69K we don't add : to settings on that docs because it's possible to pass docs via initializationOptions as json :/

Cora (she/her)20:03:26

well, :clean already had that

ericdallo20:03:47

yeah, we need a better naming converntion for nested configs

Cora (she/her)20:03:45

I can think of some ways to do this that are interesting

Cora (she/her)20:03:34

a toggle for showing json vs edn, using "jq" as the header for json and "get-in" for edn

Cora (she/her)20:03:30

or just a column for each

Cora (she/her)20:03:56

I'll close my PR

ericdallo20:03:11

yeah, maybe we should improve that table somehow

Cora (she/her)20:03:17

it's the consistency (or inconsistency) that confuses me

Cora (she/her)20:03:33

the docs throughout generally use keywords and edn, but not in the table (except for :clean)

ericdallo20:03:14

yeah, so let's go with the : , which is way most common

Cora (she/her)20:03:43

does an option like :download-jdk-source? translate to "download-jdk-source?" in json?

ericdallo20:03:22

but I think using the json it's pretty uncommon nowadays with clojure-lsp file config

Cora (she/her)20:03:39

should I re-open my PR then?

Cora (she/her)20:03:08

oh, you re-opened already 🙂

Cora (she/her)20:03:41

I'll bet I can make it a toggle at some point here, purely in js

ericdallo20:03:20

that'd be awesome

ericdallo20:03:31

but maybe it would make the markdown a little bit worst to maintain?

Cora (she/her)20:03:47

oh, no, I'd have the js translate the edn to json

ericdallo20:03:50

maybe not, as it'd be a separated js

ericdallo20:03:04

sounds like a good improvement

Cora (she/her)20:03:08

although I'm not sure how you'd handle `

#re ".*"

ericdallo20:03:33

yeah, there is a pretty chance that they don't work at all or we cast it wrongly 😅

ericdallo20:03:28

initializationOptions are json settings that usually editors send, so they use just one or two settings, nothing advanced

Cora (she/her)20:03:18

maybe it pays to just have the json listed in that column for those specific values

Cora (she/her)20:03:27

as a way of saying "these are supported in json"

ericdallo20:03:45

yeah, I think we should support all as json, so I'm okay adding a note somewhere, maybe on initializationOptions section saying that a json is expected and ifsomething not works, fix on clojure-lsp

snoe21:03:10

I think a lot of this could be replaced by merging in ~/.lsp/config.edn(which I think we do now?) or ~/.lsp/profile.edn Then dropping support for config coming from initializationOptions since it really does confuse things. The way I thought about initializationOptions are for global or user specific settings whereas project/.lsp/config.edn are shared, project specific.

ericdallo21:03:55

Not sure, dependency-scheme is required since all emacs users should send jar, same for Calva

ericdallo21:03:06

So we need a Editor way to set a config

ericdallo21:03:34

That's my point regarding of that setting, would be possible make vim (the only editor that uses zipfile AFAIK) to use jar as well?

snoe21:03:53

there's some nice benefits to it, for clojure files you can actually edit within zipfile after jumping in.

ericdallo21:03:40

Hum, but do we need that? you should not edit a external deps right?

ericdallo21:03:52

Sounds like a really corner case

snoe21:03:20

Don't use it often, but when it's needed to debug something within it's really really nice.

snoe21:03:08

Like service startup problems before repl is accessible.

Cora (she/her)19:03:42

like this?

{:java {:download-jdk-source? true}}

borkdude21:03:58

I had a pretty interesting CPU spike just now. The clojure-lsp processes weren't busy at all, also no clj-kondo active in my activity monitor, but emacs was locked up at 100%. All I did was type in an empty clojure buffer: (def ^{:ma_}), at the underscore I tried to write :macro

borkdude21:03:41

Obviously I forgot the def symbol too

ericdallo21:03:03

Só the CPU came from emacs and not clojure-lsp?

ericdallo21:03:21

It could be lsp-mode or even other emacs packages

borkdude21:03:24

I had to forcequit my emacs

ericdallo21:03:28

The emacs profiler is the best tool to understand that

ericdallo21:03:46

Or for that case: toggle-debug-on-quit

ericdallo21:03:57

Which would stop emacs and tell what was doing and the stack

borkdude21:03:11

I could not type anything anymore

borkdude21:03:22

so how I can turn something on if I cannot type?

ericdallo21:03:50

Yeah, that would be needed to be turned before the freeze :/

borkdude21:03:22

well I can repro it easy enough

borkdude21:03:28

will try tomorow

👍 1
genmeblog21:03:48

Mine is not freezing at this case (speaking as a freezing emacs user 🙂 )

borkdude22:03:37

it could be flycheck invoking clj-kondo over and over, but I didn't see the clj-kondo process at all

jacob.maine19:04:27

I occasionally have random freezes of emacs too. Usually nothing is using much CPU, it just stops responding. But, this is an issue as old as time. https://www.reddit.com/r/emacs/comments/k7cku8/when_emacs_hangs_what_do_you_do/

☝️ 1
ericdallo19:04:18

Still, it's pretty pretty rare to me some emacs hang that hitting C-g multiple times doesn't solve it 😅

borkdude20:04:39

Yesterday's freeze wasn't solvable by any means, but I'll try the signal

borkdude20:04:19

So I reproduced it again and did pkill USR2

borkdude20:04:22

Debugger entered--Lisp error: (quit)
  bounds-of-thing-at-point(sexp)
  clojure-match-next-def()
  imenu--generic-function(((nil clojure-match-next-def 0)))
  imenu-default-create-index-function()
  imenu--make-index-alist(t)
  which-function()
  which-func-update-1(#<window 3 on foo.clj>)
  which-func-update()
  apply(which-func-update nil)
  timer-event-handler([t 0 0 500000 t which-func-update nil idle 0])

borkdude20:04:51

not sure what that is

ericdallo20:04:59

clojure-match-next-def this is from clojure-mode right?

ericdallo20:04:13

cider or cljr could be using that

ericdallo20:04:20

or even just clojure-mode itself

borkdude20:04:22

not connected to cider in that buffer

ericdallo20:04:52

so just clojure-mode , from docs: > Scans the buffer backwards for the next "top-level" definition.

ericdallo20:04:59

what did you do before that hang?