From 3d1485060c519e8aabe1f12ede09cc5634ce9b42 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Mon, 15 Jul 2024 17:35:25 -0500 Subject: [PATCH] fix "unknown module field" when accessing fields from doc objects with no known fields this means stuff like `io.stderr:write` isn't a warning anymore --- src/fennel-ls/analyzer.fnl | 8 +++++--- src/fennel-ls/lint.fnl | 4 +++- test/init.fnl | 3 ++- test/lint.fnl | 3 +++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/fennel-ls/analyzer.fnl b/src/fennel-ls/analyzer.fnl index 932b9f1..be1f8b4 100644 --- a/src/fennel-ls/analyzer.fnl +++ b/src/fennel-ls/analyzer.fnl @@ -65,14 +65,16 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find (stack-add-split! stack (utils.multi-sym-split symbol))) (λ search-document [server document stack opts] - (when (and (not= (tostring (?. document :binding)) :_G) - (= (length stack) 1)) + (when (not= (tostring (?. document :binding)) :_G) (set opts.searched-through-require-with-stack-size-1 true)) (if (= 0 (length stack)) document (and document.fields (. document.fields (. stack (length stack)))) - (search-document server (. document.fields (table.remove stack)) stack opts))) + (search-document server (. document.fields (table.remove stack)) stack opts) + (not document.fields) + (do + (set opts.searched-through-require-indeterminate true)))) (λ search-val [server file ?ast stack opts] "searches for the definition of the ast, adjusted to 1 value" diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index 80c4764..8c13751 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -46,7 +46,9 @@ the `file.diagnostics` field, filling it with diagnostics." "if ?ast is a module field that isn't known, return a diagnostic" (let [opts {} item (analyzer.search-ast server file ?ast stack opts)] - (if (and (not item) opts.searched-through-require-with-stack-size-1) + (if (and (not item) + opts.searched-through-require-with-stack-size-1 + (not opts.searched-through-require-indeterminate)) {:range (message.ast->range server file symbol) :message (.. "unknown field: " (tostring symbol)) :severity message.severity.WARN diff --git a/test/init.fnl b/test/init.fnl index 45a55bf..5d81964 100644 --- a/test/init.fnl +++ b/test/init.fnl @@ -3,7 +3,8 @@ (case (os.getenv "FAITH_TEST") target (let [(module function) (target:match "([^ ]+) ([^ ]+)")] - (xpcall (. (require module) function) #(print ($:tostring target)))) + (tset package.loaded module {function (. (require module) function)}) + (faith.run [module])) _ (faith.run [:test.json-rpc :test.string-processing diff --git a/test/lint.fnl b/test/lint.fnl index 1d93ee3..055c89b 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -110,6 +110,9 @@ field.unknown"} [] [{:code 302}]) + (check "package.loaded.mymodule io.stderr.write" + [] + [{:code 302}]) nil) (fn test-unnecessary-colon []