flsproject update on save

This commit is contained in:
XeroOl 2024-07-07 12:35:26 -05:00
parent fbd9b0981f
commit caab3ebfd1
3 changed files with 19 additions and 6 deletions

View File

@ -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}

View File

@ -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}}]

View File

@ -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}