better multisym search, and hover tests to prove it

The search code is getting messy again. I may have to refactor it at
some point.
This commit is contained in:
XeroOl 2024-02-10 01:07:43 -06:00
parent a3dcd92e85
commit 3a3b5d38d6
2 changed files with 40 additions and 4 deletions

View File

@ -55,8 +55,24 @@ As of now, there's no caching, but that could be a way to improve performance.
(let [multival (or ?multival 1)]
(if
;; we're looking at a (values), just solve it now
(and (list? ast) (sym? (. ast 1) :values))
(search-ast self file (. ast (+ 1 multival)) stack opts)
(list? ast)
(let [call (. ast 1)]
(if
(sym? call :do)
(search-multival self file (. ast (length ast)) stack multival opts)
(sym? call :values)
;; (values x y z)
;; len 3
;; multival 2
(let [len (- (length ast) 1)]
(if (< multival len)
(search-multival self file (. ast (+ 1 multival)) stack nil opts)
(search-multival self file (. ast (+ len 1)) stack (+ multival (- len) 1) opts)))
;; we're looking for value number 1 anyway
(= 1 multival)
(search-ast self file ast stack opts) ;; this goes to search-list but indirectly
(values nil file))) ;; GIVING UP !!
;; we're looking for value number 1 anyway
(= 1 multival)
@ -64,9 +80,9 @@ As of now, there's no caching, but that could be a way to improve performance.
;; other cases
(sym? ast) (values nil file) ;; BASE CASE !!
(list? ast) (values nil file) ;; GIVING UP !!
;; (varg? ast) something
(= :table (type ast)) (values nil file)))) ;; BASE CASE !!
(= :table (type ast)) (values nil file) ;; BASE CASE !!
(values nil file)))) ;; supposed to be unreachable !!
(λ search-assignment [self file assignment stack opts]
(let [{:target {:binding _

View File

@ -61,4 +61,24 @@
[hover-b] (client:hover :foo.fnl 0 10)]
(is (hover-a.result.contents.value:find "```fnl\n1\n```"))
(is (hover-b.result.contents.value:find "```fnl\n2\n```"))
nil))
(it "hovers over a multival destructure over (do (values))"
(let [client (doto (create-client)
(: :open-file! :foo.fnl "(local (a b) (do (values 1 2)))"))
[hover-a] (client:hover :foo.fnl 0 8)
[hover-b] (client:hover :foo.fnl 0 10)]
(is (hover-a.result.contents.value:find "```fnl\n1\n```"))
(is (hover-b.result.contents.value:find "```fnl\n2\n```"))
nil))
(it "hovers over a multival destructure over a mean test (do (values))"
(let [client (doto (create-client)
(: :open-file! :foo.fnl "(let [(x y z a) (do (do (values 1 (do (values (values 2 4) (do 3))))))]\n (print x y z a))"))
[hover-x] (client:hover :foo.fnl 1 9)
[hover-y] (client:hover :foo.fnl 1 11)
[hover-z] (client:hover :foo.fnl 1 13)]
(is (hover-x.result.contents.value:find "```fnl\n1\n```"))
(is (hover-y.result.contents.value:find "```fnl\n2\n```"))
(is (hover-z.result.contents.value:find "```fnl\n3\n```"))
nil)))