Skip to content

Commit 3463c1e

Browse files
authored
Merge pull request #29 from liquidz/dev
Next release
2 parents d77aa19 + bcb38d9 commit 3463c1e

File tree

8 files changed

+143
-23
lines changed

8 files changed

+143
-23
lines changed

.clj-kondo/metosin/malli-types-clj/config.edn

+6-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@
226226
:component/clj-kondo :any}}
227227
:sequential],
228228
:ret :any}}}},
229-
elin.function.sexpr {get-top-list {:arities {3 {:args [{:op :keys,
229+
elin.function.sexpr {validate-code-and-position {:arities {1 {:args [{:op :keys,
230+
:req {:code :string,
231+
:lnum :int,
232+
:col :int}}],
233+
:ret :any}}},
234+
get-top-list {:arities {3 {:args [{:op :keys,
230235
:req {:message {:op :keys,
231236
:req {:method :keyword}},
232237
:component/nrepl :any,

CHANGELOG.adoc

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
All notable changes to this project will be documented in this file. This change log follows the conventions of http://keepachangelog.com/[keepachangelog.com].
22

3+
== [2025.3.2-alpha] - 2025-03-07
4+
5+
=== Added
6+
7+
- Add elin.interceptor.test/register-started-at interceptor
8+
9+
=== Fixed
10+
11+
- Update elin.interceptor.test/output-test-result-to-cmdline to show elapsed time
12+
- Update elin.function.lookup/lookup to support ordered lookup
13+
- Update elin.handler.lookup/lookup to use lookup-config
14+
- Update elin.handler.lookup/show-source to use lookup-config
15+
- Elin.handler.lookup/show-clojuredocs to use lookup-config
16+
- Update elin.handler.navigate/jump-to-definition to use lookup-config
17+
- Update elin.handler.navigate/cycle-function-and-test to use lookup-config
18+
319
== [2025.3.1-alpha] - 2025-03-01
420

521
=== Fixed

autoload/elin/internal/sexpr.vim

+10-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ endfunction
4545
if has('nvim') && exists('*nvim_get_runtime_file') && len(nvim_get_runtime_file('parser', v:true)) > 0
4646

4747
function! s:get_top_list(lnum, col) abort
48-
return luaeval('require("elin.sexpr").get_top_list(_A[1], _A[2])', [a:lnum - 1, a:col - 1])
48+
try
49+
return luaeval('require("elin.sexpr").get_top_list(_A[1], _A[2])', [a:lnum - 1, a:col - 1])
50+
catch
51+
return {'code': '', 'lnum': 0, 'col': 0}
52+
endtry
4953
endfunction
5054

5155
function! s:get_list(lnum, col) abort
52-
return luaeval('require("elin.sexpr").get_list(_A[1], _A[2])', [a:lnum - 1, a:col - 1])
56+
try
57+
return luaeval('require("elin.sexpr").get_list(_A[1], _A[2])', [a:lnum - 1, a:col - 1])
58+
catch
59+
return {'code': '', 'lnum': 0, 'col': 0}
60+
endtry
5361
endfunction
5462

5563
else

dev/analysis.edn

+1-1
Large diffs are not rendered by default.

doc/pages/lookup/index.adoc

+38
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,41 @@ The result format is defined by configuration file as a https://mustache.github.
3737
| * https://github.com/liquidz/elin/blob/main/resources/template/clojuredocs.mustache[ClojureDocs]
3838

3939
|===
40+
41+
=== Lookup order
42+
43+
In Elin, there are three types of var lookups: `nrepl`, `clj-kondo`, and `local`.
44+
45+
[%autowidth,cols="a,a"]
46+
|===
47+
| Lookup type | Description
48+
49+
| `nrepl`
50+
| Looking up vars based on information from the nREPL server. Even if a var is not saved in a file, it can still be referenced if it has been evaluated.
51+
52+
| `clj-kondo`
53+
| Looking up vars based on clj-kondo's analysis results. If a var is not saved in a file and is not reflected in the analysis results, it cannot be referenced.
54+
55+
| `local`
56+
| Looking up local vars bound with `let`, etc., based on clj-kondo's analysis results. If a var is not saved in a file and is not reflected in the analysis results, it cannot be referenced.
57+
|===
58+
59+
Each handler has different reference targets and priorities, which can be customized in the configuration file.
60+
61+
[%autowidth,cols="a,a,a"]
62+
|===
63+
| Command | Default order | Description
64+
65+
| <<ElinLookup>>
66+
| `nrepl`, `clj-kondo`
67+
| `local` is not included in the order because it is not necessary to look up the documentation.
68+
69+
| <<ElinShowSource>>
70+
| `local`, `nrepl`, `clj-kondo`
71+
| `local` is prioritized because we'd like to see the local definition first.
72+
73+
| <<ElinShowClojureDocs>>
74+
| `nrepl`, `clj-kondo`
75+
| `local` is not included in the order because it is not necessary to look up clojuredocs.
76+
77+
|===

src/elin/function/sexpr.clj

+23-8
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,56 @@
99
[elin.util.sexpr :as e.u.sexpr]
1010
[malli.core :as m]))
1111

12+
(m/=> validate-code-and-position [:=> [:cat e.s.host/?CodeAndPosition] (e.schema/error-or e.s.host/?CodeAndPosition)])
13+
(defn- validate-code-and-position
14+
[{:as code-and-position :keys [code]}]
15+
(if (seq code)
16+
code-and-position
17+
(e/not-found)))
18+
1219
(m/=> get-top-list [:function
1320
[:-> e.s.handler/?Elin int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]
1421
[:-> e.s.handler/?Elin string? int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]])
1522
(defn get-top-list
1623
([{:component/keys [host]} lnum col]
17-
(async/<!! (e.p.host/get-top-list-sexpr! host lnum col)))
24+
(e/-> (async/<!! (e.p.host/get-top-list-sexpr! host lnum col))
25+
(validate-code-and-position)))
1826
([{:component/keys [host]} path lnum col]
19-
(async/<!! (e.p.host/get-top-list-sexpr! host path lnum col))))
27+
(e/-> (async/<!! (e.p.host/get-top-list-sexpr! host path lnum col))
28+
(validate-code-and-position))))
2029

2130
(m/=> get-list [:function
2231
[:-> e.s.handler/?Elin int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]
2332
[:-> e.s.handler/?Elin string? int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]])
2433
(defn get-list
2534
([{:component/keys [host]} lnum col]
26-
(async/<!! (e.p.host/get-list-sexpr! host lnum col)))
35+
(e/-> (async/<!! (e.p.host/get-list-sexpr! host lnum col))
36+
(validate-code-and-position)))
2737
([{:component/keys [host]} path lnum col]
28-
(async/<!! (e.p.host/get-list-sexpr! host path lnum col))))
38+
(e/-> (async/<!! (e.p.host/get-list-sexpr! host path lnum col))
39+
(validate-code-and-position))))
2940

3041
(m/=> get-expr [:function
3142
[:-> e.s.handler/?Elin int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]
3243
[:-> e.s.handler/?Elin string? int? int? (e.schema/error-or e.s.host/?CodeAndPosition)]])
3344
(defn get-expr
3445
([{:component/keys [host]} lnum col]
35-
(async/<!! (e.p.host/get-single-sexpr! host lnum col)))
46+
(e/-> (async/<!! (e.p.host/get-single-sexpr! host lnum col))
47+
(validate-code-and-position)))
3648
([{:component/keys [host]} path lnum col]
37-
(async/<!! (e.p.host/get-single-sexpr! host path lnum col))))
49+
(e/-> (async/<!! (e.p.host/get-single-sexpr! host path lnum col))
50+
(validate-code-and-position))))
3851

3952
(m/=> get-namespace-sexpr [:function
4053
[:=> [:cat e.s.handler/?Elin] (e.schema/error-or e.s.host/?CodeAndPosition)]
4154
[:=> [:cat e.s.handler/?Elin string?] (e.schema/error-or e.s.host/?CodeAndPosition)]])
4255
(defn get-namespace-sexpr
4356
([{:component/keys [host]}]
44-
(async/<!! (e.p.host/get-namespace-sexpr! host)))
57+
(e/-> (async/<!! (e.p.host/get-namespace-sexpr! host))
58+
(validate-code-and-position)))
4559
([{:component/keys [host]} path]
46-
(async/<!! (e.p.host/get-namespace-sexpr! host path))))
60+
(e/-> (async/<!! (e.p.host/get-namespace-sexpr! host path))
61+
(validate-code-and-position))))
4762

