Fork me on GitHub
#cider
<
2020-04-03
>
yuhan06:04:46

Just to be sure I'm not missing anything - does Cider currently offer any way to view the constructor types or arguments for a Java interop form? eg.

(Classname. ,,,) 
cider-doc and eldoc don't appear to display any relevant information.

yuhan06:04:17

More concretely, something like (Integer. 1.0) throws the error "No matching ctor found" without any hint of what ctors it's matching against, and I end up having to leave Emacs and trawl through Javadocs to figure out what what the constructors and argument types are.

bozhidar07:04:03

@qythium This certainly worked at some point - you’d get all the constructors in the eldoc.

bozhidar07:04:40

What’s your JDK? Many Java-related things broke after Java 8 because of the modules system.

yuhan07:04:00

I'm using jdk 11

bozhidar07:04:08

Can you check if this works differently with JDK 8?

jumar08:04:41

I'm not sure if that ever worked or not; I guess I'm looking at constructors very infrequently. @qythium for your particular case it could be better to look at static methods just typing Integer/, pressing TAB for autocomplete and "showing javadoc" via Shift+K (in Spacemacs) works for me (parameters are shown, not actual javadoc). @bozhidar It's true that lot of things (like javadoc and source code navigation) broke after switch to JDK >8; It would be nice to know if there are any future plans to address this soon since JDK 8 has become quite old at this point 🙂

bozhidar08:04:51

@jumar Plans I have plenty, but with so many projects that I’m juggling I’m certainly short on time. 🙂

yuhan09:04:25

Nope, doesn't work with JDK 8 either on my end

yuhan09:04:08

@jumar K (cider-doc) -> show javadoc works for certain builtin classes but not external libraries, and it opens in a separate web browser app

jumar10:04:51

Mine shows inline docs, it's not the same as standard javadoc function; That's also why it works for some external libs - they are defined here: https://github.com/clojure/clojure/blob/master/src/clj/clojure/java/javadoc.clj#L29-L41

yuhan10:04:28

Do you know the Emacs command name for that? M-x cider-javadoc?

yuhan10:04:41

or is it that you have URLs set to open within Emacs, using EWW or something?

jumar12:04:32

I think it's just cider-doc

yuhan09:04:14

Does it work on anyone else's setup? If it's a missing feature I could open an issue in the relevant GH repo (orchard / cider-nrepl)

bozhidar09:04:41

For external classes you have to have the source jars on your classpath.

bozhidar09:04:53

(regardless of the JDK version)

yuhan09:04:39

Meaning jars that were downloaded from Maven and which I can import from my repl?

yuhan09:04:32

Some external libraries work but not others, I guess not every package has a generated javadocs website (not sure how that works)

introom09:04:17

when I use projectile-toggle-between-implementation-and-test to switch between test and src file. I got: No matching test file found for project type ’generic

introom09:04:27

any thing I need to configure for that ?

introom09:04:58

found this: projectile-register-project-type . maybe I should tweak it.

yuhan09:04:45

Are you in a lein / deps project?

introom10:04:00

I see. projectile tells the project type on the top level project.clj

introom10:04:28

.projectile subfoler/project.clj

introom10:04:30

this wont do it.

introom10:04:05

I am in the middle of (apply |caret| str (reverse “asdf”))

introom10:04:18

what function should I invoke to evaluate the (apply str (reverse “asdf”)) .

introom10:04:50

cider-eval-sexp-at-point . evaluates “apply”

practicalli-john10:04:33

@i to get projectile to work with a mono-repo (multiple clojure projects within a project) I used the following .dir-locals.el file https://github.com/practicalli/codewars-guides/blob/master/.dir-locals.el This enables projectile to toggle between implementation and test correctly. It should work for both deps and leiningen projects

practicalli-john10:04:57

You can change nil to clojure-mode if you want to limit the scope to clojure (something I forgot to do). I dont think it causes any side effects as it is anyway.

practicalli-john10:04:41

@i you wish to evaluate the top level expression, so its cider-eval-defun-at-point or as its on the same line, you could also do cider-eval-sexp-end-of-line but the defn command is generally more useful.

introom11:04:39

(defn reverse-string [s] ;; <- arglist goes here ;; your code goes here (apply <caret> str (reverse “asdf”)))

introom11:04:03

neither of the two functions evaluates the (apply str (reverse “asdfasf”)) stuff

yuhan12:04:16

I made my own wrapper for this purpose - basically (up-list) then (cider-eval-last-sexp)

practicalli-john15:04:22

@i those functions work for the original question you asked. Now you have changed the code by wrapping it in a defn. I dont understand what you are trying to do now, there is no point wrapping it in a defn if you are not using the argument received by the defn. Replace the "asdf" with s (a terrible arg name by the way) and then just write an expression to call the defn and evaluate that. (reverse-string "asdf") . Using eval-defn works with this expression and is what your tests will do (I assume you doing the exercism challenge this comes from)

Mitch11:04:46

and you just put that at the root of the monorepo? much nicer than running touch .projectile on all my subprojects

practicalli-john11:04:40

Yes, having one .dir-locals.el worked more effectively for me than the .projectile files.

bowie 4
Mitch14:04:12

works like a charm! awesome trick

introom11:04:41

i put a dummy project.clj at . the top level.

introom11:04:57

@jr0cket thanks. especially for your website docs.

👍 4
yuhan11:04:12

