Make the root folder optional
This commit is contained in:
parent
5018444d1a
commit
a122d9d361
@ -55,7 +55,7 @@ identifiers are declared / referenced in which places."
|
||||
{: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"
|
||||
;; The useful information being recorded:
|
||||
(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
|
||||
(let [old-macro-path fennel.macro-path]
|
||||
(set fennel.macro-path
|
||||
(searcher.add-workspaces-to-path macro-path [root-uri]))
|
||||
(when ?root-uri
|
||||
(set fennel.macro-path
|
||||
(searcher.add-workspaces-to-path macro-path [?root-uri])))
|
||||
|
||||
;; compile
|
||||
(each [_i form (ipairs (if macro-file? (ast->macro-ast ast) ast))]
|
||||
(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)]
|
||||
(cmd))
|
||||
|
||||
@ -42,19 +42,21 @@ I suspect this file may be gone after a bit of refactoring."
|
||||
(case (io.open (utils.uri->path uri))
|
||||
f (do (f:close) true))))
|
||||
|
||||
(λ lookup [{:configuration {: fennel-path} : root-uri &as self} mod]
|
||||
(let [mod (mod:gsub "%." sep)
|
||||
root-path (utils.uri->path root-uri)]
|
||||
(accumulate [uri nil
|
||||
segment (fennel-path:gmatch "[^;]+")
|
||||
&until uri]
|
||||
(let [segment (segment:gsub "%?" mod)
|
||||
segment (if (absolute? segment)
|
||||
segment
|
||||
(join root-path segment))
|
||||
segment (utils.path->uri segment)]
|
||||
(if (file-exists? self segment)
|
||||
segment)))))
|
||||
(λ lookup [{:configuration {: fennel-path} :root-uri ?root-uri &as self} mod]
|
||||
"Use the fennel path to find a file on disk"
|
||||
(when ?root-uri
|
||||
(let [mod (mod:gsub "%." sep)
|
||||
root-path (utils.uri->path ?root-uri)]
|
||||
(accumulate [uri nil
|
||||
segment (fennel-path:gmatch "[^;]+")
|
||||
&until uri]
|
||||
(let [segment (segment:gsub "%?" mod)
|
||||
segment (if (absolute? segment)
|
||||
segment
|
||||
(join root-path segment))
|
||||
segment (utils.path->uri segment)]
|
||||
(if (file-exists? self segment)
|
||||
segment))))))
|
||||
|
||||
{: lookup
|
||||
: add-workspaces-to-path}
|
||||
|
||||
@ -11,24 +11,25 @@
|
||||
(.. "file://" ROOT-PATH))
|
||||
|
||||
(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 {})
|
||||
(fn create-client [?opts]
|
||||
(fn create-client [?opts ?provide-root-uri]
|
||||
(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
|
||||
:jsonrpc "2.0"
|
||||
:method "initialize"
|
||||
:params (or (?. ?opts :params) default-params)}
|
||||
: params}
|
||||
result (dispatch.handle* self.server initialize)]
|
||||
(case (?. ?opts :settings)
|
||||
settings
|
||||
|
||||
@ -34,10 +34,10 @@
|
||||
result))
|
||||
|
||||
(fn create-client-with-files [file-contents ?client-options]
|
||||
(let [file-contents (if (= (type file-contents) :string)
|
||||
{:main.fnl file-contents}
|
||||
file-contents)
|
||||
self (create-client ?client-options)
|
||||
(let [(?give-a-root-uri file-contents) (if (= (type file-contents) :string)
|
||||
(values nil {:main.fnl file-contents})
|
||||
(values true file-contents))
|
||||
self (create-client ?client-options ?give-a-root-uri)
|
||||
locations []]
|
||||
(each [name marked (pairs file-contents)]
|
||||
(if (not= name :main.fnl)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user