From db7a911b7f50da1017d84cc5e021624df54ba35b Mon Sep 17 00:00:00 2001 From: XeroOl Date: Tue, 7 May 2024 14:03:19 -0500 Subject: [PATCH] docs get-global takes a `self` parameter --- src/fennel-ls/compiler.fnl | 4 +--- src/fennel-ls/docs.fnl | 18 ++++++++++-------- src/fennel-ls/handlers.fnl | 2 +- src/fennel-ls/language.fnl | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index f83e3d0..4a51ea2 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -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 diff --git a/src/fennel-ls/docs.fnl b/src/fennel-ls/docs.fnl index 36d2fb0..124c683 100644 --- a/src/fennel-ls/docs.fnl +++ b/src/fennel-ls/docs.fnl @@ -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} diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index 6eeffc9..3af5991 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -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 []] diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/language.fnl index 2aef3e8..d7aad70 100644 --- a/src/fennel-ls/language.fnl +++ b/src/fennel-ls/language.fnl @@ -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 {}))))))