diff --git a/src/fennel-ls.fnl b/src/fennel-ls.fnl index e85fd59..322e1b5 100644 --- a/src/fennel-ls.fnl +++ b/src/fennel-ls.fnl @@ -8,7 +8,7 @@ (local state []) (while true (let [msg (json-rpc.read in)] - (log msg) + ;; (log msg) (dispatch.handle state send msg)))) (λ main [] diff --git a/test/document-test.fnl b/test/document-test.fnl index 2585b97..9c393c9 100644 --- a/test/document-test.fnl +++ b/test/document-test.fnl @@ -18,10 +18,8 @@ (describe "create-from-disk" (it "opens documents from disk" (local uri (.. ROOT-URI "/test/init.fnl")) - (local test-fnl-document (document.create-from-disk uri)) - (assert.equal (. test-fnl-document.lines 1) - "((require :busted.runner))")) + (assert (stringx.startswith test-fnl-document.text "((require :busted.runner))"))) (it "crashes on bad file" (assert.errors #(document.create-from-disk "fill://my/path/here")) @@ -32,23 +30,23 @@ (local uri (.. ROOT-URI "/test_document")) (assert-matches (document.create-from-contents uri "line 1\nline 2\nline 3") - {:lines ["line 1" "line 2" "line 3"]}))) + {:text "line 1\nline 2\nline 3"}))) (describe "sub" (it "updates the start of a line" - (local my-document (document.create FILE-URI ["replace beginning"])) - (document.sub my-document 0 0 0 7 "the") - (assert-matches my-document {:lines ["the beginning"]})) + (local my-document (document.create FILE-URI "replace beginning")) + (document.replace my-document 0 0 0 7 "the") + (assert-matches my-document {:text "the beginning"})) (it "updates the end of a line" - (local my-document (document.create FILE-URI ["replace end"])) - (document.sub my-document 0 7 0 11 "ment") - (assert-matches my-document {:lines ["replacement"]})) + (local my-document (document.create FILE-URI "first line\nsecond line\nreplace end")) + (document.replace my-document 2 7 2 11 "ment") + (assert-matches my-document {:text "first line\nsecond line\nreplacement"})) (it "replaces a line" - (local my-document (document.create FILE-URI ["replace all"])) - (document.sub my-document 0 0 0 11 "new string") - (assert-matches my-document {:lines ["new string"]}))) + (local my-document (document.create FILE-URI "replace all")) + (document.replace my-document 0 0 0 11 "new string") + (assert-matches my-document {:text "new string"}))) ;; fixme: ;; test for errors on out of bounds @@ -57,35 +55,25 @@ ;; (it "can handle unicode" ;; (local uri (.. ROOT-URI "test_document")) - ;; (local my-document (document.create uri [""])) - ;; (document.sub my-document 0 0 0 0 "どれみふぁそらてぃど") - ;; (document.sub my-document 0 1 0 3 "😀") - ;; (document.sub my-document 0 11 0 11 "end") - ;; (assert-matches my-document {:lines ["ど😀ふぁそらてぃどend"]}))) + ;; (local my-document (document.create uri "")) + ;; (document.replace my-document 0 0 0 0 "どれみふぁそらてぃど") + ;; (document.replace my-document 0 1 0 3 "😀") + ;; (document.replace my-document 0 11 0 11 "end") + ;; (assert-matches my-document {:text "ど😀ふぁそらてぃどend"}))) (describe "apply-changes" (it "can handle substituting things" - (local my-document (document.create FILE-URI ["replace beginning"])) + (local my-document (document.create FILE-URI "replace beginning")) (document.apply-changes my-document [{:range {:start {:line 0 :character 0} :end {:line 0 :character 7}} :text "the"}]) - (assert-matches my-document {:lines ["the beginning"]})) + (assert-matches my-document {:text "the beginning"})) (it "can handle replacing everything" - (local my-document (document.create FILE-URI ["this is the" "old file"])) + (local my-document (document.create FILE-URI "this is the\nold file")) (document.apply-changes my-document [{:text "And this is the\nnew file"}]) - (assert-matches my-document {:lines ["And this is the" "new file"]}))) - - (describe "lines" - (it "splits lines" - (assert.same (document.lines "hello world\nnewlines are fun\rgaming\r\nworld -double double\r\n\ndouble trouble\n\r\nfunny\r\rand\n\nfinal") - ["hello world" "newlines are fun" - "gaming" "world" "double double" - "" "double trouble" - "" "funny" "" "and" - "" "final"])))) + (assert-matches my-document {:text "And this is the\nnew file"})))) diff --git a/test/lsp-test.fnl b/test/lsp-test.fnl index 722c009..dcf8fbd 100644 --- a/test/lsp-test.fnl +++ b/test/lsp-test.fnl @@ -7,9 +7,10 @@ (local ROOT-PATH (-> (io.popen "pwd") (: :read :*a) - (stringx.strip))) + (stringx.strip) + (.. "/test/test-project"))) (local ROOT-URI - (.. "document://" ROOT-PATH)) + (.. "file://" ROOT-PATH)) (local server-initialize-message {:id 1 @@ -35,16 +36,41 @@ :result {:capabilities {} :serverInfo {:name "fennel-ls" : version}}}])) - (it "can jump to definition" - (local state []) - (dispatch.handle* state server-initialize-message) - (assert-matches - (dispatch.handle* state - {:id 2 - :jsonrpc "2.0" - :method "textDocument/definition" - :params {:position {:character 5 :line 0} - :textDocument {:uri (.. ROOT-URI "/test.fnl")}}}) - [{:id 2 - :jsonrpc "2.0" - :result {: uri : range}}]))) ;; FIXME: test whether the location is correct + (describe "jump to definition" + (it "handles (local _ (require XXX)" + (local state []) + (dispatch.handle* state server-initialize-message) + (assert-matches + (dispatch.handle* state + {:id 2 + :jsonrpc "2.0" + :method "textDocument/definition" + :params {:position {:character 11 :line 0} + :textDocument {:uri (.. ROOT-URI "/example.fnl")}}}) + (where [{:id 2 + :jsonrpc "2.0" + :result {: uri :range {:start {:line 0 :character 0} + :end {:line 0 :character 0}}}}] + (stringx.endswith uri "foo.fnl")))) + + (it "handles (require XXX))" + (local state []) + (dispatch.handle* state server-initialize-message) + (assert-matches + (dispatch.handle* state + {:id 2 + :jsonrpc "2.0" + :method "textDocument/definition" + :params {:position {:character 5 :line 1} + :textDocument {:uri (.. ROOT-URI "/example.fnl")}}}) + (where [{:id 2 + :jsonrpc "2.0" + :result {: uri :range {:start {:line 0 :character 0} + :end {:line 0 :character 0}}}}] + (stringx.endswith uri "bar.fnl")))))) + + ;; (it "can go to a fn") + ;; (it "can go to a local") + ;; (it "can go to a table and its field") + ;; (it "can go to a destructured local") + ;; (it "can go to a table field in another file"))) diff --git a/test/test-project/bar.fnl b/test/test-project/bar.fnl new file mode 100644 index 0000000..607602c --- /dev/null +++ b/test/test-project/bar.fnl @@ -0,0 +1 @@ +nil diff --git a/test/test-project/example.fnl b/test/test-project/example.fnl new file mode 100644 index 0000000..7a55f3b --- /dev/null +++ b/test/test-project/example.fnl @@ -0,0 +1,8 @@ +(local foo (require :foo)) +(require :bar) + +(fn bar [a b] + (print a b) + (foo.my-export)) + +{: bar} diff --git a/test/test-project/foo.fnl b/test/test-project/foo.fnl new file mode 100644 index 0000000..81d2e5c --- /dev/null +++ b/test/test-project/foo.fnl @@ -0,0 +1,5 @@ +(local constant 5) + +(fn my-export []) + +{: my-export : constant}