Fork me on GitHub
#vim
<
2019-08-19
>
mikepjb07:08:23

Does anyone know how to put the openjdk sources on their classpath to jump from Clojure -> Java code? e.g hitting [C-d on (Runtime/getRuntime) should take me to the java source code. I've downloaded the source using the Arch openjdk10-src package and then setting the path in neovim: au Syntax clojure set path+=/usr/lib/jvm/java-10-openjdk/lib/src.zip

dominicm07:08:28

Setting 'path' like that won't inform the jdk of anything 🙂

dominicm07:08:51

I think there's some code in cider to automatically find that

dominicm07:08:30

You might want to update your ~/.clojure/deps.edn with something like {:deps {jdk-sources {:local/root "/path/to/src.zip"}}}

dominicm08:08:27

(just a guess based on source, please report back)

👍 4
mikepjb08:08:29

No success yet but a few things crossed off:

{:deps
 ;; {jdk-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib/src.zip"}}
 ;; {jdk-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib"}}
 ;; {java-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib"}}
 ;; {java-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib/src.zip"}}
 }
none of these have worked so far, is there a step required to use ~/.clojure/deps.edn?

dominicm08:08:59

nope, automatically loaded.

dominicm08:08:24

I might be lying

dominicm08:08:28

maybe it needs to be in an alias

mikepjb08:08:30

hmm I only say this because if I include this alias

{:deps
 ;; {jdk-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib/src.zip"}}
 ;; {jdk-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib"}}
 ;; {java-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib"}}
 ;; {java-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib/src.zip"}}
 :aliases
 {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "RELEASE"}}
          :main-opts ["-m" "rebel-readline.main"]}}}
I can't do clj -Arebel

mikepjb08:08:39

it doesn't seem to recognise it

dominicm08:08:53

that should definitely work 🙂

dominicm09:08:08

your deps.edn is invalid there ^

dominicm09:08:15

your :deps key doesn't have a value

parrot 4
dominicm09:08:52

just testing this locally

dominicm09:08:16

So, I don't actually have to do anything, because it's picked up automatically for me by cider.

echo fireplace#message({'op': 'info', 'ns': 'user', 'symbol': 'Object'}, type({}))
Gives me a path/`file` entry.

dominicm09:08:47

But you're right that fireplace isn't handling it properly, I can't jump to source on it. I would guess that fireplace is trying to intelligently guess it's a java thing? dunno

dominicm09:08:21

Oh, actually, fireplace#info isn't even returning anything

dominicm09:08:16

Ha 😄 fireplace#info is not sending the 'ns' and it needs to for 'symbol' to work. I think fireplace#info is completely broken right now for using cider.

mikepjb09:08:29

I don't think my system deps.edn is being picked up:

~(!) $ clj -A:rebel
Error building classpath. Specified aliases are undeclared: [:rebel]
~(!) $ cat ~/.clojure/deps.edn 
{:aliases
 {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "RELEASE"}}
          :main-opts ["-m" "rebel-readline.main"]}}}
~(!) $ 
Which doesn't help..

mikepjb09:08:39

ah ok, yeah that's not going to work

dominicm09:08:43

the system deps.edn is different

dominicm09:08:59

do you have $XDG_CONFIG_DIR explicitly set? Or maybe $CLJ_CONFIG?

mikepjb09:08:29

No but I have $XDG_CONFIG_HOME set

dominicm09:08:36

diff --git a/autoload/fireplace.vim b/autoload/fireplace.vim
index 4b72f43..b0e9399 100644
--- a/autoload/fireplace.vim
+++ b/autoload/fireplace.vim
@@ -1798,7 +1798,7 @@ endfunction
 
 function! fireplace#info(symbol) abort
   if fireplace#op_available('info')
-    let response = fireplace#message({'op': 'info', 'symbol': a:symbol}, v:t_dict)
+    let response = fireplace#message({'op': 'info', 'symbol': a:symbol, 'ns': fireplace#ns()}, v:t_dict)
     if type(get(response, 'value')) == type({})
       return response.value
     elseif has_key(response, 'file') || has_key(response, 'doc')
^ basic diff you need

mikepjb09:08:59

ah thanks, looks like it's using XDG so ~/.config/clojure/deps.edn

dominicm09:08:03

okay, in the case you have that set then clojure will read from there instead of ~/.clojure. It's not exactly correct or properly documented.

dominicm09:08:21

Really on Linux it should always look there, but Alex is not interested in that change for some reason.

dominicm09:08:32

(I'm a bit sour about it tbh)

mikepjb09:08:18

fair enough.. I've been collecting a lot of these gotchas in a "What I wish I knew when starting Clojure" document haha

dominicm09:08:35

that's neat 🙂

mikepjb09:08:19

I've applied the diff but I'm still not able to lookup Java source code - I'll pick this up during lunch and let you know if I get this working (thanks again :thumbsup:)

dominicm09:08:51

haven't tested the diff admittedly.

dominicm09:08:05

That patch fixes fireplace#info(), but I guess it doesn't help if it's never called 🙂

dominicm09:08:36

Okay, so fireplace#source() will look at resource for some reason even if there's already a path. I'm not sure why.

dominicm09:08:07

and fireplace#findresource() is not returning the file. When I call fireplace#path() I get nothing back so I think that's why it's broken for me. I think it should really be checking the existing path anyway.

dominicm09:08:11

hmph, and also fireplace doesn't handle the jar:file prefix apparently... 😔

dominicm09:08:03

I have something confirmed working locally

dominicm09:08:13

elseif get(info, 'file', '') =~# '^jar:file:'
    let zip = matchstr(info.file, '^jar:file:\zs.*\ze!')
    let file = 'zipfile:' . zip . '::' . info.resource
^ this is the general code, but the if statements need some reordering too. That's

dominicm09:08:21

need to work now, but if you could test & pr that would be cool 😛

👍 4
mikepjb12:08:58

Hi @dominicm, trying to get this PR together - I am getting a blank array back as file at the point you're checking for '^jar:file'

with extra-deps openjdk:
{'status': ['done'], 'file': [], 'throws': [], 'javadoc': '', 'modifiers': '#{:publi
c :static}', 'id': 'e5392260-d43e-4b8e-f6af-4c69c86240d2', 'session': ['4c3e7750-88b8-45ea-a2c9-6de4af55aa4b'], 'returns': 'java.lang.Runtime', 'class': 'java.l
ang.Runtime', 'argtypes': [], 'member': 'getRuntime', 'arglists-str': '[]'}
(I got this back when running FireplaceJumpD against (Runtime/getRuntime) inside clojure/java/shell.clj from stdlib)

mikepjb12:08:22

I am guessing this means that I still do not have the local source setup properly

dominicm12:08:36

Try it on "Object"

dominicm12:08:49

you can do something like fireplace#info('Object')

mikepjb12:08:27

I am getting an empty dictionary for echo fireplace#info('Object')

mikepjb12:08:16

I'm starting the repl with clj -A:nrepl using this deps.edn

{:deps
 {org.clojure/clojure {:mvn/version "1.10.1"}}
 :paths ["src"]
 :aliases
 {:nrepl {:extra-deps {nrepl {:mvn/version "RELEASE"}
                       cider/cider-nrepl {:mvn/version "0.21.1"}
                       jdk-sources {:local/root "/usr/lib/jvm/java-10-openjdk/lib/src.zip"}}
          :main-opts ["-m" "nrepl.cmdline"
                      "--middleware" "[cider.nrepl/cider-middleware]"]}
  :build {:extra-deps {pack/pack.alpha
                       {:git/url ""
                        :sha "dccf2134bcf03726a9465d2b9997c42e5cd91bff"
                        :exclusions [org.slf4j/slf4j-nop]}}
          :main-opts ["-m" "mach.pack.alpha.capsule citadel.jar"
                      "-m" "citadel.core"]}}}
which I *think* should give me access to the openjdk source code The diff for vim-fireplace I have so far is:
diff --git a/autoload/fireplace.vim b/autoload/fireplace.vim
index 4b72f43..4a7ad3a 100644
--- a/autoload/fireplace.vim
+++ b/autoload/fireplace.vim
@@ -1798,7 +1798,7 @@ endfunction
 
 function! fireplace#info(symbol) abort
   if fireplace#op_available('info')
-    let response = fireplace#message({'op': 'info', 'symbol': a:symbol}, v:t_dict)
+    let response = fireplace#message({'op': 'info', 'symbol': a:symbol, 'ns': fireplace#ns()}, v:t_dict)
     if type(get(response, 'value')) == type({})
       return response.value
     elseif has_key(response, 'file') || has_key(response, 'doc')
@@ -1846,6 +1846,9 @@ function! fireplace#source(symbol) abort
     let file = fireplace#findresource(info.resource)
   elseif get(info, 'file', '') =~# '^file:'
     let file = substitute(strpart(info.file, 5), '/', s:slash(), 'g')
+  elseif get(info, 'file', '') =~# '^jar:file:'
+    let zip = matchstr(info.file, '^jar:file:\zs.*\ze!')
+    let file = 'zipfile:' . zip . '::' . info.resource
   else
     let file = get(info, 'file', '')
   endif

dominicm14:08:32

in fireplace#source you need to move the if !empty(get(info, 'resource')) down to a later elseif, because most things have a resource

👍 4
mikepjb15:08:10

I starting executing some of the clojure code in fireplace#info and discovered that for me, calling special-doc on Object doesn't return a file:

user=> (#'clojure.repl/special-doc 'Object)
{:name Object, :special-form true}
user=> (#'clojure.repl/special-doc 'defn)
{:added "1.0", :ns #object[clojure.lang.Namespace 0x70331432 "clojure.core"], :name defn, :special-form true, :file "clojure/core.clj", :column 1, :line 283, :m
acro true, :arglists ([name doc-string? attr-map? [params*] prepost-map? body] [name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?]), :doc "Sa
me as (def name (fn [params* ] exprs*)) or (def\n    name (fn ([params* ] exprs*)+)) with any doc-string or attrs added\n    to the var metadata. prepost-map de
fines a map with optional keys\n    :pre and :post that contain collections of pre or post conditions."

dominicm15:08:25

There's no file for special docs

dominicm15:08:43

They are special forms, basically magic

mikepjb15:08:34

Oh yes, (#'clojure.core/special-symbol? 'Object) returns false anyway so that part of the cond doesn't apply