compliment
compliment copied to clipboard
Proposal: allow for filtering sources using predicate
description
allow the :sources
option for compliment.core/completion
and compliment.core/documentation
work with a predicate function that operates over source definition maps (like {:candidate ... :doc ... :enabled true :name :my.project/custom-source}
). This would allow for downstream libraries such as cider-nrepl
to include/exclude certain sources but remain open to user-contributed sources.
problem context
I'm working to create some custom autocomplete functionality for a Clojure project and a colleague pointed me to this library; I'm very excited to see a tool that will work with both neovim and emacs!
I tried to define my own source via something like the following
(defn init-source []
(try (require 'cider.nrepl.inlined.deps.compliment.v0v3v14.compliment.core)
((resolve 'cider.nrepl.inlined.deps.compliment.v0v3v14.compliment.sources/defsource) ::my-special-autocompletion-source
:candidates (constantly #{{:candidate "java.whatever" :type :class}})
:doc (constantly nil))
(catch Exception ex ex)))
(init-source)
I wasn't able to get it to work via cider-nrepl
(similar to these folks on clojurians). That said the following used the new source:
(cider.nrepl.inlined.deps.compliment.v0v3v14.compliment.core/completions "1")
;; =>
({:candidate "java.whatever", :type :class})
The reason for this being that cider-nrepl
has an allow-list of sources to consider.
The changes here are
with it, the cider-nrepl
allow-lists could become the following
(def clj-sources #(not= :cljs (:language %)))
(def cljs-sources #(= :cljs (:language %)))
assuming that clj-suitable
changed its defsource to be
(defsource ::cljs-source
:language :cljs
:candidates #'candidates
:doc #'doc)
alternatives
Maybe there are others, but the only one I can think of is:
instead of using an allow-list in cider-nrepl
have it set the :enabled
flag of sources it wants to consider
(swap! (deref #'cider.nrepl.inlined.deps.compliment.v0v3v14.compliment.sources/sources)
(fn [old-sources]
(map (fn [[k v]]
[k (if (#{:source-a :source-b} k)
(assoc v :enabled false)
v)])
old-sources)))
@philomates Hello Phillip! Sorry I only got to this now. Are you still interested in merging this? Can we iterate over the PR and make it mergeable?
hey @alexander-yakushev, I kinda forgot about the context around this issue / am no longer using compliment/in need of the change. If it looks like something useful in general feel free to take it over and get it merged, otherwise I guess it could be closed