after doing a bit of hacking around in orchard.java I found the following to work in both cider-doc and eldoc:

(in-ns 'cider.nrepl.inlined-deps.orchard.v0v5v7.orchard.java) ;; or replace with your corresponding inlined ns

(reset! cache {})

(defn type-info
  "For the class or interface symbol, return Java type info. If the type has
  defined contructors, the line and column returned will be for the first of
  these for more convenient `jump` navigation."
  [class]
  (let [info       (class-info class)
        ctors      (vals (get-in info [:members class]))
        first-ctor (->> ctors
                     (sort-by :line)
                     (filter :line)
                     (first))]
    (-> info
      (dissoc :members)
      (assoc :arglists
        (map #(if (:argnames %)
                (mapv (fn [n t] (symbol (str t " " n))) (:argnames %) (:argtypes %))
                (:argtypes %)) ctors))
      (merge (select-keys first-ctor [:line :column])))))

bozhidar08:04:36

@qythium I think it’s best to submit this as GH ticket/PR, so it’s easier to discuss the code there. Slack is poorly suited for this purpose IMO. 🙂

yuhan08:04:38

done as a draft PR :)

yuhan12:04:24

I'm probably doing something questionable by constructing a symbol with a space in it.. I wonder how else to represent both the type and arg name

yuhan12:04:52

Would appreciate if someone could help test this out informally before I package it into a PR for orchard - my JVM knowledge is pretty minimal and I could be missing something

FiVo16:04:11

I think I have asked this question before, but can't remember the answer. I installed a local version of nrepl via lein install and now removed it from ~/.m2/... but when I jack in it still says nREPL 0.7.0-alpha3.

bozhidar16:04:15

@finn.volkel You need to update your CIDER snapshot.

bozhidar16:04:45

CIDER specifies the version of nREPL to use internally if you’re using cider-jack-in.

FiVo16:04:28

What exactly do you mean? I upgraded cider today actually, am now on 0.25.0snapshot.

bozhidar16:04:24

See cider-nrepl-required-version. CIDER plugs this into the command it uses to start the server.

FiVo08:04:00

thanks, it's now on the correct version. I don't know what I did, but today it's the correct verison.

practicalli-john21:04:30

@finn.volkel sounds like you have nrepl version set in Leiningen profil

mafcocinco21:04:34

Having trouble with Spacemacs. Has been working great for the last 2 years or so but today, for some reason, my `*cider-repl*` buffer stopped launching for no reason that I have been able to discover. I've tried multiple launching different projects, thinking maybe there was something in the configuration of a specific project, which did not work. I've tried creating a new project, which also did not work. I moved my previous `.emacs.d` folder to a backup location and create a fresh install of Spacemacs but no luck. Here is the tall end of the `*Messages*` buffer for the fresh install

mafcocinco21:04:48

Done (Total of 1 file compiled, 2 skipped)
(Spacemacs) --> installing package: [email protected] [155/155]
Auto-evilification could not remap these functions in map 'edebug-mode-map':
   - 'edebug-Go-nonstop-mode' originally mapped on 'G'
Auto-evilification could not remap these functions in map 'tar-mode-map':
   - 'tar-chgrp-entry' originally mapped on 'G'
(Spacemacs) Warning: tern binary not found!
Loading /Users/marcusoladell/.emacs.d/layers/+distributions/spacemacs-base/keybindings.el (source)...done
Loading /Users/marcusoladell/.emacs.d/layers/+source-control/version-control/keybindings.el (source)...done
Loading /Users/marcusoladell/.emacs.d/.cache/recentf...done
Saving file /Users/marcusoladell/.spacemacs...
Wrote /Users/marcusoladell/.spacemacs [2 times]
Spacemacs is ready.
Open the quickhelp.
Start checking for new version...
Spacemacs is up to date.
[yas] Check your `yas-snippet-dirs': /Users/marcusoladell/.emacs.d/elpa/yasnippet-20200329.1434/snippets is not a directory
[yas] Prepared just-in-time loading of snippets with some errors.  Check *Messages*.
[nREPL] Starting server via /usr/local/bin/lein update-in :dependencies conj \[nrepl\ \"0.7.0\"\] -- update-in :plugins conj \[refactor-nrepl\ \"2.5.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.0-SNAPSHOT\"\] -- repl :headless :host localhost
Quit
[nREPL] Starting server via /usr/local/bin/lein update-in :dependencies conj \[nrepl\ \"0.7.0\"\] -- update-in :plugins conj \[refactor-nrepl\ \"2.5.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.0-SNAPSHOT\"\] -- repl :headless :host localhost
<left-fringe> <drag-mouse-1> is undefined

mafcocinco22:04:07

Many of these warnings or errors I have seen before things went sideways today. Not sure if they are relevant to what is happening. The `nrepl-server` launches successfully. I just don't get any `*cider-nrepl*` buffer connected to it. 😕

bozhidar08:04:54

I don’t see any CIDER-specific errors in the log you’ve posted. You might want to check https://docs.cider.mx/cider/troubleshooting.html

didibus17:04:28

Does your code compiles sucessfully?

didibus17:04:50

I've noticed sometimes launching nRepl when your source is broken makes it crash

didibus17:04:09

Well, might not be nRepl, but lein repl

mafcocinco13:04:06

It does. in the end, it was a versioning issue with various pieces of the middleware.

mafcocinco22:04:35

(originally posted this to #spacemacs but seems more appropriate here)