go-to-definition for require with fixed module name

This commit is contained in:
XeroOl 2022-07-30 23:58:12 -05:00
parent 3c91ad0680
commit db59350a1c
No known key found for this signature in database
GPG Key ID: 9DD4B4B4DAED0322
6 changed files with 76 additions and 48 deletions

View File

@ -8,7 +8,7 @@
(local state [])
(while true
(let [msg (json-rpc.read in)]
(log msg)
;; (log msg)
(dispatch.handle state send msg))))
(λ main []

View File

@ -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"}))))

View File

@ -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")))

View File

@ -0,0 +1 @@
nil

View File

@ -0,0 +1,8 @@
(local foo (require :foo))
(require :bar)
(fn bar [a b]
(print a b)
(foo.my-export))
{: bar}

View File

@ -0,0 +1,5 @@
(local constant 5)
(fn my-export [])
{: my-export : constant}