4863
(m/=> replace-list-sexpr [:=> [:cat e.s.handler/?Elin int? int? string?] (e.schema/error-or [:maybe string?])])
4964
(defn replace-list-sexpr

src/elin/handler/lookup.clj

+1-11
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,7 @@
3232

3333
(m/=> lookup [:=> [:cat e.s.handler/?Elin] any?])
3434
(defn lookup
35-
"Look up symbol at cursor position.
36-
37-
.Configuration
38-
[%autowidth.stretch]
39-
|===
40-
| key | type | description
41-
42-
| format | todo | todo
43-
| replace-string | todo | todo
44-
| lookup-config | todo | todo
45-
|==="
35+
"Look up symbol at cursor position."
4636
[{:as elin :component/keys [host]}]
4737
(e/let [{:as config :keys [lookup-config]} (e.u.handler/config elin #'lookup)
4838
{:keys [lnum col]} (async/<!! (e.p.host/get-cursor-position! host))

test/elin/function/sexpr_test.clj

+48
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,54 @@
1616
(async/go
1717
{:code ns-form :lnum 0 :col 0})))
1818

19+
(t/deftest get-top-list-test
20+
(let [test-elin (h/test-elin)]
21+
(t/testing "Positive"
22+
(with-redefs [e.p.host/get-top-list-sexpr! (h/async-constantly {:code "foo" :lnum 1 :col 2})]
23+
(t/is (= {:code "foo" :lnum 1 :col 2}
24+
(sut/get-top-list test-elin 0 0)))))
25+
26+
(t/testing "Negative"
27+
(t/testing "Failed to fetch"
28+
(with-redefs [e.p.host/get-top-list-sexpr! (h/async-constantly (e/fault))]
29+
(t/is (e/fault? (sut/get-top-list test-elin 0 0)))))
30+
31+
(t/testing "No code"
32+
(with-redefs [e.p.host/get-top-list-sexpr! (h/async-constantly {:code "" :lnum 0 :col 0})]
33+
(t/is (e/not-found? (sut/get-top-list test-elin 0 0))))))))
34+
35+
(t/deftest get-list-test
36+
(let [test-elin (h/test-elin)]
37+
(t/testing "Positive"
38+
(with-redefs [e.p.host/get-list-sexpr! (h/async-constantly {:code "foo" :lnum 1 :col 2})]
39+
(t/is (= {:code "foo" :lnum 1 :col 2}
40+
(sut/get-list test-elin 0 0)))))
41+
42+
(t/testing "Negative"
43+
(t/testing "Failed to fetch"
44+
(with-redefs [e.p.host/get-list-sexpr! (h/async-constantly (e/fault))]
45+
(t/is (e/fault? (sut/get-list test-elin 0 0)))))
46+
47+
(t/testing "No code"
48+
(with-redefs [e.p.host/get-list-sexpr! (h/async-constantly {:code "" :lnum 0 :col 0})]
49+
(t/is (e/not-found? (sut/get-list test-elin 0 0))))))))
50+
51+
(t/deftest get-expr-test
52+
(let [test-elin (h/test-elin)]
53+
(t/testing "Positive"
54+
(with-redefs [e.p.host/get-single-sexpr! (h/async-constantly {:code "foo" :lnum 1 :col 2})]
55+
(t/is (= {:code "foo" :lnum 1 :col 2}
56+
(sut/get-expr test-elin 0 0)))))
57+
58+
(t/testing "Negative"
59+
(t/testing "Failed to fetch"
60+
(with-redefs [e.p.host/get-single-sexpr! (h/async-constantly (e/fault))]
61+
(t/is (e/fault? (sut/get-expr test-elin 0 0)))))
62+
63+
(t/testing "No code"
64+
(with-redefs [e.p.host/get-single-sexpr! (h/async-constantly {:code "" :lnum 0 :col 0})]
65+
(t/is (e/not-found? (sut/get-expr test-elin 0 0))))))))
66+
1967
(t/deftest get-namespace-test
2068
(let [test-elin (h/test-elin)]
2169
(t/testing "no metadata"

0 commit comments

Comments
 (0)