Make the root folder optional

This commit is contained in:
XeroOl 2024-05-17 20:45:16 -05:00
parent 5018444d1a
commit a122d9d361
4 changed files with 38 additions and 33 deletions

View File

@ -55,7 +55,7 @@ identifiers are declared / referenced in which places."
{:start position :end position})) {:start position :end position}))
(λ compile [{:configuration {: macro-path} : root-uri &as self} file] (λ compile [{:configuration {: macro-path} :root-uri ?root-uri &as self} file]
"Compile the file, and record all the useful information from the compiler into the file object" "Compile the file, and record all the useful information from the compiler into the file object"
;; The useful information being recorded: ;; The useful information being recorded:
(let [definitions-by-scope (doto {} (setmetatable has-tables-mt)) (let [definitions-by-scope (doto {} (setmetatable has-tables-mt))
@ -364,14 +364,16 @@ identifiers are declared / referenced in which places."
;; This is bad; we mutate fennel.macro-path ;; This is bad; we mutate fennel.macro-path
(let [old-macro-path fennel.macro-path] (let [old-macro-path fennel.macro-path]
(set fennel.macro-path (when ?root-uri
(searcher.add-workspaces-to-path macro-path [root-uri])) (set fennel.macro-path
(searcher.add-workspaces-to-path macro-path [?root-uri])))
;; compile ;; compile
(each [_i form (ipairs (if macro-file? (ast->macro-ast ast) ast))] (each [_i form (ipairs (if macro-file? (ast->macro-ast ast) ast))]
(filter-errors :compiler (xpcall #(fennel.compile form opts) fennel.traceback))) (filter-errors :compiler (xpcall #(fennel.compile form opts) fennel.traceback)))
(set fennel.macro-path old-macro-path)) (when ?root-uri
(set fennel.macro-path old-macro-path)))
(each [_ cmd (ipairs defer)] (each [_ cmd (ipairs defer)]
(cmd)) (cmd))

View File

@ -42,19 +42,21 @@ I suspect this file may be gone after a bit of refactoring."
(case (io.open (utils.uri->path uri)) (case (io.open (utils.uri->path uri))
f (do (f:close) true)))) f (do (f:close) true))))
(λ lookup [{:configuration {: fennel-path} : root-uri &as self} mod] (λ lookup [{:configuration {: fennel-path} :root-uri ?root-uri &as self} mod]
(let [mod (mod:gsub "%." sep) "Use the fennel path to find a file on disk"
root-path (utils.uri->path root-uri)] (when ?root-uri
(accumulate [uri nil (let [mod (mod:gsub "%." sep)
segment (fennel-path:gmatch "[^;]+") root-path (utils.uri->path ?root-uri)]
&until uri] (accumulate [uri nil
(let [segment (segment:gsub "%?" mod) segment (fennel-path:gmatch "[^;]+")
segment (if (absolute? segment) &until uri]
segment (let [segment (segment:gsub "%?" mod)
(join root-path segment)) segment (if (absolute? segment)
segment (utils.path->uri segment)] segment
(if (file-exists? self segment) (join root-path segment))
segment))))) segment (utils.path->uri segment)]
(if (file-exists? self segment)
segment))))))
{: lookup {: lookup
: add-workspaces-to-path} : add-workspaces-to-path}

View File

@ -11,24 +11,25 @@
(.. "file://" ROOT-PATH)) (.. "file://" ROOT-PATH))
(local default-encoding :utf-8) (local default-encoding :utf-8)
(local default-params
{:capabilities {:general {:positionEncodings [default-encoding]}}
:clientInfo {:name "Neovim" :version "0.7.2"}
:initializationOptions {}
:processId 16245
:rootPath ROOT-PATH
:rootUri ROOT-URI
:trace "off"
:workspaceFolders [{:name ROOT-PATH
:uri ROOT-URI}]})
(local mt {}) (local mt {})
(fn create-client [?opts] (fn create-client [?opts ?provide-root-uri]
(let [self (doto {:server [] :prev-id 1} (setmetatable mt)) (let [self (doto {:server [] :prev-id 1} (setmetatable mt))
params (or (?. ?opts :params)
{:capabilities {:general {:positionEncodings [default-encoding]}}
:clientInfo {:name "Neovim" :version "0.7.2"}
:initializationOptions {}
:processId 16245
:rootPath (if ?provide-root-uri ROOT-PATH)
:rootUri (if ?provide-root-uri ROOT-URI)
:trace "off"
:workspaceFolders (if ?provide-root-uri
[{:name ROOT-PATH
:uri ROOT-URI}])})
initialize {:id 1 initialize {:id 1
:jsonrpc "2.0" :jsonrpc "2.0"
:method "initialize" :method "initialize"
:params (or (?. ?opts :params) default-params)} : params}
result (dispatch.handle* self.server initialize)] result (dispatch.handle* self.server initialize)]
(case (?. ?opts :settings) (case (?. ?opts :settings)
settings settings

View File

@ -34,10 +34,10 @@
result)) result))
(fn create-client-with-files [file-contents ?client-options] (fn create-client-with-files [file-contents ?client-options]
(let [file-contents (if (= (type file-contents) :string) (let [(?give-a-root-uri file-contents) (if (= (type file-contents) :string)
{:main.fnl file-contents} (values nil {:main.fnl file-contents})
file-contents) (values true file-contents))
self (create-client ?client-options) self (create-client ?client-options ?give-a-root-uri)
locations []] locations []]
(each [name marked (pairs file-contents)] (each [name marked (pairs file-contents)]
(if (not= name :main.fnl) (if (not= name :main.fnl)