From a86c52f33afc0381151665ac48cd0966595acde3 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Thu, 22 Sep 2022 00:44:10 -0500 Subject: [PATCH] Add settings (untested / undocumented) --- src/fennel-ls/handlers.fnl | 4 ++-- src/fennel-ls/searcher.fnl | 10 +++------ src/fennel-ls/state.fnl | 40 ++++++++++++++++++++++++++++------- test/goto-definition-test.fnl | 4 ++-- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index 4ee62df..5c25224 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -159,14 +159,14 @@ Every time the client sends a message, it gets handled by a function in the corr (set file.open? false)) (λ notifications.workspace/didChangeConfiguration [self send params] - (set self.settings params.fennel-ls)) - ;; TODO respect the settings + (state.write-config self params.fennel-ls)) (λ requests.shutdown [self send] "The server still needs to respond to this request, so the program can't close yet. Just wait until notifications.exit" nil) (λ notifications.exit [self] + "This is the real shutdown request, we can quit now" (os.exit 0)) {: requests diff --git a/src/fennel-ls/searcher.fnl b/src/fennel-ls/searcher.fnl index d71d729..61e18a8 100644 --- a/src/fennel-ls/searcher.fnl +++ b/src/fennel-ls/searcher.fnl @@ -1,14 +1,10 @@ "Searcher This file has all the logic needed to take the name of a module and find the corresponding URI. -I suspect this file is going to be gone after a bit of refactoring." +I suspect this file may be gone after a bit of refactoring." (local fennel (require :fennel)) (local utils (require :fennel-ls.utils)) -"works on my machine >:)" -(local luapath "?.lua;src/?.lua") -(local fennelpath "?.fnl;src/?.fnl") - (local sep (package.config:sub 1 1)) (λ is_absolute [path] @@ -39,9 +35,9 @@ I suspect this file is going to be gone after a bit of refactoring." (table.insert result (join (utils.uri->path workspace) path))))) (table.concat result ";"))) -(λ lookup [{: root-uri} mod] +(λ lookup [{:config {: fennel-path} : root-uri} mod] (match (or ;; TODO support lua ;; (fennel.searchModule mod (add-workspaces-to-path luapath [root-uri])) - (fennel.searchModule mod (add-workspaces-to-path fennelpath [root-uri]))) + (fennel.searchModule mod (add-workspaces-to-path fennel-path [root-uri]))) modname (utils.path->uri modname) nil nil)) diff --git a/src/fennel-ls/state.fnl b/src/fennel-ls/state.fnl index 9cd151b..9dd9f0d 100644 --- a/src/fennel-ls/state.fnl +++ b/src/fennel-ls/state.fnl @@ -9,11 +9,6 @@ object." (local searcher (require :fennel-ls.searcher)) (local {: compile} (require :fennel-ls.compiler)) -(λ init-state [self params] - (set self.files {}) - (set self.modules {}) - (set self.root-uri params.rootUri)) - (λ read-file [uri] (with-open [fd (io.open (utils.uri->path uri))] {:uri uri @@ -61,7 +56,36 @@ object." (compile self file) file))) -{: get-by-uri - : get-by-module +(local default-config + {:fennel-path "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl" + :macro-path "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl" + :globals ""}) + +(λ write-config [self ?config] + (if (not ?config) + (set self.config default-config) ;; fast path, use all defaults + (set self.config + {;; fennel-path: + ;; the path to use to find fennel files using (require) or (include) + :fennel-path (or ?config.fennelpath + default-config.fennel-path) + ;; macro-path: + ;; the path to use to find fennel files using (require-macros) or (include-macros) + :macro-path (or ?config.macro-path + default-config.fennel-path) + ;; globals: + ;; Comma separated list of extra globals that are allowed. + :globals (or ?config.globals + default-config.globals)}))) + +(λ init-state [self params] + (set self.files {}) + (set self.modules {}) + (set self.root-uri params.rootUri) + (write-config self)) + +{: get-by-module + : get-by-uri + : init-state : set-uri-contents - : init-state} + : write-config} diff --git a/test/goto-definition-test.fnl b/test/goto-definition-test.fnl index 9af2bd4..1b58e32 100644 --- a/test/goto-definition-test.fnl +++ b/test/goto-definition-test.fnl @@ -56,7 +56,7 @@ (check :goto-definition.fnl 35 19 :goto-definition.fnl 34 20 34 35)) (it "can go to a function in another file when accessed by multisym" - (check :goto-definition.fnl 7 7 :foo.fnl 2 4 2 13)) + (check :goto-definition.fnl 7 7 :./foo.fnl 2 4 2 13)) (it "goes further if you go to definition on a binding" (check :goto-definition.fnl 31 12 :goto-definition.fnl 23 4 23 5)) @@ -70,7 +70,7 @@ (check :goto-definition.fnl 45 15 :goto-definition.fnl 40 7 40 13)) (it "works directly on a require/include (require XXX))" - (check :goto-definition.fnl 1 5 :bar.fnl 0 0 0 2)) + (check :goto-definition.fnl 1 5 :./bar.fnl 0 0 0 2)) (it "goes to the last form of `do` and `let`" (check :goto-definition.fnl 47 13 :goto-definition.fnl 47 30 47 52))