From caab3ebfd1759793a819736aa6a8a6508bf01eec Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sun, 7 Jul 2024 12:35:26 -0500 Subject: [PATCH] flsproject update on save --- src/fennel-ls/config.fnl | 10 +++++++--- src/fennel-ls/handlers.fnl | 7 +++++-- src/fennel-ls/utils.fnl | 8 +++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/fennel-ls/config.fnl b/src/fennel-ls/config.fnl index 3c00b88..3eb8a7f 100644 --- a/src/fennel-ls/config.fnl +++ b/src/fennel-ls/config.fnl @@ -70,7 +70,7 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf- (local [ok? _err result] [(pcall (fennel.parser text uri))]) (if ok? result)) -(λ make-configuration-2 [server] +(λ load-config [server] "This is where we can put anything that needs to react to config changes" (make-configuration @@ -78,14 +78,18 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf- (-?> (files.read-file server (utils.path->uri (utils.path-join (utils.uri->path server.root-uri) "flsproject.fnl"))) try-parsing)))) +(λ reload [server] + (set server.configuration (load-config server))) + (λ initialize [server params] (set server.files {}) (set server.modules {}) (set server.root-uri params.rootUri) (set server.position-encoding (choose-position-encoding params)) - (set server.configuration (make-configuration-2 server)) + (reload server) ;; Eglot does completions differently than every other client I've seen so far, in that it considers foo.bar to be one "symbol". ;; If the user types `foo.b`, every other client accepts `bar` as a completion, bun eglot wants the full `foo.bar` symbol. (set server.EGLOT_COMPLETION_QUIRK_MODE (= (?. params :clientInfo :name) :Eglot))) -{: initialize} +{: initialize + : reload} diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index a1655e1..4c0930f 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -273,8 +273,11 @@ Every time the client sends a message, it gets handled by a function in the corr (send (message.diagnostics file)) (set file.open? true)) -(λ notifications.textDocument/didSave [_server _send _server] - ;; TODO be careful about which modules need to be recomputed, and also eagerly flush existing files +(λ notifications.textDocument/didSave [server send {: uri}] + (when (utils.endswith uri "flsproject.fnl") + (config.reload server)) + + ;; TODO recompute for files when macro is changed (set fennel.macro-loaded [])) (λ notifications.textDocument/didClose [server _send {:textDocument {: uri}}] diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index 25a4630..9e63351 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -93,6 +93,11 @@ These functions are all pure functions, which makes me happy." (let [len (length pre)] (= (str:sub 1 len) pre))) +(λ endswith [str post] + (let [len (length post)] + (or (= post "") + (= post (str:sub (- len)))))) + (λ uri->path [uri] "Strips the \"file://\" prefix from a uri to turn it into a path. Throws an error if it is not a path uri" (local prefix "file://") @@ -225,4 +230,5 @@ WARNING: this is only used in the test code, not in the real language server" : split-spaces : absolute-path? : path-join - : path-sep} + : path-sep + : endswith}