Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next release #18

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/analysis.edn

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@
elin-alias-run-test-focused-current-testing {:handler elin.handler.test/run-test-under-cursor
:config {:interceptor {:includes [elin.interceptor.test/focus-current-testing]}}}
elin-alias-overview-current-list {:handler elin.handler.evaluate/evaluate-current-list
:config {:interceptor {:includes [elin.interceptor.handler/overview]}}}
:config {:interceptor {:includes [elin.interceptor.handler/overview]
:excludes [elin.interceptor.evaluate/output-eval-result-to-cmdline
elin.interceptor.evaluate/set-eval-result-to-virtual-text
elin.interceptor.evaluate/yank-eval-result]}}}
elin-alias-overview-current-top-list {:handler elin.handler.evaluate/evaluate-current-top-list
:config {:interceptor {:includes [elin.interceptor.handler/overview]}}}}
:config {:interceptor {:includes [elin.interceptor.handler/overview]
:excludes [elin.interceptor.evaluate/output-eval-result-to-cmdline
elin.interceptor.evaluate/set-eval-result-to-virtual-text
elin.interceptor.evaluate/yank-eval-result]}}}}

:initialize {:export {"g:elin_http_server_port" #ref [:http-server :port]}}}

Expand Down
4 changes: 2 additions & 2 deletions src/elin/component/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
(edn/read-string))
this-config (cond-> handler-config
message-config
(e.config/configure-handler message-config))
(e.config/configure message-config))
interceptor' (when this-config
(e.p.config/configure interceptor this-config))]
(cond-> context
this-config
interceptor'
(assoc :component/interceptor interceptor'
:component/nrepl (assoc nrepl :interceptor interceptor')))))

Expand Down
40 changes: 32 additions & 8 deletions src/elin/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
(:import
(java.net ServerSocket)))

(declare configure)

(defmethod aero/reader 'empty-port
[_opts _tag _value]
(with-open [sock (ServerSocket. 0)]
Expand Down Expand Up @@ -74,15 +76,27 @@

(defn- configure-handler*
[base-handler-config target-handler-config]
(let [{:keys [includes excludes]} target-handler-config
(let [{:keys [includes excludes config-map]} target-handler-config
exclude-set (set/union (set (or excludes []))
(set (or includes [])))]
(set (or includes [])))
has-config-map? (contains? base-handler-config :config-map)]
(-> base-handler-config
(merge-configs (assoc target-handler-config
:includes []
:excludes []))
(update :includes #(-> (remove exclude-set %)
(concat includes))))))
(concat includes)))
(cond->
has-config-map?
(update :config-map (fn [base-config-map]
(reduce-kv
(fn [accm handler-key base-handler-config-map]
(assoc accm handler-key
(if-let [target-handler-config-map (get config-map handler-key)]
(configure base-handler-config-map target-handler-config-map)
base-handler-config-map)))
{}
base-config-map)))))))

(defn- configure-interceptor*
[base-interceptor-config target-interceptor-config]
Expand All @@ -94,7 +108,11 @@
:includes []
:excludes []))
(update :includes #(-> (remove exclude-set %)
(concat includes))))))
(concat includes)
(distinct)))
;; Retain the :excludes settings to be able to exclude global interceptors
(update :excludes #(-> (concat % excludes)
(distinct))))))

#_(m/=> expand-uses [:=> [:cat [:* [:cat symbol? map?]]]
[:map [:includes [:sequential symbol?]]
Expand Down Expand Up @@ -140,11 +158,17 @@
interceptor)))

