fix a crash

This isn't a great fix, but now finding the definition of a number
doesn't cause a crash.

It used to crash because there's no way to get metadata about the
source-code location of a number.
This commit is contained in:
XeroOl 2023-09-18 16:56:16 -05:00
parent 223976194e
commit 824525573a
3 changed files with 14 additions and 5 deletions

View File

@ -327,7 +327,6 @@ later by fennel-ls.language to answer requests from the client."
(set file.definitions-by-scope definitions-by-scope)
(set file.diagnostics diagnostics)
(set file.references references)
(set file.deep-references references)
(set file.require-calls require-calls)
(set file.allowed-globals allowed-globals))))

View File

@ -135,10 +135,13 @@ WARNING: this is only used in the test code, not in the real language server"
{:range {: start : end} : newText}
(replace contents start end newText encoding))))
(λ get-ast-info [?ast info]
;; find a given key of info from an AST object
(or (?. (getmetatable ?ast) info)
(?. ?ast info)))
(λ get-ast-info [ast info]
"gets `info` from ast if possible"
(if (= :number (type ast))
nil
;; find a given key of info from an AST object
(or (?. (getmetatable ast) info)
(?. ast info))))
(fn multi-sym-split [symbol ?offset]
(local symbol (tostring symbol))

View File

@ -97,6 +97,13 @@
:range {:start {:line 0 :character 4}
:end {:line 0 :character 5}}}}])))
(it "doesn't crash when doing this"
(let [c (create-client)
_ (c:open-file! :foo.fnl "(macro cool [a b] `(let [,b 10] ,a))\n(cool x x)")
_response (c:definition :foo.fnl 1 6)
_response (c:definition :foo.fnl 1 8)]
nil))
;; (it "can go through more than one extra file")
;; (it "will give up instead of freezing on recursive requires")
;; (it "finds the definition of in-file macros")