Fork me on GitHub
#cider
<
2022-11-06
>
Drew Verlee04:11:59

I followed the instructions to get fuzzy candidate matching in cider here https://docs.cider.mx/cider/usage/code_completion.html#fuzzy-candidate-matching here is the variable

cider-repl-mode-hook is a variable defined in 'cider-repl.el'.

Its value is
(cider-company-enable-fuzzy-completion spacemacs/toggle-evil-safe-lisp-structural-editing-on spacemacs//activate-smartparens eldoc-mode spacemacs//init-company-cider-repl-mode company-mode)
But i don't get fuzzy matching. (see picture) What should i try next?

Drew Verlee04:11:38

complete does seem to have the fuzzy matches

(cider.nrepl.middleware.complete/complete {:ns 'core
                                           ;; grab all functions starting by c:
                                           :prefix "mi"})
;; => ({:candidate "min", :type :function, :ns "clojure.core"}
;;     {:candidate "min-key", :type :function, :ns "clojure.core"}
;;     {:candidate "map-indexed", :type :function, :ns "clojure.core"}
;;     {:candidate "mix-collection-hash", :type :function, :ns "clojure.core"})

Drew Verlee04:11:22

this is going to be because lsp is doing the completion or something. I remember this being annoying like a year ago.

Drew Verlee04:11:48

same...

ELISP> (cider-sync-request:complete "mi" (cider-completion-get-context) )
((dict "candidate" "min" "ns" "clojure.core" "type" "function")
 (dict "candidate" "min-key" "ns" "clojure.core" "type" "function")
 (dict "candidate" "map-indexed" "ns" "clojure.core" "type" "function")
 (dict "candidate" "mix-collection-hash" "ns" "clojure.core" "type" "function"))

Drew Verlee04:11:25

Only slightly related, i also tried to follow the instructions here to change my https://nrepl.org/nrepl/usage/misc.html#code-completion

You can either specify a custom completion function in the requests (via the complete-fn key) or by setting nrepl.middleware.completion/*complete-fn*.

user=> (set! nrepl.middleware.completion/*complete-fn* my.namespace/my-completion)
And it threw an exception when i called set! (see picture ty šŸ™‚ )

Drew Verlee04:11:59

cider version 1.5.0.

vemv11:11:17

generally only a few dyn vars (those bundled with a clojure repl) can be freely set!-table you need to use binding instead

Drew Verlee21:11:08

@U45T93RA6 i'm starting to think that nrepl doesn't use the compliment library directly sense version 0.8. I traced nrepl.middleware.completion/complete-fn to This

(ns nrepl.util.completion
  "Code completion functionality.

  The functionality here is experimental and
  the API is subject to changes."
  {:author "Bozhidar Batsov"
   :added  "0.8"}
  (:require [clojure.main]
            [nrepl.misc :as misc])
  (:import [java.util.jar JarFile]
           [ File]
           [java.lang.reflect Field Member]
           [java.util.jar JarEntry]
           [java.util.concurrent ConcurrentHashMap]))

;; Code adapted from Compliment ()
and I'm going to be reading this post from 2020 about completion changes. Just sharing with you in case it's news to you as well. https://metaredux.com/posts/2020/06/15/nrepl-0-8-evolving-the-protocol.html

vemv21:11:35

you are assessing nrepl, while you should be assessing cider-nrepl for what concerns us here, nrepl.util.completion powers completions in e.g. lein repl completions, but is otherwise irrelevant to cider's machinery

vemv21:11:48

(sorry if that is confusing!)

vemv21:11:52

in the end nrepl can be thought of simply as a pipe - https://github.com/clojure-emacs/cider-nrepl has most if not all of the features you get to use in CIDER

Drew Verlee22:11:35

By lein repl, were talking about the repl started at the command line by lein?

vemv22:11:01

yes

šŸ‘ 1
šŸ™ 1
bozhidar07:11:09

@drewverlee Iā€™d suggest filing a couple of tickets, so we can properly follow up on both issues.

šŸ‘€ 1
Drew Verlee10:11:13

How do i ask emacs to tell me what's doing the completion? I suspect this might not even be a cider issue. This has been nagging me for years and i can't seem to figure it out, in part because i don't know how to get good diagnostic info to share with anyone. :(

Drew Verlee11:11:42

i think the completion-styles-alist might be what lists all the completion functions (the name is misleading if so)

Drew Verlee11:11:48

fwiw, i more or less did https://github.com/clojure-emacs/cider-nrepl/issues/732 a year ago, and though the context (shadow-cljs) was slightly different, i don't think those differences matter much here, and I think my confusion and the reason completion doesn't work as expected in multiple areas is probably the same. fwiw trying the completion across two emacs profiles. Spacemacs and a nearly fresh install of Doom. but sure ill open another ticket in the morning šŸ™‚ .