From 4c92af1bc506f9bb3ed9f88d27e5a49c24873582 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Fri, 17 May 2024 20:45:37 -0500 Subject: [PATCH] Align allowed-globals with the currently selected docs --- src/fennel-ls/compiler.fnl | 4 +--- src/fennel-ls/docs.fnl | 26 +++++++++++++------------- test/completion.fnl | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index fd6d4a9..3ad3811 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -293,9 +293,7 @@ identifiers are declared / referenced in which places." (call-me-to-reset-the-compiler) (error "__NOT_AN_ERROR")))) - (local allowed-globals - (icollect [k _ (pairs _G)] - k)) + (local allowed-globals (docs.get-all-globals self)) (each [_ v (ipairs (utils.split-spaces self.configuration.extra-globals))] (table.insert allowed-globals v)) diff --git a/src/fennel-ls/docs.fnl b/src/fennel-ls/docs.fnl index b92ade5..b24f7eb 100644 --- a/src/fennel-ls/docs.fnl +++ b/src/fennel-ls/docs.fnl @@ -18,22 +18,21 @@ :lua53 (require :fennel-ls.docs.lua53) :lua54 (require :fennel-ls.docs.lua54)}) -(fn compute-global-docs [self] - (local sets []) - (when (not (. versions self.configuration.version)) - (error (.. "fennel-ls doesn't know about lua version " self.configuration.version "\n" - "The allowed versions are:" +(fn get-lua-version [version] + (when (not (. versions version)) + (error (.. "fennel-ls doesn't know about lua version " version "\n" + "The allowed versions are: " (fennel.view (icollect [key (pairs versions)] key))))) - (table.insert sets (. versions self.configuration.version))) + (. versions version)) + +(fn get-all-globals [self] + (icollect [name (pairs (get-lua-version self.configuration.version))] + name)) (fn get-global [self global-name] - (when (not (. versions self.configuration.version)) - (error (.. "fennel-ls doesn't know about lua version " self.configuration.version "\n" - "The allowed versions are:" - (fennel.view (icollect [key (pairs versions)] - key))))) - (. versions self.configuration.version global-name)) + (. (get-lua-version self.configuration.version) + global-name)) (fn get-builtin [_self builtin-name] (or (. specials builtin-name) @@ -42,4 +41,5 @@ ;; TODO get-module-metadata {: get-global - : get-builtin} + : get-builtin + : get-all-globals} diff --git a/test/completion.fnl b/test/completion.fnl index 515d01f..24846aa 100644 --- a/test/completion.fnl +++ b/test/completion.fnl @@ -179,7 +179,7 @@ ;; things that aren't present in lua5.4 but are in other versions, I guess?? (local things-that-are-allowed-to-have-missing-docs - {:lua 1 :set-forcibly! 1 :unpack 1 :setfenv 1 :getfenv 1 :module 1 :newproxy 1 :gcinfo 1 :loadstring 1 :bit 1 :jit 1 :bit32 1}) + {:lua 1 :set-forcibly! 1}) ;:unpack 1 :setfenv 1 :getfenv 1 :module 1 :newproxy 1 :gcinfo 1 :loadstring 1 :bit 1 :jit 1 :bit32 1}) (check "(" [;; builtin specials