From 3a3b5d38d6ad92d7488e8943189116edd174500b Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sat, 10 Feb 2024 01:07:43 -0600 Subject: [PATCH] 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. --- src/fennel-ls/language.fnl | 24 ++++++++++++++++++++---- test/hover-test.fnl | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/language.fnl index de660a8..f5218af 100644 --- a/src/fennel-ls/language.fnl +++ b/src/fennel-ls/language.fnl @@ -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 _ diff --git a/test/hover-test.fnl b/test/hover-test.fnl index a8146ff..0a59643 100644 --- a/test/hover-test.fnl +++ b/test/hover-test.fnl @@ -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)))