diff --git a/src/scicloj/kindly_advice/v1/api.cljc b/src/scicloj/kindly_advice/v1/api.cljc index f32c0d0..c882648 100644 --- a/src/scicloj/kindly_advice/v1/api.cljc +++ b/src/scicloj/kindly_advice/v1/api.cljc @@ -1,10 +1,17 @@ (ns scicloj.kindly-advice.v1.api (:require [scicloj.kindly-advice.v1.advisors :as advisors] - [scicloj.kindly-advice.v1.completion :as completion])) + [scicloj.kindly-advice.v1.completion :as completion] + [scicloj.kindly.v4.api :as kindly])) (def *advisors (atom advisors/default-advisors)) +(defn f [{:keys [form]}] + (if (and (sequential? form) + (-> form first (= 'ns))) + (set! kindly/*options* (completion/deep-merge kindly/*options*) + (completion/meta-options form)))) + (defn advise "Adds advice to a context such as `{:form [:div]}`. Advice recommends a kind `{:form [:div], :value [:div], :kind :kindly/hiccup}`. @@ -14,6 +21,11 @@ (advise context @*advisors)) ([context advisors] (-> context + + ;; if ns form, mutate *options*? + ;; replace or merge? + f + completion/complete (#(reduce advisors/update-context % diff --git a/src/scicloj/kindly_advice/v1/completion.cljc b/src/scicloj/kindly_advice/v1/completion.cljc index b9146b7..442118c 100644 --- a/src/scicloj/kindly_advice/v1/completion.cljc +++ b/src/scicloj/kindly_advice/v1/completion.cljc @@ -55,7 +55,7 @@ (or (when-let [m (meta x)] (:kindly/options m)) - (when (var? x) (meta-kind @x)))) + (when (var? x) (meta-options @x)))) (defn deep-merge "Recursively merges maps together. If all the maps supplied have nested maps @@ -81,11 +81,16 @@ (defn complete-options [{:keys [form value] :as context}] - (let [meta-options (or (meta-options form) - (meta-options value))] + (let [options (or (meta-options form) + (meta-options value))] + ;; Kindly options found on ns cause *options* to be mutated + (when (and (sequential? form) + (-> form first (= 'ns))) + (set! kindly/*options* (deep-merge kindly/*options* options (meta-options *ns*)))) + ;; Toolmakers should ensure *options* is reset when reading namespaces by (binding [kindly/*options* kindly/*options*] ...) (update context :kindly/options (fn [options] - (deep-merge options kindly/*options* meta-options))))) + (deep-merge options kindly/*options* options))))) (defn complete [context] (-> context