simplify tests. only one create-client function

This commit is contained in:
XeroOl 2024-07-05 00:21:56 -05:00
parent 9e9af12f41
commit d309c80541
15 changed files with 140 additions and 142 deletions

View File

@ -64,7 +64,6 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-
(λ initialize [server params] (λ initialize [server params]
(set server.files {}) (set server.files {})
(set server.preload {})
(set server.modules {}) (set server.modules {})
(set server.root-uri params.rootUri) (set server.root-uri params.rootUri)
(set server.position-encoding (choose-position-encoding params)) (set server.position-encoding (choose-position-encoding params))

View File

@ -11,7 +11,7 @@ in the \"server\" object."
(local {: compile} (require :fennel-ls.compiler)) (local {: compile} (require :fennel-ls.compiler))
(λ read-file [server uri] (λ read-file [server uri]
(let [text (case (. server.preload uri) (let [text (case (?. server.preload uri)
preload preload preload preload
_ (let [file (io.open (utils.uri->path uri))] _ (let [file (io.open (utils.uri->path uri))]
(if file (if file

View File

@ -1,45 +1,46 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: ROOT-URI (local {: create-client : NIL} (require :test.utils))
: ROOT-PATH
: create-client} (require :test.utils.client))
(local {: get-markup} (require :test.utils))
(fn params-with-encodings [encodings]
{:clientInfo {:name "my mock client" :version "9000"}
:rootPath ROOT-PATH
:rootUri ROOT-URI
:workspaceFolders [{:name "foo" :uri ROOT-URI}]
:capabilities {:general {:positionEncodings encodings}}
:trace "off"})
(fn test-offset-encoding [] (fn test-offset-encoding []
(let [(client _ [response]) (let [{: client
(create-client {:params (params-with-encodings [:utf-16])}) : cursor
_ (faith.= :utf-16 (. response :result :capabilities :positionEncoding)) : uri
{: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-16) : encoding
_ (client:open-file! "foo.fnl" text) :locations [{:range {: start : end}}]
[response] (client:definition "foo.fnl" cursor)] : initialize-response} (create-client "(let [==𐐀𐐀== 100] 𐐀𐐀|)"
{:position-encodings [:utf-16]
:markup-encoding :utf-16})
[response] (client:definition uri cursor)]
(faith.= :utf-16 encoding)
(faith.= :utf-16 (. initialize-response 1 :result :capabilities :positionEncoding))
(faith.= cursor {:line 0 :character 20})
(faith.= start response.result.range.start) (faith.= start response.result.range.start)
(faith.= end response.result.range.end)) (faith.= end response.result.range.end))
(let [(client _ [response]) (let [{: client
(create-client {:params (params-with-encodings [:utf-16 :utf-8])}) : cursor
_ (faith.= :utf-8 (. response :result :capabilities :positionEncoding)) : uri
{: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-8) : encoding
_ (client:open-file! "foo.fnl" text) :locations [{:range {: start : end}}]
[response] (client:definition "foo.fnl" cursor)] : initialize-response} (create-client "(let [==𐐀𐐀== 100] 𐐀𐐀|)"
{:position-encodings [:utf-8]
:markup-encoding :utf-8})
[response] (client:definition uri cursor)]
(faith.= :utf-8 encoding)
(faith.= :utf-8 (. initialize-response 1 :result :capabilities :positionEncoding))
(faith.= cursor {:line 0 :character 28})
(faith.= start response.result.range.start) (faith.= start response.result.range.start)
(faith.= end response.result.range.end)) (faith.= end response.result.range.end))
;; utf-16 is the fallback ;; utf-16 is the fallback
(let [(_ _ [response]) (create-client {:params (params-with-encodings nil)})] (let [{: initialize-response} (create-client "" {:position-encodings NIL})]
(faith.= :utf-16 (. response :result :capabilities :positionEncoding))) (faith.= :utf-16 (. initialize-response 1 :result :capabilities :positionEncoding)))
(let [(_ _ [response]) (create-client {:params (params-with-encodings [:random-encoding])})] (let [{: initialize-response} (create-client "" {:position-encodings [:some-unknown-encoding]})]
(faith.= :utf-16 (. response :result :capabilities :positionEncoding))) (faith.= :utf-16 (. initialize-response 1 :result :capabilities :positionEncoding)))
(let [(_ _ [response]) (create-client {:params (params-with-encodings [:utf-8 :utf-16])})] (let [{: initialize-response} (create-client "" {:position-encodings [:utf-8 :utf-16]})]
(faith.= :utf-8 (. response :result :capabilities :positionEncoding))) (faith.= :utf-8 (. initialize-response 1 :result :capabilities :positionEncoding)))
nil) nil)

View File

@ -1,12 +1,12 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local {: apply-edits} (require :fennel-ls.utils)) (local {: apply-edits} (require :fennel-ls.utils))
(create-client-with-files "(print :hi)") (create-client "(print :hi)")
(fn check [file-contents action-I-want-to-take desired-file-contents] (fn check [file-contents action-I-want-to-take desired-file-contents]
(let [{: client : uri :locations [range] : encoding : text} (create-client-with-files file-contents) (let [{: client : uri :locations [range] : encoding : text} (create-client file-contents)
[{:result responses}] (client:code-action uri range.range) [{:result responses}] (client:code-action uri range.range)
action (accumulate [result nil action (accumulate [result nil
_ action (ipairs responses) &until result] _ action (ipairs responses) &until result]
@ -21,7 +21,7 @@
edited-text (apply-edits text edits encoding)] edited-text (apply-edits text edits encoding)]
(faith.= desired-file-contents edited-text)))) (faith.= desired-file-contents edited-text))))
(fn check-negative [file-contents action-not-suggested] (fn check-negative [file-contents action-not-suggested]
(let [{: client : uri :locations [range]} (create-client-with-files file-contents) (let [{: client : uri :locations [range]} (create-client file-contents)
[{:result responses}] (client:code-action uri range.range)] [{:result responses}] (client:code-action uri range.range)]
(each [_ action (ipairs responses)] (each [_ action (ipairs responses)]
(assert (not= action.title action-not-suggested) (assert (not= action.title action-not-suggested)

View File

@ -1,5 +1,5 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: create-client-with-files (local {: create-client
: position-past-end-of-text} (require :test.utils)) : position-past-end-of-text} (require :test.utils))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
@ -42,8 +42,8 @@
(and (= (type e.textEdit) :function)) (e.textEdit c.textEdit)))) (and (= (type e.textEdit) :function)) (e.textEdit c.textEdit))))
i))) i)))
(fn check [file-contents expected unexpected ?client-options] (fn check [file-contents expected unexpected ?client-opts]
(let [{: client : uri : cursor : text} (create-client-with-files file-contents ?client-options) (let [{: client : uri : cursor : text} (create-client file-contents ?client-opts)
[{:result ?result}] (client:completion uri [{:result ?result}] (client:completion uri
(or cursor (or cursor
(position-past-end-of-text text))) (position-past-end-of-text text)))
@ -241,15 +241,7 @@
[]) [])
nil) nil)
(local eglot {:params {:capabilities {:general {:positionEncodings [:utf-8]}} (local eglot {:client-info {:name "Eglot" :version "1 million"}})
:clientInfo {:name "Eglot" :version "1 million"}
:initializationOptions {}
:processId 1000
:rootPath "/home/my-cool-user/my-cool-project/"
:rootUri "file:///home/my-cool-user/my-cool-project/"
:trace "off"
:workspaceFolders [{:name "/home/my-cool-user/my-cool-projects/"
:uri "file:///home/my-cool-user/my-cool-project/"}]}})
(fn test-eglot-fields [] (fn test-eglot-fields []
"tests for handling Eglot specially" "tests for handling Eglot specially"

View File

@ -1,6 +1,6 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(fn find [diagnostics e] (fn find [diagnostics e]
"returns the index of the diagnostic that matches `e`" "returns the index of the diagnostic that matches `e`"
@ -21,7 +21,7 @@
i))) i)))
(fn check [file-contents expected unexpected] (fn check [file-contents expected unexpected]
(let [{: diagnostics} (create-client-with-files file-contents)] (let [{: diagnostics} (create-client file-contents)]
(each [_ e (ipairs unexpected)] (each [_ e (ipairs unexpected)]
(let [i (find diagnostics e)] (let [i (find diagnostics e)]
(faith.= nil i (.. "Lint matching " (view e) "\n" (faith.= nil i (.. "Lint matching " (view e) "\n"

View File

@ -1,10 +1,10 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local {: null} (require :dkjson)) (local {: null} (require :dkjson))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(fn check [file-contents] (fn check [file-contents]
(let [{: client : uri : cursor :locations [location]} (create-client-with-files file-contents) (let [{: client : uri : cursor :locations [location]} (create-client file-contents)
[message] (client:definition uri cursor)] [message] (client:definition uri cursor)]
(if location (if location
(faith.= location message.result (faith.= location message.result

View File

@ -1,10 +1,10 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local {: null} (require :dkjson)) (local {: null} (require :dkjson))
(fn check [file-contents ?response-string] (fn check [file-contents ?response-string]
(let [{: client : uri : cursor} (create-client-with-files file-contents) (let [{: client : uri : cursor} (create-client file-contents)
[message] (client:hover uri cursor)] [message] (client:hover uri cursor)]
(if (= (type ?response-string) :string) (if (= (type ?response-string) :string)
(faith.= ?response-string (?. message :result :contents :value) (faith.= ?response-string (?. message :result :contents :value)

View File

@ -1,6 +1,6 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(fn find [diagnostics e] (fn find [diagnostics e]
"returns the index of the diagnostic " "returns the index of the diagnostic "
@ -21,7 +21,7 @@
i))) i)))
(fn check [file-contents expected unexpected] (fn check [file-contents expected unexpected]
(let [{: diagnostics} (create-client-with-files file-contents)] (let [{: diagnostics} (create-client file-contents)]
(each [_ e (ipairs unexpected)] (each [_ e (ipairs unexpected)]
(let [i (find diagnostics e)] (let [i (find diagnostics e)]
(faith.= nil i (.. "Lint matching " (view e) "\n" (faith.= nil i (.. "Lint matching " (view e) "\n"

View File

@ -1,6 +1,6 @@
(local faith (require :faith)) (local faith (require :faith))
(local fennel (require :fennel)) (local fennel (require :fennel))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local analyzer (require :fennel-ls.analyzer)) (local analyzer (require :fennel-ls.analyzer))
(local utils (require :fennel-ls.utils)) (local utils (require :fennel-ls.utils))
@ -16,7 +16,7 @@
nil) nil)
(fn test-find-symbol [] (fn test-find-symbol []
(let [{: server : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)") (let [{: server : uri} (create-client "(match [1 2 4] [1 2 sym-one] sym-one)")
file (. server.files uri) file (. server.files uri)
(symbol parents) (analyzer.find-symbol file.ast 23)] (symbol parents) (analyzer.find-symbol file.ast 23)]
(faith.= symbol (fennel.sym :sym-one)) (faith.= symbol (fennel.sym :sym-one))
@ -25,7 +25,7 @@
(fennel.view parents {:one-line? true}) (fennel.view parents {:one-line? true})
"bad parents")) "bad parents"))
(let [{: server : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)") (let [{: server : uri} (create-client "(match [1 2 4] [1 2 sym-one] sym-one)")
file (. server.files uri) file (. server.files uri)
(symbol parents) (analyzer.find-symbol file.ast 18)] (symbol parents) (analyzer.find-symbol file.ast 18)]
(faith.= symbol nil) (faith.= symbol nil)
@ -36,11 +36,11 @@
nil) nil)
(fn test-failure [] (fn test-failure []
(create-client-with-files "(macro foo {} nil) (create-client "(macro foo {} nil)
(λ test {} nil) (λ test {} nil)
(λ {} nil") (λ {} nil")
(create-client-with-files "(fn foo []\n #\n (print :test))") (create-client "(fn foo []\n #\n (print :test))")
(create-client-with-files "(let [map {}] (set (. map (tostring :a)) :b))") (create-client "(let [map {}] (set (. map (tostring :a)) :b))")
nil) nil)
(fn test-split-spaces [] (fn test-split-spaces []

View File

@ -1,5 +1,5 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local {: null} (require :dkjson)) (local {: null} (require :dkjson))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
@ -16,7 +16,7 @@
(= a.range.end.character b.range.end.character))))))))))) (= a.range.end.character b.range.end.character)))))))))))
(fn check [file-contents] (fn check [file-contents]
(let [{: client : uri : cursor : locations} (create-client-with-files file-contents) (let [{: client : uri : cursor : locations} (create-client file-contents)
[response] (client:references uri cursor)] [response] (client:references uri cursor)]
(if (not= null response.result) (if (not= null response.result)
(do (do

View File

@ -1,10 +1,10 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: create-client-with-files} (require :test.utils)) (local {: create-client} (require :test.utils))
(local {: null} (require :dkjson)) (local {: null} (require :dkjson))
(local {: apply-edits} (require :fennel-ls.utils)) (local {: apply-edits} (require :fennel-ls.utils))
(fn check [file-content new-name expected-file-content] (fn check [file-content new-name expected-file-content]
(let [{: client : uri : cursor : text : encoding} (create-client-with-files file-content) (let [{: client : uri : cursor : text : encoding} (create-client file-content)
[{: result}] (client:rename uri cursor new-name)] [{: result}] (client:rename uri cursor new-name)]
(if (= null result) (if (= null result)
(faith.= expected-file-content text) (faith.= expected-file-content text)

View File

@ -1,11 +1,9 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: ROOT-URI (local {: create-client} (require :test.utils))
: ROOT-PATH} (require :test.utils.client))
(local {: create-client-with-files} (require :test.utils))
(fn test-path [] (fn test-path []
(let [{: client : uri : cursor :locations [location]} (let [{: client : uri : cursor :locations [location]}
(create-client-with-files (create-client
{:modname.fnl "{:this-is-in-modname {:this :one :isnt :on :the :path}}" {:modname.fnl "{:this-is-in-modname {:this :one :isnt :on :the :path}}"
:modname/modname/modname/modname.fnl "(fn ==this-is-in-modname== [] nil) {: this-is-in-modname}" :modname/modname/modname/modname.fnl "(fn ==this-is-in-modname== [] nil) {: this-is-in-modname}"
:main.fnl "(local {: this-is-in-mod|name} (require :modname))"} :main.fnl "(local {: this-is-in-mod|name} (require :modname))"}
@ -17,7 +15,7 @@
;; TODO fix macros to use a custom searcher ;; TODO fix macros to use a custom searcher
; (let [{: diagnostics} ; (let [{: diagnostics}
; (create-client-with-files ; (create-client
; {:modname.fnl "{:this-is-in-modname {:this :one :isnt :on :the :path}}" ; {:modname.fnl "{:this-is-in-modname {:this :one :isnt :on :the :path}}"
; :modname/modname/modname/modname.fnl "(fn this-is-in-modname [] nil) {: this-is-in-modname}" ; :modname/modname/modname/modname.fnl "(fn this-is-in-modname [] nil) {: this-is-in-modname}"
; :main.fnl "(import-macros {: this-is-in-modname} :modname) ; :main.fnl "(import-macros {: this-is-in-modname} :modname)
@ -32,8 +30,8 @@
;; (local client (doto [] ({:settings {:fennel-ls {:fennel-path "./?/?/?/?.fnl"}})))) ;; (local client (doto [] ({:settings {:fennel-ls {:fennel-path "./?/?/?/?.fnl"}}))))
(fn test-extra-globals [] (fn test-extra-globals []
(let [{:diagnostics good} (create-client-with-files "(foo-100 bar :baz)" {:settings {:fennel-ls {:extra-globals "foo-100 bar"}}}) (let [{:diagnostics good} (create-client "(foo-100 bar :baz)" {:settings {:fennel-ls {:extra-globals "foo-100 bar"}}})
{:diagnostics bad} (create-client-with-files "(foo-100 bar :baz)")] {:diagnostics bad} (create-client "(foo-100 bar :baz)")]
(faith.= [] good) (faith.= [] good)
(faith.not= [] bad)) (faith.not= [] bad))
nil) nil)
@ -45,26 +43,22 @@
;; (local client (doto [] (setup-server {:fennel-ls {:diagnostics {:E202 "warning"}}}))))) ;; (local client (doto [] (setup-server {:fennel-ls {:diagnostics {:E202 "warning"}}})))))
(fn test-lints [] (fn test-lints []
(let [{:diagnostics good} (create-client-with-files "(local x 10)" {:settings {:fennel-ls {:checks {:unused-definition false}}}}) (let [{:diagnostics good} (create-client "(local x 10)" {:settings {:fennel-ls {:checks {:unused-definition false}}}})
{:diagnostics bad} (create-client-with-files "(local x 10)")] {:diagnostics bad} (create-client "(local x 10)")]
(faith.= [] good) (faith.= [] good)
(faith.not= [] bad)) (faith.not= [] bad))
nil) nil)
(fn test-initialization-options [] (fn test-initialization-options []
(let [initializationOptions {:fennel-ls {:checks {:unused-definition false}}} (let [initialization-options {:fennel-ls {:checks {:unused-definition false}}}
{: diagnostics} (create-client-with-files "(local x 10)" {:params {: initializationOptions {: diagnostics} (create-client "(local x 10)" {: initialization-options})]
:rootPath ROOT-PATH
:rootUri ROOT-URI
:workspaceFolders [{:name ROOT-PATH
:uri ROOT-URI}]}})]
(faith.= [] diagnostics)) (faith.= [] diagnostics))
nil) nil)
(fn test-native-libaries [] (fn test-native-libaries []
(let [{:diagnostics bad} (create-client-with-files "(print btn)" (let [{:diagnostics bad} (create-client "(print btn)"
{:settings {}}) {:settings {}})
{:diagnostics good} (create-client-with-files "(print btn)" {:diagnostics good} (create-client "(print btn)"
{:settings {:fennel-ls {:native-libraries [:tic80]}}})] {:settings {:fennel-ls {:native-libraries [:tic80]}}})]
(faith.not= [] bad) (faith.not= [] bad)
(faith.= [] good))) (faith.= [] good)))

View File

@ -12,34 +12,6 @@
(local default-encoding :utf-8) (local default-encoding :utf-8)
(local mt {})
(fn create-client [?opts ?provide-root-uri]
(let [server []
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}
initialize-response (dispatch.handle* server initialize)
client (doto {: server :prev-id 1} (setmetatable mt))]
(case (?. ?opts :settings)
settings
(dispatch.handle* server
{:jsonrpc "2.0"
:method :workspace/didChangeConfiguration
:params {: settings}}))
(values client server initialize-response)))
(fn next-id! [self] (fn next-id! [self]
(set self.prev-id (+ self.prev-id 1)) (set self.prev-id (+ self.prev-id 1))
self.prev-id) self.prev-id)
@ -53,6 +25,11 @@
:version 1 :version 1
: text}}))) : text}})))
(fn did-change-configuration [self settings]
(dispatch.handle* self.server
(message.create-notification :workspace/didChangeConfiguration
{: settings})))
(fn pretend-this-file-exists! [self name text] (fn pretend-this-file-exists! [self name text]
(tset self.server.preload name text)) (tset self.server.preload name text))
@ -95,17 +72,18 @@
:textDocument {:uri file} :textDocument {:uri file}
:context {:diagnostics []}}))) :context {:diagnostics []}})))
(set mt.__index (local client-mt
{: open-file! {:__index {: open-file!
: pretend-this-file-exists! : pretend-this-file-exists!
: did-change-configuration
: completion : completion
: definition : definition
: hover : hover
: references : references
: rename : rename
: code-action}) : code-action}})
{: create-client {: client-mt
: default-encoding : default-encoding
: ROOT-URI : ROOT-URI
: ROOT-PATH} : ROOT-PATH}

View File

@ -1,9 +1,17 @@
(local {: ROOT-URI (local {: ROOT-URI
: create-client : ROOT-PATH
: client-mt
: default-encoding} (require :test.utils.client)) : default-encoding} (require :test.utils.client))
(local utils (require :fennel-ls.utils))
(fn get-markup [text ?encoding] (local utils (require :fennel-ls.utils))
(local dispatch (require :fennel-ls.dispatch))
(local NIL {})
(fn un-nil [arg]
(if (not= arg NIL)
arg))
(fn parse-markup [text ?encoding]
"find the | character, which represents the cursor position" "find the | character, which represents the cursor position"
(var text text) (var text text)
(let [result {:ranges []} (let [result {:ranges []}
@ -33,25 +41,49 @@
(set result.text text) (set result.text text)
result)) result))
(fn create-client-with-files [file-contents ?client-options] (fn create-client [file-contents ?opts]
(let [(?give-a-root-uri file-contents) (if (= (type file-contents) :string) ;; TODO big function, split up
(values nil {:main.fnl file-contents}) (let [opts (or ?opts {})
(values true file-contents)) (provide-root-uri file-contents) (if (= (type file-contents) :table)
(client server) (create-client ?client-options ?give-a-root-uri) (values true file-contents)
(values false {:main.fnl file-contents}))
server {:preload (if provide-root-uri {})}
client (doto {: server :prev-id 1}
(setmetatable client-mt))
locations []] locations []]
(each [name marked (pairs file-contents)] ;; NOT main.fnl
(each [name contents (pairs file-contents)]
(if (not= name :main.fnl) (if (not= name :main.fnl)
(let [uri (.. ROOT-URI "/" name) (let [uri (.. ROOT-URI "/" name)
{: text : ranges} (get-markup marked)] {: text : ranges} (parse-markup contents opts.markup-encoding)]
(icollect [_ range (ipairs ranges) &into locations] (icollect [_ range (ipairs ranges) &into locations]
{: range : uri}) {: range : uri})
(client:pretend-this-file-exists! uri text)))) (client:pretend-this-file-exists! uri text))))
;; main.fnl
(let [uri (.. ROOT-URI "/" :main.fnl) (let [uri (.. ROOT-URI "/" :main.fnl)
main-file-contents (. file-contents :main.fnl) main-file-contents (. file-contents :main.fnl)
{: text : ranges : cursor} (get-markup main-file-contents)] {: text : ranges : cursor} (parse-markup main-file-contents opts.markup-encoding)
(icollect [_ range (ipairs ranges) &into locations] _ (icollect [_ range (ipairs ranges) &into locations]
{: range : uri}) {: range : uri})
(let [[{:params {: diagnostics}}] (client:open-file! uri text)]
params {:capabilities {:general {:positionEncodings (un-nil (or opts.position-encodings [default-encoding]))}}
:clientInfo (un-nil (or opts.client-info {:name "Neovim" :version "0.7.2"}))
:initializationOptions opts.initialization-options
: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-response (dispatch.handle* server
{:id 1
:jsonrpc "2.0"
:method "initialize"
: params})
_ (when opts.settings
(client:did-change-configuration opts.settings))
[{:params {: diagnostics}}] (client:open-file! uri text)]
{: client {: client
: server : server
: diagnostics : diagnostics
@ -59,11 +91,13 @@
: locations : locations
: text : text
: uri : uri
:encoding server.position-encoding})))) : initialize-response
:encoding server.position-encoding})))
(fn position-past-end-of-text [text ?encoding] (fn position-past-end-of-text [text ?encoding]
(utils.byte->position text (+ (length text) 1) (or ?encoding default-encoding))) (utils.byte->position text (+ (length text) 1) (or ?encoding default-encoding)))
{: create-client-with-files {: create-client
: position-past-end-of-text : position-past-end-of-text
: get-markup} : parse-markup
: NIL}