From bc0898510e694fd5b8b279afe5454ae3e97e5b49 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Thu, 27 Feb 2025 00:32:10 -0800 Subject: [PATCH] Missing Lua versions or libraries cause warnings, not crashes. Unfortunately the experience here is not great, at least in emacs; the spec states that the server may send showMessage during initialization, but eglot displays these messages only for a brief flash, quickly replacing them with the "Connected!" message. We probably need a different solution here but it might get ugly; like some kind of outbound queue. --- src/fennel-ls/docs.fnl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/fennel-ls/docs.fnl b/src/fennel-ls/docs.fnl index 18b211f..beb3b62 100644 --- a/src/fennel-ls/docs.fnl +++ b/src/fennel-ls/docs.fnl @@ -31,12 +31,7 @@ (set lua-versions.lua54 (. lua-versions "lua5.4")) (fn get-lua-version [version] - (when (not (. lua-versions version)) - (error (.. "fennel-ls doesn't know about lua version " version "\n" - "The known versions are: " - (fennel.view (doto (icollect [key (pairs lua-versions)] key) - table.sort))))) - (. lua-versions version)) + (or (. lua-versions version) lua-versions.lua54)) ;; work around a mistake in Lua's own manual (set lua-versions.lua51.package.fields.config @@ -57,12 +52,13 @@ (λ load-library [name] (let [path (.. data-dir name docset-ext)] - (case (io.open path :r) - nil (error (string.format "Could not find docset for library %s at %s" - name path)) + (case (io.open path) f (let [docs (fennel.load-code (f:read :a) {})] (f:close) - (docs))))) + (docs)) + _ {:status :not-found + :msg (string.format "Could not find docset for library %s at %s" + name path)}))) (λ get-library [name] (when (not (. libraries name)) @@ -97,10 +93,14 @@ (λ validate-config [configuration invalid] (when (not (. lua-versions configuration.lua-version)) - (invalid (.. "unknown lua version: " configuration.lua-version))) + (invalid (.. "fennel-ls doesn't know about lua version " + configuration.lua-version + "\nThe known versions are: " + (table.concat (icollect [k (pairs lua-versions)] k) ", ")) + :WARN)) (each [library-name (pairs configuration.libraries)] - (case (pcall get-library library-name) - (nil msg) (invalid msg)))) + (case (get-library library-name) + {:status :not-found : msg} (invalid msg :WARN)))) {: get-global : get-builtin