Fork me on GitHub
#cider
<
2022-03-19
>
Chicão19:03:22

hello, i'm trying to import some java lib at clojure code and i'm using emacs, someone knows how could I see javadoc or parameters from those function at java code that I'm importing into my clojure code. I already tried with clojure-lsp but they don't have support yet to this. Does anyone know if cider do this?

magnars21:03:10

Yes, CIDER will give you autocompletion and parameter signatures for java code.

Chicão23:03:04

could I go to definition inside java lib import it on clojure code?

Chicão23:03:56

I'm working with jgit java and would like to go to some definition inside java lib, like intellij do. Is this possible with emacs doom?

vemv23:03:16

yes, 100%, javadocs and sources. You'd have to enable this option https://github.com/clojure-emacs/cider/blob/1e27eba570d265bc27317dc2a8f8c98d8b5414e0/cider.el#L428-L436 It only works for Lein projects. It's disabled by default because in big projects, occasionally it can create issues. Both things will be fixed in the next major CIDER release

👍 1
practicalli-johnny09:03:36

For Java open source projects, I download the source code for the project and add the Java source code to the classpath. (I think this is what the enrich paths function does in the background) I use Clojure CLI and add the Java source code via an alias, adding an :extra-paths that points to the Java source directory or zip archive

👍 1
Chicão15:03:13

nice, i will try it.

Chicão15:03:45

@U05254DQM this is my deps.edn, i'm trying go to jgit definitions, but jump to definition did not work. Even doc about the function/classes. I put extra-paths with the jgit source code.

{:paths     ["src"]
 :mvn/repos {"jgit-repository" {:url ""}}
 :deps      {org.clojure/clojure               {:mvn/version "1.10.2"}
             org.clojure/data.json             {:mvn/version "1.1.0"}
             org.clojure/tools.logging         {:mvn/version "1.2.4"}
             clj-jgit/clj-jgit                 {:mvn/version "1.0.2"
                                                :exclusions  [org.eclipse.jgit/org.eclipse.jgit.gpg.bc]}
             clucie/clucie                     {:mvn/version "0.4.2"}
             environ/environ                   {:mvn/version "1.2.0"}
             middlesphere/clj-compress         {:mvn/version "0.1.0"}
             talltale/talltale                 {:mvn/version "0.4.3"}
             org.eclipse.jgit/org.eclipse.jgit {:mvn/version "6.0.0.202111291000-r"}}
 :aliases   {:run     {:ns-default chrondb.core
                       :exec-fn    chrondb.core/-main}
             :extra-paths ["/Users/matheusfrancisco/m/dev/jgit"]
             :test    {:extra-paths ["test"]
                       :extra-deps  {clj-kondo/clj-kondo {:mvn/version "2022.02.09"}
                                     com.cognitect/test-runner
                                     {:git/url ""
                                      :sha     "76568540e7f40268ad2b646110f237a60295fa3c"}}
                       :main-opts   ["-m" "cognitect.test-runner" "-d" "test"]}
             :depstar {:extra-deps {seancorfield/depstar {:mvn/version "2.0.171"}}}
             :uberjar {:replace-deps {seancorfield/depstar {:mvn/version "2.0.171"}}
                       :name         "chrondb-standalone.jar"
                       :exec-fn      hf.depstar/uberjar
                       :exec-args    {:aot        true
                                      :jar        "chrondb.jar"
                                      :main-class "chrondb.core"
                                      :sync-pom   true}}}} 

Chicão15:03:59

with project.clj adding the jgit to dependencies it work, but needs to type (.org.eclipse.jgit.lib.Repository) the whole path to goto definition work.

Chicão15:03:21

with deps.edn I couldn't be able yet to config this on emacs

practicalli-johnny18:03:08

@UL618PRQ9 To include the Java standard library sources, I create an alias as follows (with the zip of the sources manually downloaded to the path specified)

:src/java17
  {:extra-deps
   {openjdk/java-sources {:local/root "/usr/lib/jvm/openjdk-17/lib/src.zip"}}}

practicalli-johnny18:03:37

I believe you should just need to move the jgit :extrapaths into the :run alias scope in the deps.edn file above

:aliases
{
:run {:extra-paths ["/Users/matheusfrancisco/m/dev/jgit"]
      :ns-default chrondb.core
      :exec-fn    chrondb.core/-main}
,,,
}             

practicalli-johnny18:03:08

Or probably they need to be a :local/root to work (I havent tried just using the path), so that would then be

:aliases
{
:run {:extra-deps {jgit/src {:local/root "/Users/matheusfrancisco/m/dev/jgit"}}
      :ns-default chrondb.core
      :exec-fn    chrondb.core/-main}
,,,
}    

practicalli-johnny18:03:52

The jgit sources can be cloned from the Eclipse foundation Git service https://git.eclipse.org/c/jgit/jgit.git/ I assume the sources are not distributed in the jar files obtained from the Eclipse Maven repository, so should be downloaded separately.

git clone  /Users/matheusfrancisco/m/dev/jgit

👍 1
practicalli-johnny18:03:41

I made an example project here: https://github.com/practicalli-john/jgit-hack There are several sub projects under the cloned repository above (I dont know if they are all needed). If other sub-projects are needed, then add an :extra-deps for each sub-project. In the jgit-hack project it only includes org.eclipse.jgit, so that is probably the only functions that will auto-complete and for which cider-find-var command will work. cider-find-var need a running repl process and at least one namespace from the clojure project to be evaluated (standard Cider function behaviour)

❤️ 2
thanks3 2
Chicão19:03:49

i tried with your repo, thanks a lot , it worked very well with deps.edn

👍 1