Fork me on GitHub
#emacs
<
2022-10-17
>
mkvlr18:10:08

I’m trying to live-code a completion by finding the inlined compliment namespaces bundled with my cider and add a defsource for it:

(cider.nrepl.inlined-deps.compliment.v0v3v12.compliment.sources/defsource ::my-source
  :candidates #'candidates
  :doc #'doc)
not seeing my candidates function being called though. Has anybody tried this before?

vemv18:10:25

fairly confident that it works. can retry myself if needed. @U0DJ4T5U1 was playing with this recently?

mkvlr19:10:16

hmm, and should I be able to print from the candidates function or should that show up elsewhere (compared to my other print statements)?

vemv19:10:00

printlns might be swallowed - I'd go for an atom

mkvlr19:10:24

ok, tried that as well, I’ll try again

mkvlr19:10:56

still not seeing it (all-sources) does list it though and it has :enabled true

vemv00:10:10

sorry for the delay. This works perfectly for me:

(def calls (atom []))

(defn candidates [prefix ns context]
  (swap! calls conj [prefix ns context])
  [])

(defn doc [s ns]
  (swap! calls conj [s ns])
  nil)

(blah-blah.compliment/defsource ::foo
  :candidates #'candidates
  :doc #'doc)
...after hitting m<TAB> , @calls will have a "m" in it

vemv00:10:51

so I'd suggest to start by that minimally viable snippet. build your way up iteratively - if it stops working, perhaps Compliment has some sort of try/catch

👀 2
mkvlr19:11:47

sorry, took me forever to get back to this. Still can’t get it to work using your snippet, here’s exactly what I have but the calls atom stays empty. Anything I should be doing except typing in Emacs?

(ns my-custom.completion-source)

(defonce calls (atom []))

(defn candidates [prefix ns context]
  (swap! calls conj [prefix ns context])
  [])

(defn doc [s ns]
  (swap! calls conj [s ns])
  nil)

(filter #(clojure.string/includes? (str %) "compliment") (all-ns))

(cider.nrepl.inlined-deps.compliment.v0v3v12.compliment.sources/defsource ::foo
  :candidates #'candidates
  :doc #'doc)

vemv22:11:47

I'd suggest starting by determining if the issue is client-side (elisp) or server-side. try triggering completions over the clojure repl (no elisp involved) after your source has been defined. Do you see the results you'd normally see in Emacs? After that, have the atoms changed?

Drew Verlee01:11:59

the atom stays empty for me too after trying the same code as vemv linked.

Drew Verlee01:11:35

would it be possible to do a quick huddle or something on this? I'm guessing there is something obvious i'm missing about getting the right feedback here.

Drew Verlee01:11:49

i see completions for m<tab> but the atom doesn't change.

Drew Verlee01:11:58

@U5H74UNSF did you get anywhere with this?

Drew Verlee01:11:34

if i call the clojure code directly, (candidates ....) then obviously the atom gets mutated.

Drew Verlee01:11:08

I'm guessing what i'm expecting is for m<tab> to work, but it doesn't because my emacs logic isn't hooked up to complement logic i cloned down. It's been a while sense i messed with this, maybe compliment starts a server and i can tell emacs to talk to it instead of the one created off the code from the official branch.

vemv02:11:19

hey! no, compliment doesn't create any servers. as indicated by the cider.nrepl.inlined-deps.compliment.v0v3v12 prefix, this namespace is 'inlined' by cider-nrepl. your emacs is only talking to cider-nrepl, through nrepl, through cider.el

vemv02:11:04

> (candidates ....) then obviously the atom gets mutated. that's good news. one further experiment you can run is: instead of invoking candidates (presumably from the Compliment library), invoke the cider-nrepl code that invokes the compliment library. i.e simulate what cider-nrepl message does when receiving a completion nrepl "op"

vemv02:11:40

(this code is fairly easy to navigate and comprehend - I'd encourage you to take a look since it's exactly what I'd do. I don't know it by heart!)

vemv02:11:10

this is the ns https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/complete.clj , the only non-obvious thing is that the compliment namespaces get the cider.nrepl.inlined-deps prefix at CI release time.

Phillip Mates14:12:46

was running into this issue today as well. Seems like cider-nrepl has a strict set of compliment sources it uses: https://github.com/clojure-emacs/cider-nrepl/blob/804eec7ae73ba2f0f098a57108359f68966a34c8/src/cider/nrepl/middleware/complete.clj#L25-L35 looks like it was included when clj-suitable support was added (https://github.com/clojure-emacs/cider-nrepl/pull/641) to allow toggling between clj and cljs completion sources. maybe the filtering could be done by having sources include the languages they work over. Or the :enabled map entry could be set to false (https://github.com/alexander-yakushev/compliment/blob/39d444f5d9f15d9ab8499c312e3639c9fc14489d/src/compliment/core.clj#L78)

Drew Verlee07:04:26

I'm picking up this thread again. My confusion is about how to make nrepl accept my custom completion source. I tried adding defining a source and then calling init-source as https://github.com/alexander-yakushev/compliment/wiki/Custom-sources, and afterwards emacs isn't autocompleting using that source. It would make sense if the nprel server with the nrepl middleware was already running with the old version of compliment. But I'm probably not capturing the picture correctly here... Do i have to get that source into cider-nrepl inside this https://github.com/clojure-emacs/cider-nrepl/blob/804eec7ae73ba2f0f098a57108359f68966a34c8/src/cider/nrepl/middleware/complete.clj#L25-L35?