From 07e8239216197f301008b846caae8a306109747e Mon Sep 17 00:00:00 2001 From: XeroOl Date: Tue, 9 Jul 2024 20:37:11 -0500 Subject: [PATCH] goto module definition tested --- src/fennel-ls/compiler.fnl | 1 - test/goto-definition.fnl | 44 ++++++++++++++++++++++++-------------- test/init.fnl | 34 ++++++++++++++++------------- test/utils/client.fnl | 6 +----- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index b7f2222..270a386 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -56,7 +56,6 @@ identifiers are declared / referenced in which places." position (utils.pos->position file.text line byte server.position-encoding)] {:start position :end position})) - (λ compile [{:configuration {: macro-path} :root-uri ?root-uri &as server} file] "Compile the file, and record all the useful information from the compiler into the file object" ;; The useful information being recorded: diff --git a/test/goto-definition.fnl b/test/goto-definition.fnl index b623568..d6c1ae9 100644 --- a/test/goto-definition.fnl +++ b/test/goto-definition.fnl @@ -14,7 +14,7 @@ ;; "|" is the cursor ;; "==" is the definition that should be found -(fn test-basics [] +(fn test-local [] (check "(fn ==x== []) x|") (check "(local ==x== 10) @@ -77,7 +77,7 @@ (check "==(fn foo| [] nil)==") nil) -(fn test-indirection [] +(fn test-fields [] (check "(fn ==target== [] nil) (local obstacle {: target}) (obstacle.tar|get)") @@ -131,6 +131,19 @@ (local (a b) (values {:x y : y} {: x : y})) (print b.x| a)") + (check "(local a {:b {:c =={:d #\"hi\"}==}}) + (a.b.|c.d)") + + (check "(local a {:b {:c =={:d #\"hi\"}==}}) + (a.b.c|.d)") + + ;; finds fn declarations + (check "(local M {}) + (fn ==M.my-function== [] nil) + (M.my-function|)") + nil) + +(fn test-thru-require [] (check {:foo.fnl "(fn ==target== [] nil) @@ -175,23 +188,22 @@ ; :main.fnl "(local {: target} (require :f|oo)) ; (target)"})) - (check "(local a {:b {:c =={:d #\"hi\"}==}}) - (a.b.|c.d)") - - (check "(local a {:b {:c =={:d #\"hi\"}==}}) - (a.b.c|.d)") - - - nil) +; (fn test-macro [] +; (check "(macro ==my-macro== [] `nil) +; (my-mac|ro)") +; (check {:m.fnl ";; fennel-ls: macro-file +; (fn ==my-macro== [] `nil) +; {: my-macro}" +; :main.fnl "(import-macros m :m) +; (m.my-macro|)"})) (fn test-no-crash [] - (check "(macro cool [a b] `(let [,b 10] ,a))\n(cool |x ==x==)") (check "(macro cool [a b] `(let [,b 10] ,a))\n(cool x x|)") - - (check "|#$...")) + (check "|#$...") + nil) ; ;; (it "can go to a destructured function argument") ; ;; (it "can go through more than one file") @@ -202,13 +214,13 @@ ; ;; (it "can follow import-macros (namespaced)") ; ;; (it "can go to the definition in a lua file") ; ;; (it "finds (set a.b) definitions") -; (it "finds (fn a.b [] ...) declarations" ; ;; (it "finds (tset a :b) definitions") ; ;; (it "finds (setmetatable a {:__index {:b def}) definitions") ; ;; (it "finds definitions into a function (fn foo [] (local x 10) {: x}) (let [result (foo)] (print result.x)) finds result.x") ; ;; (it "finds definitions through a function (fn foo [{: y}] {:x y}) (let [result (foo {:y {}})] (print result.x)) finds result.x") ; ;; (it "finds through setmetatable with an :__index function") -{: test-basics - : test-indirection +{: test-local + : test-fields + : test-thru-require : test-no-crash} diff --git a/test/init.fnl b/test/init.fnl index a1a547e..45a55bf 100644 --- a/test/init.fnl +++ b/test/init.fnl @@ -1,17 +1,21 @@ (local faith (require :faith)) +(local fennel (require :fennel)) -(faith.run - [:test.json-rpc - :test.string-processing - :test.capabilities - :test.settings - :test.diagnostic - :test.goto-definition - :test.hover - :test.completion - :test.references - :test.lint - :test.code-action - :test.rename - :test.misc - :test.check]) +(case (os.getenv "FAITH_TEST") + target (let [(module function) (target:match "([^ ]+) ([^ ]+)")] + (xpcall (. (require module) function) #(print ($:tostring target)))) + _ (faith.run + [:test.json-rpc + :test.string-processing + :test.capabilities + :test.settings + :test.diagnostic + :test.goto-definition + :test.hover + :test.completion + :test.references + :test.lint + :test.code-action + :test.rename + :test.misc + :test.check])) diff --git a/test/utils/client.fnl b/test/utils/client.fnl index 68fc638..2265854 100644 --- a/test/utils/client.fnl +++ b/test/utils/client.fnl @@ -1,11 +1,7 @@ (local dispatch (require :fennel-ls.dispatch)) (local message (require :fennel-ls.message)) -(local ROOT-PATH - (-> (io.popen "pwd") - (: :read :*a) - (: :sub 1 -2) ;; take off newline - (.. "/test/test-project"))) +(local ROOT-PATH "/path/to/test/project") (local ROOT-URI (.. "file://" ROOT-PATH))