Add settings (untested / undocumented)

This commit is contained in:
XeroOl 2022-09-22 00:44:10 -05:00
parent 566b475ff8
commit a86c52f33a
No known key found for this signature in database
GPG Key ID: 9DD4B4B4DAED0322
4 changed files with 39 additions and 19 deletions

View File

@ -159,14 +159,14 @@ Every time the client sends a message, it gets handled by a function in the corr
(set file.open? false)) (set file.open? false))
(λ notifications.workspace/didChangeConfiguration [self send params] (λ notifications.workspace/didChangeConfiguration [self send params]
(set self.settings params.fennel-ls)) (state.write-config self params.fennel-ls))
;; TODO respect the settings
(λ requests.shutdown [self send] (λ 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" "The server still needs to respond to this request, so the program can't close yet. Just wait until notifications.exit"
nil) nil)
(λ notifications.exit [self] (λ notifications.exit [self]
"This is the real shutdown request, we can quit now"
(os.exit 0)) (os.exit 0))
{: requests {: requests

View File

@ -1,14 +1,10 @@
"Searcher "Searcher
This file has all the logic needed to take the name of a module and find the corresponding URI. 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 fennel (require :fennel))
(local utils (require :fennel-ls.utils)) (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)) (local sep (package.config:sub 1 1))
(λ is_absolute [path] (λ 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.insert result (join (utils.uri->path workspace) path)))))
(table.concat result ";"))) (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])) (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) modname (utils.path->uri modname)
nil nil)) nil nil))

View File

@ -9,11 +9,6 @@ object."
(local searcher (require :fennel-ls.searcher)) (local searcher (require :fennel-ls.searcher))
(local {: compile} (require :fennel-ls.compiler)) (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] (λ read-file [uri]
(with-open [fd (io.open (utils.uri->path uri))] (with-open [fd (io.open (utils.uri->path uri))]
{:uri uri {:uri uri
@ -61,7 +56,36 @@ object."
(compile self file) (compile self file)
file))) file)))
{: get-by-uri (local default-config
: get-by-module {: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 : set-uri-contents
: init-state} : write-config}

View File

@ -56,7 +56,7 @@
(check :goto-definition.fnl 35 19 :goto-definition.fnl 34 20 34 35)) (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" (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" (it "goes further if you go to definition on a binding"
(check :goto-definition.fnl 31 12 :goto-definition.fnl 23 4 23 5)) (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)) (check :goto-definition.fnl 45 15 :goto-definition.fnl 40 7 40 13))
(it "works directly on a require/include (require XXX))" (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`" (it "goes to the last form of `do` and `let`"
(check :goto-definition.fnl 47 13 :goto-definition.fnl 47 30 47 52)) (check :goto-definition.fnl 47 13 :goto-definition.fnl 47 30 47 52))