Various changes, and fix a searcher crash

This commit is contained in:
XeroOl 2023-06-22 23:28:17 -05:00
parent e5742bbc4e
commit 2c61b5401a
7 changed files with 30 additions and 21 deletions

View File

@ -93,10 +93,10 @@ Every time the client sends a message, it gets handled by a function in the corr
(if (. file.definitions symbol)
(values (. file.definitions symbol) file)
(language.search-main self file symbol {:stop-early? true} byte))
(definition result-file)
({: referenced-by &as definition} result-file)
(let [result
(icollect [_ symbol (ipairs definition.referenced-by)]
;; TODO we currently assume all references are in the same file
(icollect [_ symbol (ipairs referenced-by)]
;; TODO I currently assume all references are in the same file
(message.range-and-uri symbol result-file))]
(if ?include-declaration?
(table.insert result
@ -115,7 +115,6 @@ Every time the client sends a message, it gets handled by a function in the corr
:range (message.ast->range symbol file)}
(catch _ nil))))
;; All of the helper functions for textDocument/completion are here until I
;; finish refactoring them, and then they can find a home in language.fnl
(λ collect-scope [scope typ callback ?target]

View File

@ -14,6 +14,7 @@ the data provided by compiler.fnl."
(local -let- (sym :let))
(local -fn- (sym :fn))
(local -nil- (sym :nil))
(local -setmetatable- (sym :setmetatable))
(var search nil) ;; all of the search functions are mutually recursive
@ -61,10 +62,12 @@ the data provided by compiler.fnl."
(λ search-list [self file call stack opts]
(match call
[-require- mod]
(let [newfile (state.get-by-module self mod)]
(when newfile
(let [newitem (. newfile.ast (length newfile.ast))]
(search self newfile newitem stack (doto opts (tset :searched-through-require true))))))
(when (= :string (type mod))
(let [newfile (state.get-by-module self mod)]
(when newfile
(let [newitem (. newfile.ast (length newfile.ast))]
(search self newfile newitem stack (doto opts (tset :searched-through-require true)))))))
;; A . form indexes into item 1 with the other items
(where [-dot- & split] (. split 1))
(search self file (. split 1) (stack-add-split! stack split) opts)
@ -76,6 +79,10 @@ the data provided by compiler.fnl."
(where [-let- _binding & body] (. body 1))
(search self file (. body (length body)) stack opts)
;; TODO care about the setmetatable call
(where [-setmetatable- tbl _mt])
(search self file tbl stack opts)
;; functions evaluate to "themselves"
[-fn-]
(values {:definition call} file) ;; BASE CASE !!
@ -91,8 +98,8 @@ the data provided by compiler.fnl."
(sym? item) (search-symbol self file item stack opts)
(list? item) (search-list self file item stack opts)
(= :table (type item)) (search-table self file item stack opts)
(= 0 (length stack)) {:definition item} ;; BASE CASE !!
(error (.. "I don't know what to do with " (view item))))))
(= 0 (length stack)) {:definition item}))) ;; BASE CASE !!
;; (error (.. "I don't know what to do with " (view item))))))
(local {:metadata METADATA
:scopes {:global {:specials SPECIALS

View File

@ -5,8 +5,8 @@
(local {: ROOT-URI
: create-client} (require :test.mock-client))
(macro find [t body ?sentinel]
(assert-compile (not ?sentinel) "you can only have one thing here, put a `(do)`")
(macro find [t body ?should-be-nil]
(assert-compile (= nil ?should-be-nil) "you can only have one thing here, put a `(do)`")
(assert-compile (sequence? t) "[] square brackets please")
(local result (gensym :result))
(local nil* (sym :nil))

View File

@ -1,7 +1,7 @@
;; this package is here to translate into lust's weird dsl
(local {: view} (require :fennel))
(local {: expect} (require :test.lust))
;; lust uses weird terminology, but equal is by __eq, same is by recursively having the same contents
;; lust uses weird terminology, but what I say is that "equal" is by __eq, "same" is by recursively having the same contents
(setmetatable {:equal #(do ((. (expect $1) :to :be) $2) true)
:same #(do ((. (expect $1) :to :equal) $2 $3) true)
:nil #(do ((. (expect $1) :to_not :exist)) true)

View File

@ -8,14 +8,14 @@
(local filename (.. ROOT-URI "/imaginary-file.fnl"))
(fn check-references [body line col expected]
(fn check-references [body line col ?expected]
(let [client (doto (create-client)
(: :open-file! filename body))
response (client:references filename line col)]
(is-matching response
(where [{:jsonrpc "2.0" :id client.prev-id
: result}]
(is.same result expected)))))
:result ?result}]
(is.same ?result ?expected)))))
(describe "references"
(it "finds a reference from let"
@ -24,4 +24,8 @@
(it "finds a reference from let"
(check-references "(let [x 10] x)" 0 6
[{:uri filename :range (message.pos->range 0 12 0 13)}])))
[{:uri filename :range (message.pos->range 0 12 0 13)}]))
(it "doesn't crash here"
(check-references "(let [x nil] x.y)" 0 14
nil)))

View File

@ -17,7 +17,7 @@
(it "can set the macro path"
(let [client (create-client {:fennel-ls {:macro-path "./?/?.fnl"}})
responses (client:open-file! (.. ROOT-URI :/test.fnl) "(import-macros {: this-is-in-modname} :modname)")]
(print ((. (require :fennel) :view) responses))))
(assert (not (. responses 1 :params 1)) "if the import-macros fails it generates a diagnostic (for now at least)")))
;; (it "recompiles modules if the macro files are modified)"

View File

@ -12,9 +12,8 @@
;; test for unicode utf8 utf16 nightmare
;; (it "can handle unicode"
;; (local uri (.. ROOT-URI "test_document"))
;; (local my-document (document.create uri ""))
;; (document.replace my-document 0 0 0 0 "どれみふぁそらてぃど")
;; (utils.apply-changes ""
;; [{:range (range 0 0 0 0) :text "どれみふぁそらてぃど")
;; (document.replace my-document 0 1 0 3 "😀")
;; (document.replace my-document 0 11 0 11 "end")
;; (is-matching my-document {:text "ど😀ふぁそらてぃどend"})))