go-to-definition for require with fixed module name
This commit is contained in:
parent
3c91ad0680
commit
db59350a1c
@ -8,7 +8,7 @@
|
|||||||
(local state [])
|
(local state [])
|
||||||
(while true
|
(while true
|
||||||
(let [msg (json-rpc.read in)]
|
(let [msg (json-rpc.read in)]
|
||||||
(log msg)
|
;; (log msg)
|
||||||
(dispatch.handle state send msg))))
|
(dispatch.handle state send msg))))
|
||||||
|
|
||||||
(λ main []
|
(λ main []
|
||||||
|
|||||||
@ -18,10 +18,8 @@
|
|||||||
(describe "create-from-disk"
|
(describe "create-from-disk"
|
||||||
(it "opens documents from disk"
|
(it "opens documents from disk"
|
||||||
(local uri (.. ROOT-URI "/test/init.fnl"))
|
(local uri (.. ROOT-URI "/test/init.fnl"))
|
||||||
|
|
||||||
(local test-fnl-document (document.create-from-disk uri))
|
(local test-fnl-document (document.create-from-disk uri))
|
||||||
(assert.equal (. test-fnl-document.lines 1)
|
(assert (stringx.startswith test-fnl-document.text "((require :busted.runner))")))
|
||||||
"((require :busted.runner))"))
|
|
||||||
|
|
||||||
(it "crashes on bad file"
|
(it "crashes on bad file"
|
||||||
(assert.errors #(document.create-from-disk "fill://my/path/here"))
|
(assert.errors #(document.create-from-disk "fill://my/path/here"))
|
||||||
@ -32,23 +30,23 @@
|
|||||||
(local uri (.. ROOT-URI "/test_document"))
|
(local uri (.. ROOT-URI "/test_document"))
|
||||||
(assert-matches
|
(assert-matches
|
||||||
(document.create-from-contents uri "line 1\nline 2\nline 3")
|
(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"
|
(describe "sub"
|
||||||
(it "updates the start of a line"
|
(it "updates the start of a line"
|
||||||
(local my-document (document.create FILE-URI ["replace beginning"]))
|
(local my-document (document.create FILE-URI "replace beginning"))
|
||||||
(document.sub my-document 0 0 0 7 "the")
|
(document.replace my-document 0 0 0 7 "the")
|
||||||
(assert-matches my-document {:lines ["the beginning"]}))
|
(assert-matches my-document {:text "the beginning"}))
|
||||||
|
|
||||||
(it "updates the end of a line"
|
(it "updates the end of a line"
|
||||||
(local my-document (document.create FILE-URI ["replace end"]))
|
(local my-document (document.create FILE-URI "first line\nsecond line\nreplace end"))
|
||||||
(document.sub my-document 0 7 0 11 "ment")
|
(document.replace my-document 2 7 2 11 "ment")
|
||||||
(assert-matches my-document {:lines ["replacement"]}))
|
(assert-matches my-document {:text "first line\nsecond line\nreplacement"}))
|
||||||
|
|
||||||
(it "replaces a line"
|
(it "replaces a line"
|
||||||
(local my-document (document.create FILE-URI ["replace all"]))
|
(local my-document (document.create FILE-URI "replace all"))
|
||||||
(document.sub my-document 0 0 0 11 "new string")
|
(document.replace my-document 0 0 0 11 "new string")
|
||||||
(assert-matches my-document {:lines ["new string"]})))
|
(assert-matches my-document {:text "new string"})))
|
||||||
|
|
||||||
;; fixme:
|
;; fixme:
|
||||||
;; test for errors on out of bounds
|
;; test for errors on out of bounds
|
||||||
@ -57,35 +55,25 @@
|
|||||||
|
|
||||||
;; (it "can handle unicode"
|
;; (it "can handle unicode"
|
||||||
;; (local uri (.. ROOT-URI "test_document"))
|
;; (local uri (.. ROOT-URI "test_document"))
|
||||||
;; (local my-document (document.create uri [""]))
|
;; (local my-document (document.create uri ""))
|
||||||
;; (document.sub my-document 0 0 0 0 "どれみふぁそらてぃど")
|
;; (document.replace my-document 0 0 0 0 "どれみふぁそらてぃど")
|
||||||
;; (document.sub my-document 0 1 0 3 "😀")
|
;; (document.replace my-document 0 1 0 3 "😀")
|
||||||
;; (document.sub my-document 0 11 0 11 "end")
|
;; (document.replace my-document 0 11 0 11 "end")
|
||||||
;; (assert-matches my-document {:lines ["ど😀ふぁそらてぃどend"]})))
|
;; (assert-matches my-document {:text "ど😀ふぁそらてぃどend"})))
|
||||||
|
|
||||||
(describe "apply-changes"
|
(describe "apply-changes"
|
||||||
(it "can handle substituting things"
|
(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
|
(document.apply-changes
|
||||||
my-document
|
my-document
|
||||||
[{:range {:start {:line 0 :character 0}
|
[{:range {:start {:line 0 :character 0}
|
||||||
:end {:line 0 :character 7}}
|
:end {:line 0 :character 7}}
|
||||||
:text "the"}])
|
:text "the"}])
|
||||||
(assert-matches my-document {:lines ["the beginning"]}))
|
(assert-matches my-document {:text "the beginning"}))
|
||||||
|
|
||||||
(it "can handle replacing everything"
|
(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
|
(document.apply-changes
|
||||||
my-document
|
my-document
|
||||||
[{:text "And this is the\nnew file"}])
|
[{:text "And this is the\nnew file"}])
|
||||||
(assert-matches my-document {:lines ["And this is the" "new file"]})))
|
(assert-matches my-document {:text "And this is the\nnew 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"]))))
|
|
||||||
|
|||||||
@ -7,9 +7,10 @@
|
|||||||
(local ROOT-PATH
|
(local ROOT-PATH
|
||||||
(-> (io.popen "pwd")
|
(-> (io.popen "pwd")
|
||||||
(: :read :*a)
|
(: :read :*a)
|
||||||
(stringx.strip)))
|
(stringx.strip)
|
||||||
|
(.. "/test/test-project")))
|
||||||
(local ROOT-URI
|
(local ROOT-URI
|
||||||
(.. "document://" ROOT-PATH))
|
(.. "file://" ROOT-PATH))
|
||||||
|
|
||||||
(local server-initialize-message
|
(local server-initialize-message
|
||||||
{:id 1
|
{:id 1
|
||||||
@ -35,16 +36,41 @@
|
|||||||
:result {:capabilities {}
|
:result {:capabilities {}
|
||||||
:serverInfo {:name "fennel-ls" : version}}}]))
|
:serverInfo {:name "fennel-ls" : version}}}]))
|
||||||
|
|
||||||
(it "can jump to definition"
|
(describe "jump to definition"
|
||||||
(local state [])
|
(it "handles (local _ (require XXX)"
|
||||||
(dispatch.handle* state server-initialize-message)
|
(local state [])
|
||||||
(assert-matches
|
(dispatch.handle* state server-initialize-message)
|
||||||
(dispatch.handle* state
|
(assert-matches
|
||||||
{:id 2
|
(dispatch.handle* state
|
||||||
:jsonrpc "2.0"
|
{:id 2
|
||||||
:method "textDocument/definition"
|
:jsonrpc "2.0"
|
||||||
:params {:position {:character 5 :line 0}
|
:method "textDocument/definition"
|
||||||
:textDocument {:uri (.. ROOT-URI "/test.fnl")}}})
|
:params {:position {:character 11 :line 0}
|
||||||
[{:id 2
|
:textDocument {:uri (.. ROOT-URI "/example.fnl")}}})
|
||||||
:jsonrpc "2.0"
|
(where [{:id 2
|
||||||
:result {: uri : range}}]))) ;; FIXME: test whether the location is correct
|
: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")))
|
||||||
|
|||||||
1
test/test-project/bar.fnl
Normal file
1
test/test-project/bar.fnl
Normal file
@ -0,0 +1 @@
|
|||||||
|
nil
|
||||||
8
test/test-project/example.fnl
Normal file
8
test/test-project/example.fnl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
(local foo (require :foo))
|
||||||
|
(require :bar)
|
||||||
|
|
||||||
|
(fn bar [a b]
|
||||||
|
(print a b)
|
||||||
|
(foo.my-export))
|
||||||
|
|
||||||
|
{: bar}
|
||||||
5
test/test-project/foo.fnl
Normal file
5
test/test-project/foo.fnl
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(local constant 5)
|
||||||
|
|
||||||
|
(fn my-export [])
|
||||||
|
|
||||||
|
{: my-export : constant}
|
||||||
Loading…
Reference in New Issue
Block a user