(defn configure
[base-config target-config]
(-> base-config
(merge-configs (dissoc target-config :handler :interceptor))
[base-config
target-config]
(let [{base-handler :handler base-interceptor :interceptor} base-config
{target-handler :handler target-interceptor :interceptor} target-config]
(cond-> (merge-configs base-config
(dissoc target-config :handler :interceptor))
(or base-handler target-handler)
(update :handler #(configure-handler % (:handler target-config)))
(update :interceptor #(configure-interceptor % (:interceptor target-config)))))

(or base-interceptor target-interceptor)
(update :interceptor #(configure-interceptor % (:interceptor target-config))))))

(defn- load-default-config
[]
Expand Down
19 changes: 16 additions & 3 deletions test/elin/component/handler_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,22 @@
(t/is (= 13 (call-test-handler' #'test-configured-interceptor-handler))))

(t/testing "Requested interceptor"
(let [options {:config (pr-str {:interceptor {:includes [(symbol #'test-requst-interceptor)]}})}]
(t/is (= 5 (call-test-handler' #'test-global-interceptor-handler [] options)))
(t/is (= 17 (call-test-handler' #'test-configured-interceptor-handler [] options))))))
(t/testing "includes"
(let [options {:config (pr-str {:interceptor {:includes [(symbol #'test-requst-interceptor)]}})}]
(t/is (= 5 (call-test-handler' #'test-global-interceptor-handler [] options)))
(t/is (= 17 (call-test-handler' #'test-configured-interceptor-handler [] options)))))

(t/testing "excludes"
(t/is (= 0 (->> {:config (pr-str {:interceptor {:excludes [(symbol #'test-global-interceptor)]}})}
(call-test-handler' #'test-global-interceptor-handler []))))

(t/is (= 1 (->> {:config (pr-str {:interceptor {:excludes [(symbol #'test-configured-interceptor)]}})}
(call-test-handler' #'test-global-interceptor-handler []))))

(t/is (= 12 (->> {:config (pr-str {:interceptor {:excludes [(symbol #'test-global-interceptor)]}})}
(call-test-handler' #'test-configured-interceptor-handler []))))
(t/is (= 11 (->> {:config (pr-str {:interceptor {:excludes [(symbol #'test-configured-interceptor)]}})}
(call-test-handler' #'test-configured-interceptor-handler [])))))))

(finally
(component/stop-system sys))))))
109 changes: 53 additions & 56 deletions test/elin/config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -86,152 +86,149 @@
:else (throw (ex-info "interceptor should be only once" {})))))

(t/deftest configure-test
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {}
(sut/configure {} {})))

(t/testing "handler"
(t/testing "includes"
(t/is (= {:handler {:includes ['foo] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes []}}
(sut/configure {}
{:handler {:includes ['foo]}})))

(t/is (= {:handler {:includes ['foo] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes []}}
(sut/configure {:handler {:includes ['foo]}}
{:handler {:includes ['foo]}})))

(t/is (= {:handler {:includes ['foo 'bar] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo 'bar] :excludes []}}
(sut/configure {:handler {:includes ['foo]}}
{:handler {:includes ['bar]}}))))

(t/testing "exclude"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/testing "excludes"
(t/is (= {:handler {:includes [] :excludes []}}
(sut/configure {:handler {:includes ['foo]}}
{:handler {:excludes ['foo]}}))))

(t/testing "includes and excludes"
(t/is (= {:handler {:includes ['foo] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes []}}
(sut/configure {}
{:handler {:includes ['foo] :excludes ['foo]}}))))

(t/testing "config-map"
(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 1}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {}
{:handler {:config-map {'foo {:a 1}}}})))

(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 1}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {:handler {:config-map {'foo {:a 1}}}}
{:handler {:config-map {'foo {:a 1}}}})))

(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 10}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 10}}}}
(sut/configure {:handler {:config-map {'foo {:a 1}}}}
{:handler {:config-map {'foo {:a 10}}}})))

(t/is (= {:handler {:includes [] :excludes [] :config-map {'foo {:a 1}
'bar {:b 2}}}
:interceptor {:includes [] :excludes []}}
'bar {:b 2}}}}
(sut/configure {:handler {:config-map {'foo {:a 1}}}}
{:handler {:config-map {'bar {:b 2}}}}))))
{:handler {:config-map {'bar {:b 2}}}})))

(t/testing "interceptor config-map"
(t/testing "includes"
(t/is (= {:handler {:includes []
:excludes []
:config-map {'foo {:interceptor {:includes '[bar baz]
:excludes []}}}}}
(sut/configure {:handler {:config-map {'foo {:interceptor {:includes ['bar]}}}}}
{:handler {:config-map {'foo {:interceptor {:includes ['baz]}}}}}))))

(t/testing "excludes"
(t/is (= {:handler {:includes []
:excludes []
:config-map {'foo {:interceptor {:includes '[bar]
:excludes '[baz]}}}}}
(sut/configure {:handler {:config-map {'foo {:interceptor {:includes ['bar]}}}}}
{:handler {:config-map {'foo {:interceptor {:excludes ['baz]}}}}})))

(t/is (= {:handler {:includes []
:excludes []
:config-map {'foo {:interceptor {:includes []
:excludes '[bar]}}}}}
(sut/configure {:handler {:config-map {'foo {:interceptor {:includes ['bar]}}}}}
{:handler {:config-map {'foo {:interceptor {:excludes ['bar]}}}}}))))))

(t/testing "uses"
(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {}
{:handler {:uses ['foo {:a 1}]}})))

(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {:handler {:includes ['foo] :config-map {'foo {:a 1}}}}
{:handler {:uses ['foo {:a 1}]}})))

(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 10}}}
:interceptor {:includes [] :excludes []}}
(t/is (= {:handler {:includes ['foo] :excludes [] :config-map {'foo {:a 10}}}}
(sut/configure {:handler {:includes ['foo] :config-map {'foo {:a 1}}}}
{:handler {:uses ['foo {:a 10}]}})))

(t/is (= {:handler {:includes ['foo 'bar] :excludes [] :config-map {'foo {:a 1}
'bar {:b 2}}}
:interceptor {:includes [] :excludes []}}
'bar {:b 2}}}}
(sut/configure {:handler {:includes ['foo] :config-map {'foo {:a 1}}}}
{:handler {:uses ['bar {:b 2}]}})))))

(t/testing "interceptor"
(t/testing "includes"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes []}}
(t/is (= {:interceptor {:includes ['foo] :excludes []}}
(sut/configure {}
{:interceptor {:includes ['foo]}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes []}}
(t/is (= {:interceptor {:includes ['foo] :excludes []}}
(sut/configure {:interceptor {:includes ['foo]}}
{:interceptor {:includes ['foo]}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo 'bar] :excludes []}}
(t/is (= {:interceptor {:includes ['foo 'bar] :excludes []}}
(sut/configure {:interceptor {:includes ['foo]}}
{:interceptor {:includes ['bar]}}))))

(t/testing "excludes"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes []}}
(t/is (= {:interceptor {:includes [] :excludes ['foo]}}
(sut/configure {:interceptor {:includes ['foo]}}
{:interceptor {:excludes ['foo]}}))))

(t/testing "includes and excludes"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes []}}
(t/is (= {:interceptor {:includes ['foo] :excludes ['foo]}}
(sut/configure {}
{:interceptor {:includes ['foo] :excludes ['foo]}}))))

(t/testing "config-map"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(t/is (= {:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {}
{:interceptor {:config-map {'foo {:a 1}}}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(t/is (= {:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {:interceptor {:config-map {'foo {:a 1}}}}
{:interceptor {:config-map {'foo {:a 1}}}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes [] :config-map {'foo {:a 10}}}}
(t/is (= {:interceptor {:includes [] :excludes [] :config-map {'foo {:a 10}}}}
(sut/configure {:interceptor {:config-map {'foo {:a 1}}}}
{:interceptor {:config-map {'foo {:a 10}}}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}
(t/is (= {:interceptor {:includes [] :excludes [] :config-map {'foo {:a 1}
'bar {:b 2}}}}
(sut/configure {:interceptor {:config-map {'foo {:a 1}}}}
{:interceptor {:config-map {'bar {:b 2}}}}))))

(t/testing "uses"
(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(t/is (= {:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {}
{:interceptor {:uses ['foo {:a 1}]}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(t/is (= {:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 1}}}}
(sut/configure {:interceptor {:includes ['foo] :config-map {'foo {:a 1}}}}
{:interceptor {:uses ['foo {:a 1}]}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 10}}}}
(t/is (= {:interceptor {:includes ['foo] :excludes [] :config-map {'foo {:a 10}}}}
(sut/configure {:interceptor {:includes ['foo] :config-map {'foo {:a 1}}}}
{:interceptor {:uses ['foo {:a 10}]}})))

(t/is (= {:handler {:includes [] :excludes []}
:interceptor {:includes ['foo 'bar] :excludes [] :config-map {'foo {:a 1}
(t/is (= {:interceptor {:includes ['foo 'bar] :excludes [] :config-map {'foo {:a 1}
'bar {:b 2}}}}
(sut/configure {:interceptor {:includes ['foo] :config-map {'foo {:a 1}}}}
{:interceptor {:uses ['bar {:b 2}]}}))))))
Expand Down
Loading