diff --git a/src/fennel-ls/config.fnl b/src/fennel-ls/config.fnl index 3eb8a7f..3e1cbd4 100644 --- a/src/fennel-ls/config.fnl +++ b/src/fennel-ls/config.fnl @@ -19,15 +19,15 @@ There are no global settings. They're all stored in the `server` object. (local default-configuration {:fennel-path (option "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl") :macro-path (option "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl") - :version (option "lua54") - :checks {:unused-definition (option true) - :unknown-module-field (option true) - :unnecessary-method (option true) - :bad-unpack (option true) - :var-never-set (option true) - :op-with-no-arguments (option true) - :multival-in-middle-of-call (option true)} - :native-libraries (option []) + :lua-version (option "lua54") + :lints {:unused-definition (option true) + :unknown-module-field (option true) + :unnecessary-method (option true) + :bad-unpack (option true) + :var-never-set (option true) + :op-with-no-arguments (option true) + :multival-in-middle-of-call (option true)} + :libraries {:tic-80 (option false)} :extra-globals (option "")}) (fn make-configuration-from-template [default ?user ?parent] diff --git a/src/fennel-ls/docs.fnl b/src/fennel-ls/docs.fnl index 5e25270..b6e7c8c 100644 --- a/src/fennel-ls/docs.fnl +++ b/src/fennel-ls/docs.fnl @@ -26,31 +26,30 @@ (. lua-versions version)) (local libraries - {:tic80 (require :fennel-ls.docs.generated.tic80)}) + {:tic-80 (require :fennel-ls.docs.generated.tic80)}) -(fn get-native-library [library] +(fn get-library [library] (when (not (. libraries library)) - (error (.. "fennel-ls doesn't know about native library " library "\n" + (error (.. "fennel-ls doesn't know about library " library "\n" "The builtin libraries are: " (fennel.view (doto (icollect [key (pairs libraries)] key) table.sort))))) (. libraries library)) (fn get-all-globals [server] (let [result []] - (each [_ library (ipairs server.configuration.native-libraries)] - (icollect [name (pairs (get-native-library library)) &into result] - name)) - (icollect [name (pairs (get-lua-version server.configuration.version)) &into result] + (each [library enabled? (pairs server.configuration.libraries)] + (when enabled? + (icollect [name (pairs (get-library library)) &into result] + name))) + (icollect [name (pairs (get-lua-version server.configuration.lua-version)) &into result] name))) (fn get-global [server global-name] (or - (accumulate [result nil - _ library (ipairs server.configuration.native-libraries) - &until result] - (. (get-native-library library) - global-name)) - (. (get-lua-version server.configuration.version) + (and server.configuration.libraries.tic-80 + (. (get-library :tic-80) + global-name)) + (. (get-lua-version server.configuration.lua-version) global-name))) (fn get-builtin [_server builtin-name] diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index cc24eba..8c00783 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -141,21 +141,21 @@ the `file.diagnostics` field, filling it with diagnostics." (λ check [server file] "fill up the file.diagnostics table with linting things" - (let [checks server.configuration.checks + (let [lints server.configuration.lints diagnostics file.diagnostics] ;; definition lints (each [symbol definition (pairs file.definitions)] - (if checks.unused-definition (table.insert diagnostics (unused-definition server file symbol definition))) - (if checks.var-never-set (table.insert diagnostics (var-never-set server file symbol definition)))) + (if lints.unused-definition (table.insert diagnostics (unused-definition server file symbol definition))) + (if lints.var-never-set (table.insert diagnostics (var-never-set server file symbol definition)))) ;; call lints ;; all non-macro calls. This only covers specials and function calls. (each [[head &as call] (pairs file.calls)] (when head - (if checks.bad-unpack (table.insert diagnostics (bad-unpack server file head call))) - (if checks.unnecessary-method (table.insert diagnostics (unnecessary-method server file head call))) - (if checks.op-with-no-arguments (table.insert diagnostics (op-with-no-arguments server file head call))) + (if lints.bad-unpack (table.insert diagnostics (bad-unpack server file head call))) + (if lints.unnecessary-method (table.insert diagnostics (unnecessary-method server file head call))) + (if lints.op-with-no-arguments (table.insert diagnostics (op-with-no-arguments server file head call))) ;; argument lints ;; every argument to a special or a function call @@ -163,15 +163,15 @@ the `file.diagnostics` field, filling it with diagnostics." ;; I'll wait till we have more lints in here to see if it needs to change. (for [index 2 (length call)] (let [arg (. call index)] - (if checks.multival-in-middle-of-call (table.insert diagnostics (multival-in-middle-of-call server file head call arg index))))))) + (if lints.multival-in-middle-of-call (table.insert diagnostics (multival-in-middle-of-call server file head call arg index))))))) - (if checks.unknown-module-field + (if lints.unknown-module-field (unknown-module-field server file)))) - ;; (if checks.unnecessary-values + ;; (if lints.unnecessary-values ;; (unnecessary-values file))) - ;; (if checks.unnecessary-do) + ;; (if lints.unnecessary-do) ;; (unnecessary-do file))) - ;; (if checks.unnecessary-unary-op)) + ;; (if lints.unnecessary-unary-op)) ;; (unnecessary-values file))) {: check} diff --git a/test/settings.fnl b/test/settings.fnl index 25f1b5b..77475f9 100644 --- a/test/settings.fnl +++ b/test/settings.fnl @@ -38,14 +38,14 @@ nil) ;; (it "can turn off strict globals" - ;; (local client (doto [] (setup-server {:fennel-ls {:checks {:globals false}}})))) + ;; (local client (doto [] (setup-server {:fennel-ls {:lints {:globals false}}})))) ;; (it "can treat globals as a warning instead of an error" ;; (local client (doto [] (setup-server {:fennel-ls {:diagnostics {:E202 "warning"}}}))))) (fn test-lints [] (let [{:diagnostics good} (create-client {:main.fnl "(local x 10)" - :flsproject.fnl "{:checks {:unused-definition false}}"}) + :flsproject.fnl "{:lints {:unused-definition false}}"}) {:diagnostics bad} (create-client {:main.fnl "(local x 10)" :flsproject.fnl "{}"})] (faith.= [] good) @@ -56,7 +56,7 @@ (let [{:diagnostics bad} (create-client {:main.fnl "(print btn)" :flsproject.fnl "{}"}) {:diagnostics good} (create-client {:main.fnl "(print btn)" - :flsproject.fnl "{:native-libraries [:tic80]}"})] + :flsproject.fnl "{:libraries {:tic-80 true}}"})] (faith.not= [] bad) (faith.= [] good)))