Fork me on GitHub
#cider
<
2024-03-09
>
Lari Saukkonen09:03:34

Can I somehow add custom completion source to cider-nrepl completion sources?

vemv12:03:59

Sure, it's a matter of adding a defsource to https://github.com/alexander-yakushev/compliment ...cider-nrepl uses Compliment in an 'inlined' manner, via mranderson. If you get a basic POC for your intent we can help you bundling it if needed

vemv12:03:44

Good read: https://github.com/clojure-emacs/cider-nrepl/blob/95ce24bf1f40ef566aed2d073a41c943723cf1bd/src/cider/nrepl/middleware/complete.clj#L65 ...we could modify this piece of middleware to accept a :sources parameter that would extend the default set of sources. That way you wouldn't have to worry about mranderson at all.

Lari Saukkonen17:03:30

Thanks. If I understood correctly, i can currently do it by making my own version of the middleware with altered clj-sources or cljs-sources. With the change you mentioned I could possibly do it by just giving it a parameter in the future.

vemv17:03:21

Yes. You can use make install (exact instructions in readme) and you'll get that artifact installed into ~/.m2

👍 1
Lari Saukkonen16:03:10

I was able to get the complete from cider-nrepl to give me my completitions with repl but not yet with it compiled to .m2 and using emacs. I suppose i need next to try send :op completion to cider-nrepl and see if it returns the same thing.

👍 1
Lari Saukkonen17:03:56

I tried now with sending :op "complete" to make repl initiated nrepl. It returns nil even in the case where i have stub completion that should return something in all cases. :op "eval" works fine. My call:

(with-open [conn (nrepl/connect :port 51244)]
     (-> (nrepl/client conn 1000)    ; message receive timeout required
         (nrepl/message {:op "complete" :prefix ":" :ns "ns" :context "(defn access-pattern [imaginary-subfield] (__prefix__ imaginary-subfield))"} )
         nrepl/response-values))

vemv17:03:33

Nice. Let's go for modify this piece of middleware to accept a :sources parameter that would extend the default set of sources then. Would you be up for a PR? I'd consider it low-hanging fruit (No issue if it turns out to be too much)