nrepl

pez 2025-03-25T12:55:41.067079Z

With Calva looking up info on first in (. clojure.lang.RT (first coll)) below takes you to the def . Is there something I can do to at least say “can’t look this up” or something?

(def
 ^{:arglists '([coll])
   :doc "Returns the first item in the collection. Calls seq on its
    argument. If coll is nil, returns nil."
   :added "1.0"
   :static true}
 first (fn ^:static first [coll] (. clojure.lang.RT (first coll))))

pez 2025-03-25T12:56:00.770879Z

Calva uses info for this.

oyakushev 2025-03-25T13:10:18.463329Z

What cider-nrepl version are you on right now?

oyakushev 2025-03-25T13:11:02.558329Z

Ah, wait. Do you consider this behavior "wrong"?

pez 2025-03-25T13:12:14.995849Z

nrepl: 1.3.1
    cider-nrepl: 0.52.1

oyakushev 2025-03-25T13:12:55.040479Z

info doesn't use any context, and first is a valid function, so this is not really a bug in nrepl or cider-nrepl

pez 2025-03-25T13:13:52.003549Z

I’m not saying it is a bug. 😃 I am wondering if there is something I could do differently to not give this wrong answer to the Calva user.

oyakushev 2025-03-25T13:14:21.231909Z

CIDER treats it as first function too, e.g. the minibuffer hint:

pez 2025-03-25T13:14:56.165939Z

Calva is proud of being distilled from CIDER.

pez 2025-03-25T13:16:14.555339Z

I think part of this is that I suck a bit at reading interop code like that. So at first it looked like a recursive call, which didn’t make sense, then command-clicking seemed to confirm. 😃

➕ 1
pez 2025-03-25T13:16:42.291569Z

I guess my hope was that there was a way to provide context.

oyakushev 2025-03-25T13:16:58.259699Z

Unless you employ a full-blown parser/analyzer to process the whole top-level form first and understand what kind of first you are looking at, there is not really a way to do it, and it doesn't make the answer strictly wrong

➕ 1
oyakushev 2025-03-25T13:17:56.736179Z

Which is probably possible to do and may be beneficial, albeit mostly for other cases where context matters.

oyakushev 2025-03-25T13:18:44.901869Z

Cue this form:

(let [first second]
  (first coll))
Info on first here will also be "wrong"

oyakushev 2025-03-25T13:21:03.967219Z

Actually, there is a way to pass precisely "context" to info, but it doesn't handle such interop cases

oyakushev 2025-03-25T13:23:15.425269Z

If you feel this is important, you can consider submitting a fix for it. I'm still wondering how useful that will be. I've never seen this raw interop form anywhere beyond clojure.core.

pez 2025-03-25T13:24:06.304439Z

Ah, looks like I should provide context at least, even if it doesn’t handle these cases.

pez 2025-03-25T13:24:46.621509Z

Doesn’t look like it handles the let binding case, either, right?

oyakushev 2025-03-25T13:24:51.599519Z

Nope

oyakushev 2025-03-25T13:25:17.050279Z

It only improves lookups for cases like (.someMethod ^MyClass x)

oyakushev 2025-03-25T13:25:42.005779Z

Where the presence of the type hint helps cider-nrepl pick up the target class for info

pez 2025-03-25T13:25:48.104899Z

Calva allows the user to choose between prioritizing dynamic (nrepl) lookup info and static (clojure-lsp). Default is dynamic, because that makes the most sense to me. But here clojure-lsp makes the correcter call for both cases. It does use a full blown parser, so not so strange.

oyakushev 2025-03-25T13:26:55.188589Z

And I assume if it were (. clojure.lang.RT (contains something)) then it would work because contains is not a valid function

pez 2025-03-25T13:27:30.294789Z

I wasn’t here to suggest changes to how cider-nrepl does it. But to get enlighted. And that worked. 😃

❤️ 1
oyakushev 2025-03-25T13:30:03.844869Z

Have you considered giving lsp a higher priority over cider-nrepl results? Will it lead to worse UX?

pez 2025-03-25T13:31:43.888739Z

Calva has a setting allowing that. But for me the REPL is my truth so have left this at the default.

pez 2025-03-25T13:32:40.112889Z

But I can look into if I can make the selection smarter. Right now it similar to (or nrepl clojure-lsp).