diff --git a/README.md b/README.md index 4eb6495..deda5f5 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,15 @@ fennel-ls default settings: "checks": { "unused-definition": true, "unknown-module-field": true - } + }, + "extra-globals": "" } } ``` +extra-globals +: Space separated list of allowed global identifiers; in addition to a set of predefined lua globals. + Your editor can send these settings using one of these two methods: * The client sends an `initialize` request with the structure `{initializationOptions: {"fennel-ls": {...}}, ...}` * The client sends a `workspace/didChangeConfiguration` notfication containing the field `{settings: {"fennel-ls": {YOUR_SETTINGS}}}` diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index 9ac3c03..c2b9ef6 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -263,11 +263,8 @@ later by fennel-ls.language to answer requests from the client." (local allowed-globals (icollect [k _ (pairs _G)] k)) - - ;; just a couple of globals that are probably not errors - ;; TODO make this configurable in a better way - (table.insert allowed-globals :vim) - (table.insert allowed-globals :love) + (each [_ v (ipairs (utils.split-spaces self.configuration.extra-globals))] + (table.insert allowed-globals v)) ;; TODO clean up this code. It's awful now that there is error handling (let [macro-file? (= (file.text:sub 1 24) ";; fennel-ls: macro-file") diff --git a/src/fennel-ls/state.fnl b/src/fennel-ls/state.fnl index 54be034..b2902d0 100644 --- a/src/fennel-ls/state.fnl +++ b/src/fennel-ls/state.fnl @@ -62,7 +62,6 @@ in the \"self\" object." ;; TODO: set the warning levels of lints ;; allow all globals -;; allow some globals ;; pick from existing libraries of globals (ie love2d) ;; pick between different versions of lua (ie luajit) ;; pick a "compat always" mode that accepts anything if it could be valid in any lua @@ -97,7 +96,8 @@ in the \"self\" object." :checks {:unused-definition (option true) :unknown-module-field (option true) :unnecessary-method (option true) - :bad-unpack (option true)}}) + :bad-unpack (option true)} + :extra-globals (option "")}) (λ make-configuration [?c] (make-configuration-from-template default-configuration ?c)) diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index beb9636..1ac6171 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -171,6 +171,10 @@ WARNING: this is only used in the test code, not in the real language server" (table.insert result new-item))) result)) +(λ split-spaces [str] + (icollect [m (str:gmatch "[^ ]+")] + m)) + {: uri->path : path->uri : pos->position @@ -181,4 +185,5 @@ WARNING: this is only used in the test code, not in the real language server" : multi-sym-split : get-ast-info : uniq-by - : type=} + : type= + : split-spaces} diff --git a/test/misc-test.fnl b/test/misc-test.fnl index bf8d531..5bcd35c 100644 --- a/test/misc-test.fnl +++ b/test/misc-test.fnl @@ -60,3 +60,15 @@ (is.not.nil (state.get-by-module self.server :crash-files.test1))))) ; (is.not.nil (searcher.lookup self.server :crash-files.test2)) ; (is.not.nil (state.get-by-module self.server :crash-files.test2))))) + +(describe "split-spaces" + (it "should split empty string" + (is.same [] (utils.split-spaces ""))) + (it "should split single word" + (is.same ["foo"] (utils.split-spaces "foo"))) + (it "should trim single word" + (is.same ["foo"] (utils.split-spaces " foo "))) + (it "should split multiple words" + (is.same ["foo-bar" "bar" "baz"] (utils.split-spaces "foo-bar bar baz"))) + (it "should split multiple words with arbitrary white space" + (is.same ["foo-bar" "bar" "baz"] (utils.split-spaces " foo-bar bar baz ")))) diff --git a/test/settings-test.fnl b/test/settings-test.fnl index 5f84230..8d9ec50 100644 --- a/test/settings-test.fnl +++ b/test/settings-test.fnl @@ -26,11 +26,13 @@ ;; (it "can infer the macro path from fennel-path" ;; (local self (doto [] (setup-server {:fennel-ls {:fennel-path "./?/?.fnl"}})))) - ;; (it "can accept an allowed global" - ;; (local self (doto [] (setup-server {:fennel-ls {:extra-globals "vim"}})))) - - ;; (it "can accept a list of allowed globals" - ;; (local self (doto [] (setup-server {:fennel-ls {:extra-globals "GAMESTATE,SCREEN_CENTER_X,ETC"}})))) + (it "can set extra allowed globals" + (let [client (create-client {:settings {:fennel-ls {:extra-globals "foo-100 bar"}}}) + responses (client:open-file! (.. ROOT-URI :/test.fnl) "(foo-100 bar :baz)")] + (is-matching responses + [{:method :textDocument/publishDiagnostics + :params {:diagnostics [nil]}}] + "bad"))) ;; (it "can turn off strict globals" ;; (local self (doto [] (setup-server {:fennel-ls {:checks {:globals false}}}))))