Rename self->client in tests

This commit is contained in:
XeroOl 2024-06-01 23:12:42 -05:00
parent 0b3d1b47a5
commit 9770e3eefd
11 changed files with 41 additions and 41 deletions

View File

@ -13,21 +13,21 @@
:trace "off"}) :trace "off"})
(fn test-offset-encoding [] (fn test-offset-encoding []
(let [(self [response]) (let [(client [response])
(create-client {:params (params-with-encodings [:utf-16])}) (create-client {:params (params-with-encodings [:utf-16])})
_ (faith.= :utf-16 (. response :result :capabilities :positionEncoding)) _ (faith.= :utf-16 (. response :result :capabilities :positionEncoding))
{: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-16) {: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-16)
_ (self:open-file! "foo.fnl" text) _ (client:open-file! "foo.fnl" text)
[response] (self:definition "foo.fnl" cursor)] [response] (client:definition "foo.fnl" cursor)]
(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 [(self [response]) (let [(client [response])
(create-client {:params (params-with-encodings [:utf-16 :utf-8])}) (create-client {:params (params-with-encodings [:utf-16 :utf-8])})
_ (faith.= :utf-8 (. response :result :capabilities :positionEncoding)) _ (faith.= :utf-8 (. response :result :capabilities :positionEncoding))
{: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-8) {: text : cursor :ranges [{: start : end}]} (get-markup "(let [==𐐀𐐀== 100] 𐐀𐐀|)" :utf-8)
_ (self:open-file! "foo.fnl" text) _ (client:open-file! "foo.fnl" text)
[response] (self:definition "foo.fnl" cursor)] [response] (client:definition "foo.fnl" cursor)]
(faith.= start response.result.range.start) (faith.= start response.result.range.start)
(faith.= end response.result.range.end)) (faith.= end response.result.range.end))

View File

@ -6,8 +6,8 @@
(create-client-with-files "(print :hi)") (create-client-with-files "(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 [{: self : uri :locations [range] : encoding : text} (create-client-with-files file-contents) (let [{: client : uri :locations [range] : encoding : text} (create-client-with-files file-contents)
[{:result responses}] (self: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]
(if (= action.title action-I-want-to-take) (if (= action.title action-I-want-to-take)
@ -21,8 +21,8 @@
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 [{: self : uri :locations [range]} (create-client-with-files file-contents) (let [{: client : uri :locations [range]} (create-client-with-files file-contents)
[{:result responses}] (self: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)
(.. "I found your action \"" action-not-suggested "\" in:\n" (.. "I found your action \"" action-not-suggested "\" in:\n"
@ -39,10 +39,10 @@
; (fn test-fix-method-function [] ; (fn test-fix-method-function []
; (check "(local x {}) ; (check "(local x {})
; (fn x:y [a b c] ; (fn x:y [a b c]
; (print self a b c))" ; (print client a b c))"
; "TO-BE-NAMED" ; "TO-BE-NAMED"
; "(local x {}) ; "(local x {})
; (fn x.y [self a b c] ; (fn x.y [client a b c]
; (print self a b c))")) ; (print client a b c))"))
{: test-fix-op-no-arguments} {: test-fix-op-no-arguments}

View File

@ -43,8 +43,8 @@
i))) i)))
(fn check [file-contents expected unexpected ?client-options] (fn check [file-contents expected unexpected ?client-options]
(let [{: self : uri : cursor : text} (create-client-with-files file-contents ?client-options) (let [{: client : uri : cursor : text} (create-client-with-files file-contents ?client-options)
[{:result ?result}] (self:completion uri [{:result ?result}] (client:completion uri
(or cursor (or cursor
(position-past-end-of-text text))) (position-past-end-of-text text)))
completions (or ?result [])] completions (or ?result [])]

View File

@ -4,8 +4,8 @@
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(fn check [file-contents] (fn check [file-contents]
(let [{: self : uri : cursor :locations [location]} (create-client-with-files file-contents) (let [{: client : uri : cursor :locations [location]} (create-client-with-files file-contents)
[message] (self:definition uri cursor)] [message] (client:definition uri cursor)]
(if location (if location
(faith.= location message.result (faith.= location message.result
(.. "Didn't go to location: \n" (view file-contents))) (.. "Didn't go to location: \n" (view file-contents)))

View File

@ -4,8 +4,8 @@
(local {: null} (require :fennel-ls.json.json)) (local {: null} (require :fennel-ls.json.json))
(fn check [file-contents ?response-string] (fn check [file-contents ?response-string]
(let [{: self : uri : cursor} (create-client-with-files file-contents) (let [{: client : uri : cursor} (create-client-with-files file-contents)
[message] (self: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)
(.. "Invalid hover message\nfrom: " (view file-contents))) (.. "Invalid hover message\nfrom: " (view file-contents)))

View File

@ -16,8 +16,8 @@
nil) nil)
(fn test-find-symbol [] (fn test-find-symbol []
(let [{: self : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)") (let [{: client : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)")
file (. self.server.files uri) file (. client.server.files uri)
(symbol parents) (language.find-symbol file.ast 23)] (symbol parents) (language.find-symbol file.ast 23)]
(faith.= symbol (fennel.sym :sym-one)) (faith.= symbol (fennel.sym :sym-one))
(faith.= (faith.=
@ -25,8 +25,8 @@
(fennel.view parents {:one-line? true}) (fennel.view parents {:one-line? true})
"bad parents")) "bad parents"))
(let [{: self : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)") (let [{: client : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)")
file (. self.server.files uri) file (. client.server.files uri)
(symbol parents) (language.find-symbol file.ast 18)] (symbol parents) (language.find-symbol file.ast 18)]
(faith.= symbol nil) (faith.= symbol nil)
(faith.= (faith.=

View File

@ -16,8 +16,8 @@
(= 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 [{: self : uri : cursor : locations} (create-client-with-files file-contents) (let [{: client : uri : cursor : locations} (create-client-with-files file-contents)
[response] (self:references uri cursor)] [response] (client:references uri cursor)]
(if (not= null response.result) (if (not= null response.result)
(do (do
(table.sort locations location-comparator) (table.sort locations location-comparator)

View File

@ -4,8 +4,8 @@
(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 [{: self : uri : cursor : text : encoding} (create-client-with-files file-content) (let [{: client : uri : cursor : text : encoding} (create-client-with-files file-content)
[{: result}] (self: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)
(let [new-content (apply-edits text (. result.changes uri) encoding)] (let [new-content (apply-edits text (. result.changes uri) encoding)]

View File

@ -4,14 +4,14 @@
(local {: create-client-with-files} (require :test.utils)) (local {: create-client-with-files} (require :test.utils))
(fn test-path [] (fn test-path []
(let [{: self : uri : cursor :locations [location]} (let [{: client : uri : cursor :locations [location]}
(create-client-with-files (create-client-with-files
{: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))"}
{:settings {:fennel-ls {:fennel-path "./?/?/?/?.fnl"}}}) {:settings {:fennel-ls {:fennel-path "./?/?/?/?.fnl"}}})
[response] (self:definition uri cursor)] [response] (client:definition uri cursor)]
(faith.= location response.result (faith.= location response.result
"error message"))) "error message")))
@ -29,7 +29,7 @@
;; (it "recompiles modules if the macro files are modified)" ;; (it "recompiles modules if the macro files are modified)"
;; (it "can infer the macro path from fennel-path" ;; (it "can infer the macro path from fennel-path"
;; (local self (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-with-files "(foo-100 bar :baz)" {:settings {:fennel-ls {:extra-globals "foo-100 bar"}}})
@ -39,10 +39,10 @@
nil) nil)
;; (it "can turn off strict globals" ;; (it "can turn off strict globals"
;; (local self (doto [] (setup-server {:fennel-ls {:checks {:globals false}}})))) ;; (local client (doto [] (setup-server {:fennel-ls {:checks {:globals false}}}))))
;; (it "can treat globals as a warning instead of an error" ;; (it "can treat globals as a warning instead of an error"
;; (local self (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-with-files "(local x 10)" {:settings {:fennel-ls {:checks {:unused-definition false}}}})

View File

@ -14,7 +14,7 @@
(local mt {}) (local mt {})
(fn create-client [?opts ?provide-root-uri] (fn create-client [?opts ?provide-root-uri]
(let [self (doto {:server [] :prev-id 1} (setmetatable mt)) (let [client (doto {:server [] :prev-id 1} (setmetatable mt))
params (or (?. ?opts :params) params (or (?. ?opts :params)
{:capabilities {:general {:positionEncodings [default-encoding]}} {:capabilities {:general {:positionEncodings [default-encoding]}}
:clientInfo {:name "Neovim" :version "0.7.2"} :clientInfo {:name "Neovim" :version "0.7.2"}
@ -30,14 +30,14 @@
:jsonrpc "2.0" :jsonrpc "2.0"
:method "initialize" :method "initialize"
: params} : params}
result (dispatch.handle* self.server initialize)] result (dispatch.handle* client.server initialize)]
(case (?. ?opts :settings) (case (?. ?opts :settings)
settings settings
(dispatch.handle* self.server (dispatch.handle* client.server
{:jsonrpc "2.0" {:jsonrpc "2.0"
:method :workspace/didChangeConfiguration :method :workspace/didChangeConfiguration
:params {: settings}})) :params {: settings}}))
(values self result))) (values client result)))
(fn next-id! [self] (fn next-id! [self]
(set self.prev-id (+ self.prev-id 1)) (set self.prev-id (+ self.prev-id 1))

View File

@ -37,7 +37,7 @@
(let [(?give-a-root-uri file-contents) (if (= (type file-contents) :string) (let [(?give-a-root-uri file-contents) (if (= (type file-contents) :string)
(values nil {:main.fnl file-contents}) (values nil {:main.fnl file-contents})
(values true file-contents)) (values true file-contents))
self (create-client ?client-options ?give-a-root-uri) client (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)
@ -45,20 +45,20 @@
{: text : ranges} (get-markup marked)] {: text : ranges} (get-markup marked)]
(icollect [_ range (ipairs ranges) &into locations] (icollect [_ range (ipairs ranges) &into locations]
{: range : uri}) {: range : uri})
(self:pretend-this-file-exists! uri text)))) (client:pretend-this-file-exists! uri text))))
(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} (get-markup main-file-contents)]
(icollect [_ range (ipairs ranges) &into locations] (icollect [_ range (ipairs ranges) &into locations]
{: range : uri}) {: range : uri})
(let [[{:params {: diagnostics}}] (self:open-file! uri text)] (let [[{:params {: diagnostics}}] (client:open-file! uri text)]
{: self {: client
: diagnostics : diagnostics
: cursor : cursor
: locations : locations
: text : text
: uri : uri
:encoding self.server.position-encoding})))) :encoding client.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)))