Fork me on GitHub
#cider
<
2021-07-21
>
lassemaatta14:07:35

assuming I have a leiningen project with local java classes (ie. stuff under :java-source-paths): does cider (or perhaps clojure-lsp?) support navigating to those classes (and/or displaying documentation) when I import/reference them in my clojure namespaces? I can access the documentation (`C-c C-d C-d`) for e.g. the JDK classes and other java sources in the dependencies (after tinkering with the resolve-java-sources-and-javadocs plugin), but for some reason I can't figure out how to do this for local java sources. (Disclaimer: I'm very much a beginner in emacs/cider)

ericdallo15:07:21

clojure-lsp doesn't support it, but there is an open issue for that feature, it'd need changes on clj-kondo probably

👍 2
vemv17:07:03

This is solved https://github.com/clojure-emacs/enrich-classpath and a public alpha will be released as soon as Clojars solves an administrative issue

ericdallo17:07:20

oh, I didn't know about that lib, does it plays well with clj-kondo?

vemv17:07:41

Maybe. It helps tools (like deps.edn or Leiningen) to add items to the classpath. It's not a runtime library.

ericdallo17:07:47

yeah, @U04V15CAJ that may help with that idea of supporting java source on clj-kondo/clojure-lsp ?

vemv17:07:20

btw @U0178V2SLAY I read too quickly your question and didn't notice you mentioned resolve-java-sources-and-javadocs (which is the former name of enrich-classpath). Happy you're giving it use and seeing some success. I think you're mentioning a different use case ("local" java sources). I assume this refers to .java files located within your project? That seems a slightly different use case.

lassemaatta17:07:02

yeah, exactly

vemv17:07:15

nice :) I think you can open an issue in https://github.com/clojure-emacs/cider-nrepl explaining the issue in detail (and mentioning that you already are using this plugin). Will be happy to give it a read. Not sure if it's something that should be solved by the plugin, or by cider

lassemaatta17:07:03

sure, I can try to write up what I was trying to achieve. As I'm quite new to both cider & lsp, I was mostly pondering if this is a functionality that's already provided by some component, but which I haven't configured properly.

vemv17:07:56

Because this plugin is new and there practically wasn't a solution for this problem in the preceding years, I think this is not a very often explored area. People are used for Java integration to not work at all. So it wouldn't surprise me if you found a genuine edge case!

🙂 3
borkdude17:07:11

@UKFSJSM38 clj-kondo already supports linting arities for static methods on built-in Java classes. Guess how many times this has helped me in the last two years? 0 times :) So linting for Java interop doesn't add a lot of value imo, but being able to navigate to them, could surely be useful.

ericdallo17:07:57

Agreed, I think navigation is the priority indeed, you are right

vemv17:07:42

As for linting, Eastwood lints for arities (static and instance methods), deprecations, etc from arbitrary Java deps (without requiring the .java sources to be present). It helps from time to time As always, I'm perfectly fine with the two most prominent linters having different areas of focus. In the average project I'll run both clj-kondo and Eastwood (the former fail-fasting the second for a nicer feedback loop, in CI)

borkdude17:07:41

> (without requiring the .java sources to be present). yeah, I implemented the static arity info first using the javadoc stuff, but later on I realized that can just be done using reflection facepalm I have an issue to revisit that, but when the actual sources are available, then the javadoc approach might still have value as the mapping between source and Java class/methods can be made

🙂 3
borkdude17:07:37

I think clj-kondo could provide arity info + analysis info for navigation based on analyzing the source. I just wonder if there is a better analyzer than the javadoc stuff that is also compatible with graalvm native-image. I haven't tried running the javadoc stuff at runtime

borkdude17:07:20

@U45T93RA6 how does eastwood know what class is being called using an instance call, does it always know also in the presence of reflection? how?

vemv17:07:39

> I just wonder if there is a better analyzer than the javadoc stuff that is also compatible with graalvm native-image. I haven't tried running the javadoc stuff at runtime Orchard has a variety of parsers and fallbacks. I think some of them work better in concert with https://github.com/clojure-emacs/enrich-classpath

borkdude17:07:25

can you be more specific?

vemv17:07:56

> how does eastwood know what class is being called using an instance call, does it always know also in the presence of reflection? how? it doesn't know in face of reflection. In the codebases I generally work on reflection is a no-go and will have 0 reflection warnings. The https://github.com/jonase/eastwood#reflection linter emphasizes this ideal so hopefully it will be no-go for more people (increasing Eastwood accuracy as well for the instance call linting)

borkdude17:07:10

Perhaps that stuff works in GraalVM though, never tried

borkdude17:07:39

if it does, then when its given an "enriched" classpath, there might be some gains to be made, also with respect to instance methods

rich 3
vemv17:07:21

there's https://javaparser.org/ btw, seems simpler than parsing javadoc

lassemaatta11:07:47

I attempted to document my original question under https://github.com/clojure-emacs/cider-nrepl/issues/700

lassemaatta06:08:18

thanks, I'll check it out later 🙂

👍 4