This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-28
Channels
- # aleph (16)
- # announcements (7)
- # asami (4)
- # aws (26)
- # babashka (26)
- # babashka-sci-dev (50)
- # beginners (118)
- # biff (7)
- # calva (15)
- # cider (6)
- # clj-kondo (8)
- # cljs-experience (3)
- # clojure (30)
- # clojure-austin (26)
- # clojure-europe (20)
- # clojure-france (2)
- # clojure-ireland (1)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-spec (7)
- # clojure-uk (6)
- # clojurescript (12)
- # community-development (5)
- # conjure (1)
- # copenhagen-clojurians (3)
- # core-typed (71)
- # cursive (3)
- # datomic (1)
- # emacs (4)
- # fulcro (2)
- # helix (2)
- # introduce-yourself (3)
- # jobs (1)
- # london-clojurians (6)
- # lsp (122)
- # malli (2)
- # missionary (5)
- # overtone (14)
- # pathom (4)
- # polylith (1)
- # reagent (4)
- # reitit (1)
- # releases (1)
- # shadow-cljs (80)
- # testing (10)
- # tools-deps (6)
- # vim (3)
- # xtdb (19)
Just watching the latest stuff go into clojure-lsp for the java integration. Would you consider an option to provide, in the config.edn
a path to the source, in addition to download or not download? For example, on Arch, I already have the sources downloaded, which are installed at /usr/lib/jvm/java-17-openjdk/lib/src.zip
, so would be nice to simply point the config to there.
A key benefit of this, is that I don't have to worry about ensuring the sources are up-to-date. It's someone else's problem 🙂
I've done a PR for this (https://github.com/clojure-lsp/clojure-lsp/pull/882). Happy to change based upon feedback.
@dharrigan that feature is pretty new, so I didn't have time to improve docs that much, but it should be already possible to point to existing java docs
It should work under the existing setting, if not, we should fix and not create a new setting for that
Feel free to change it to use same URI but checking if it's a filename and renaming it to :jdk-source-uri
if false, but uri is still file:///
do analyse? if false and uri is http:// do nothing?
I'll work on automatically finding the source on user's java home if available as mentioned https://clojurians.slack.com/archives/C17JYSA3H/p1648473913261469?thread_ts=1648384269.951629&cid=C17JYSA3H
How to globally turn off unused-public-var
linter in lsp? I have config.edn
containing {:linters {:clojure-lsp/unused-public-var {:level :off}}}
in ~/.clj-kondo/
and ~/.lsp
folders and this still shows the warning
It's in the docs, but I won't be that guy who tells you to RTFM because I enjoy helping people on Slack and I'm "guilty" of this myself too many times as well ;)
What confused me was the existence of ~/.clj-kondo folder with jar inside. But yeah, I skimmed the docs long time ago and have to do it again.
$ ls -l ~/.clj-kondo/
total 16968
-rw-r--r-- 1 tsl tsl 17374672 Mar 8 12:51 clj-kondo-lsp-server-2022.03.09-standalone.jar
have you been using Cursive maybe? that lsp server can be used with Cursive or any other editor, but typically it's used with Cursive
I don't remember any tool that's automatically downloading it, could it be that you have made a script which does so?
Nope, emacs only. Maybe I messed something with the setup. I was trying many things at the beginning of the month. No, rather not downloaded manually. "Rather"...
Example of java navigation in a project that uses lsp4j :-) So it should also work in clojure-lsp itself :) Requires #clojure-lsp-builds
I’m working on a project where all code is in a code
subdirectory of the root of a Git repo — so project.clj
, src
dir, test
dir etc are all in the code
directory.
Some clojure-lsp functionality isn’t working. For example, I don’t see any clj-kondo messages and the number of references to a function is not split into separate counts for tests and other code.
If I move all the contents of the code
directory up a level, all is OK.
Is there some setting I can change to make this project work nicely with clojure-lsp?
Me and @U04V15CAJ have been adding support for Java interop on clj-kondo and clojure-lsp, for now the only java interop we have so far is the find java classes definition from java class usages.
With current nightly build from #clojure-lsp-builds , we support :
• Find a java class if the source (`.java`) is available on classpath
• Find and decompile a java class if no source is available, only .class
, decompiling it to .lsp/.cache/java
• Find a JDK class (e.g. java.util.UUID
), this one was just added recently, and it has some waterfall decisions
◦ First clojure-lsp tries to find a existing JDK src.zip
, this is pretty common on JRE installations, it checks java.home
property, JAVA_HOME
env var, and java
command on PATH
◦ If above is not found, it uses the one specified on :java :jdk-source-uri
(Falbacking to clojure-lsp/jdk-source
https://github.com/clojure-lsp/jdk-source if not set manually) only if :java :download-jdk-source?
is enabled (disabled by default)
We are still improving, and we need to make some minor fixes on clj-kondo, with all of this set and working, all java classes should be found when trying to find a definition 🎉
We should keep this on master a little bit before next release, for those who want to test it, it's possible downloading a nightly build from #clojure-lsp-builds
I made a bb script for myself to download and install the latest nightly. Feel free to copy and adapt.
#!/usr/bin/env bb
(ns lsp-nightly
(:require [babashka.curl :as curl]
[babashka.fs :as fs]
[ :as io]))
(def lsp-nightly "")
(io/copy (:body (curl/get lsp-nightly {:as :stream}))
(io/file "/tmp/nightly.zip"))
(fs/unzip "/tmp/nightly.zip" "/tmp/lsp" {:replace-existing true})
;; :facepalm:, the downloaded zip file contains another zip file
(fs/unzip "/tmp/lsp/clojure-lsp-native-macos-amd64.zip" "/tmp/lsp" {:replace-existing true})
(def dest-dir (or (first *command-line-args*) "/Users/borkdude/Dropbox/bin"))
(fs/copy "/tmp/lsp/clojure-lsp" dest-dir {:replace-existing true})
(.setExecutable (io/file dest-dir "clojure-lsp") true)
Here's a crazy idea, perhaps for the looong future. In IDE's such as IntelliJ, if one is working with Java/Kotlin and has dependencies. You can opt-in to download source as well as the normal jar files. This is done if the artifact in question has also an accompanying -sources
jar located at the same location as the jar, for example:
. Wouldn't it be neato that if in the background and totally opt-in that clojure lsp could download the sources of dependencies if available for clj-kondo analysis...?
@dharrigan What I was thinking is this: you could generate an additional deps.edn with those -sources deps (through some script) and then add that deps.edn as an extra dep via :local/root or -Sdeps. This technique could be used with or without changes to lsp. lsp could also try to do this automatically.
Yeah, To be honest, the decompiler seems to work pretty well, so I'd wait for more testing on that feature
There is also a project called enrich-classpath under the emacs-clojure org that could be used (partially or as inspiration)
Yes, the -sources trick can already done manually too using an alias with extra-deps and then add the alias to the lsp startup command
Probably, I already saw people saying that one of the reasons they stick to cursive is because clojure-lsp doesn't java interop
Yeah, if you've ever used java.time, for instance, having completion is night and day difference to keeping 15 browser tabs open to each class.
Yes, we would like to add support for docs/go-to method definition and eventually completion, baby steps :)
we already have the mechanism on clj-kondo (ASM), we just need to improve it to have those features available on clojure-lsp
btw one thing that I think escaped the various threads we had on the topic was practicalli's aliases https://github.com/practicalli/clojure-deps-edn/blob/fc9f90c51113985938a5a7478d77554f477540f5/deps.edn#L462-L478 It's not drastically different from the various ideas that have been thrown around, but this one seems simple for users to understand and test out At scale it doesn't quite cut it since users will likely forget, misconfigure, etc or even after a correct configuration, switching JDKs would invalidate these aliases, possibly leaving very confusing errors.
And also deps.edn is one big map i.e. no sequential semantics. For all "sources" stuff, if you don't place this stuff at the tail of the classpath, you can and will suffer :)
Pleased to say that with the latest on master, the goto definition using vim + coc is looking good!
Not quite 100% there, for exmaple, if I goto definition on a stringbuffer constructor, it plops me at the top of the decompiled file, rather than at the constructor.
it's no biggie, I can always go to the method by a simple grep. Having the ability just to go to source is fantastic no-matter what!
Those are the little things that are going to be improved over the next couple of months
@UKFSJSM38 considering this example though: perhaps clj-kondo could add :constructor true
:arg-count 0
or so and then maybe clojure-lsp could figure out where to go, into the decompiled file?
I think that would require running a library like java-parser over the decompiled file
I'm not sure if people would be too unhappy if clj-kondo did this work and thus had an dependency on java-parser
then you could call clj-kondo with the decompiled Java file and get on the fly analysis
Yes, ATM clojure-lsp has no logic on how to parse clojure or java, it relies on analysis location, so I think having the location come from kondo would make things easy to implement on clojure-lsp side
If we parse at clj-kondo, we would probably be able to add to analysis args, methods info and more
If ASM support get row/col location, then we may not need java-parser, but I couldn't find that info
but perhaps other people will also happily use the java parsing info if clj-kondo has that dep
btw there's also java doclet stuff we could try to use. I think CIDER uses this and I've also used this but at build time, not in clj-kondo itself
Yeah, I know it would be one more lib, but it would be great for downstreams I think if kondo know more about java
it can generate javadoc stuff but as it does that, it extracts info about constructors, methods etc. it's built into java
See e.g. https://github.com/clj-kondo/clj-kondo/blob/master/extract/clj_kondo/impl/ExtractJava.clj
I don't know if (ToolProvider/getSystemDocumentationTool)
works properly in graalvm and also not if it provides good locations