docs get-global takes a self parameter

This commit is contained in:
XeroOl 2024-05-07 14:03:19 -05:00
parent 10aeb63142
commit db7a911b7f
4 changed files with 16 additions and 16 deletions

View File

@ -88,7 +88,7 @@ identifiers are declared / referenced in which places."
;; find reference
(let [name (string.match (tostring symbol) "[^%.:]+")]
(case (or (find-definition (tostring name) scope)
(docs.get-global-metadata name))
(docs.get-global self name))
target (let [ref {: symbol : target : ref-type}]
(tset references symbol ref)
(when target.referenced-by
@ -360,8 +360,6 @@ identifiers are declared / referenced in which places."
(collect-everything ast lexical)
;; This is bad; we mutate fennel.macro-path
(let [old-macro-path fennel.macro-path]
(set fennel.macro-path

View File

@ -3,19 +3,21 @@
:macros MACROS}}}
(require :fennel.compiler))
(local specials-metadata
(local specials
(collect [name value (pairs SPECIALS)]
name {:binding name :metadata (. METADATA value)}))
(local macros-metadata
(local macros*
(collect [name value (pairs MACROS)]
name {:binding name :metadata (. METADATA value)}))
(local lua54-metadata (require :fennel-ls.docs.lua54))
(local lua54 (require :fennel-ls.docs.lua54))
(fn get-global-metadata [global-name]
(or (. specials-metadata global-name)
(. macros-metadata global-name)
(. lua54-metadata global-name)))
(fn get-global [_self global-name]
(or (. specials global-name)
(. macros* global-name)
(. lua54 global-name)))
{: get-global-metadata}
;; TODO get-module-metadata
{: get-global}

View File

@ -162,7 +162,7 @@ Every time the client sends a message, it gets handled by a function in the corr
{: definition : file}
(case (values definition (type definition))
;; fields of a string are hardcoded to "string"
(_str :string) (icollect [label info (pairs (. (docs.get-global-metadata :string) :fields))]
(_str :string) (icollect [label info (pairs (. (docs.get-global self :string) :fields))]
(formatter.completion-item-format label info))
;; fields of a table
(tbl :table) (let [keys []]

View File

@ -38,7 +38,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
{:binding z :definition y}, referring to the `(local z y)` binding.
"
(local {: sym? : list? : sequence? : varg? : sym} (require :fennel))
(local {: sym? : list? : sequence? : varg?} (require :fennel))
(local utils (require :fennel-ls.utils))
(local state (require :fennel-ls.state))
(local docs (require :fennel-ls.docs))
@ -155,7 +155,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
(if (sym? ast) (search-symbol self file ast stack opts)
(= 0 (length stack)) {:definition ast : file} ;; BASE CASE !!
(= :table (type ast)) (search-table self file ast stack opts)
(= :string (type ast)) (search-document self (docs.get-global-metadata :string) stack opts))
(= :string (type ast)) (search-document self (docs.get-global self :string) stack opts))
nil)))
@ -175,7 +175,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
split (utils.multi-sym-split symbol (if ?byte (- ?byte symbol.bytestart)))]
(stack-add-split! [] split)))]
(case (docs.get-global-metadata (utils.multi-sym-base symbol))
(case (docs.get-global self (utils.multi-sym-base symbol))
document (search-document self document stack opts)
_ (case (. file.references symbol)
ref (search-reference self file ref stack opts)
@ -193,7 +193,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
(assert (= (type name) :string))
(let [split (utils.multi-sym-split name)
stack (stack-add-split! [] split)]
(case (docs.get-global-metadata (. split 1))
(case (docs.get-global self (. split 1))
metadata (search-document self metadata stack (or ?opts {}))
_ (case (find-local-definition file name scope)
def (search-val self file def.definition (stack-add-keys! stack def.keys) (or ?opts {}))))))