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

Fix elin.function.lookup to fallback when info does not respond namespace and var name #8

Merged
merged 6 commits into from
Nov 16, 2024
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
15 changes: 14 additions & 1 deletion .clj-kondo/metosin/malli-types-clj/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,20 @@
:ret {:op :keys,
:req {:path :string,
:lnum :int,
:col :int}}}}}},
:col :int}}}}},
cycle-function-and-test {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:method :keyword}},
:component/nrepl :any,
:component/interceptor :any,
:component/host {:op :keys,
:req {:host-store :any}},
:component/session-storage :any,
:component/clj-kondo :any}}],
:ret {:op :keys,
:req {:path :string,
:lnum :int,
:col :int}}}}}},
elin.function.nrepl.cider {info!! {:arities {3 {:args [:any :string :string],
:ret :any}}},
ns-path!! {:arities {2 {:args [:any :string],
Expand Down
2 changes: 1 addition & 1 deletion dev/analysis.edn

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/elin/function/lookup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
sym-str]
(try
(let [res (e.f.n.cider/info!! nrepl ns-str sym-str)
error? (e/error? res)
error? (or (e/error? res)
(not (:ns res))
(not (:name res)))
protocol-var-str (when-not error?
(:protocol res))
proto-def (when (and (not error?)
Expand Down
2 changes: 0 additions & 2 deletions src/elin/handler/debug.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
[{:component/keys [host]}]
{:enabled? true
:fn (fn [{:keys [output_]}]
(spit "/tmp/foo.txt" (str (pr-str (force output_) "\n\n"))
:append true)
(e.p.host/append-to-info-buffer host (force output_)))})

(defn enable-debug-log
Expand Down
1 change: 1 addition & 0 deletions src/elin/handler/navigate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
{:ns ns-str :path ns-path :file-separator file-sep})]
(e.u.handler/jump-to-file-response cycled-path)))

(m/=> cycle-function-and-test [:=> [:cat e.s.handler/?Elin] e.s.handler/?JumpToFile])
(defn cycle-function-and-test
[elin]
(e/let [{:keys [template]} (e.u.handler/config elin #'cycle-function-and-test)
Expand Down
19 changes: 10 additions & 9 deletions test/elin/function/lookup_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns elin.function.lookup-test
(:require
[clojure.test :as t]
[elin.function.clj-kondo :as e.f.clj-kondo]
[elin.function.lookup :as sut]
[elin.function.nrepl.cider :as e.f.n.cider]
[elin.test-helper :as h]))
Expand All @@ -11,19 +12,19 @@
(t/testing "positive"
(t/testing "cider info"
(t/testing "regular"
(let [info-resp {:ns "foo.bar"
:name "baz"
:file "./core.clj"
:arglists-str ""
:column 1
:line 2}]
(let [info-resp (h/dummy-lookup-response)]
(with-redefs [e.f.n.cider/info!! (constantly info-resp)]
(t/is (= info-resp
(sut/lookup (h/test-elin) "foo.bar" "baz"))))))

;; TODO
(t/testing "protocol"))

(t/testing "nrepl lookup"))

(t/testing "negative"))
(t/testing "nrepl lookup"
(t/testing "info does not respond namespace and var name"
(let [info-resp {:status ["done"]}
fallback-resp (h/dummy-lookup-response)]
(with-redefs [e.f.n.cider/info!! (constantly info-resp)
e.f.clj-kondo/lookup (constantly fallback-resp)]
(t/is (= fallback-resp
(sut/lookup (h/test-elin) "foo.bar" "baz")))))))))
3 changes: 2 additions & 1 deletion test/elin/interceptor/evaluate_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

(t/deftest unwrap-comment-form-test
(let [test-code (str '(comment (+ 1 2) (+ 3 4)))
test-elin (h/test-elin)
unwrap-comment-form-test (fn [column]
(-> (h/test-elin)
(-> test-elin
(assoc :code test-code
:options {:line 1 :column 1 :cursor-line 1 :cursor-column column})
(unwrap-comment-form-enter)
Expand Down
15 changes: 15 additions & 0 deletions test/elin/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@
(host-get-namespace-sexpr!-config {} code))
([config code]
(assoc-in config [:host :get-namespace-sexpr!] {:code code :lnum 0 :col 0})))

(defn rand-str
[n]
(let [coll (range 97 123)]
(apply str (repeatedly n #(char (rand-nth coll))))))

(defn dummy-lookup-response
[& [m]]
(merge {:ns (str (rand-str 5) "." (rand-str 5))
:name (rand-str 10)
:file (str "./" (rand-str 10) ".clj")
:arglists-str ""
:column (rand-int 10)
:line (rand-int 10)}
m))