switch more "match" to "case"
This commit is contained in:
parent
5329f58672
commit
95245726e1
@ -13,9 +13,9 @@ In general, this involves:
|
||||
(λ handle-request [self send id method ?params]
|
||||
;; Call the appropriate request handler.
|
||||
;; The return value of the request is sent back to the server.
|
||||
(match (. handlers.requests method)
|
||||
(case (. handlers.requests method)
|
||||
callback
|
||||
(match (callback self send ?params)
|
||||
(case (callback self send ?params)
|
||||
(nil err) (send (message.create-error :InternalError err id))
|
||||
?response (send (message.create-response id ?response)))
|
||||
nil
|
||||
@ -35,7 +35,7 @@ In general, this involves:
|
||||
|
||||
(λ handle-notification [self send method ?params]
|
||||
;; Call the appropriate notification handler.
|
||||
(match (. handlers.notifications method)
|
||||
(case (. handlers.notifications method)
|
||||
callback (callback self send ?params)))
|
||||
;; Silent error for unknown notifications
|
||||
|
||||
@ -48,7 +48,7 @@ Takes:
|
||||
* `self`, which is the state of the server,
|
||||
* `send`, which is a callback for sending responses, and
|
||||
* `msg`, which is the message to receive."
|
||||
(match (values msg (type msg))
|
||||
(case (values msg (type msg))
|
||||
{:jsonrpc "2.0" : id : method :params ?params}
|
||||
(handle-request self send id method ?params)
|
||||
{:jsonrpc "2.0" : method :params ?params}
|
||||
|
||||
@ -16,7 +16,7 @@ Luckily, I'm testing with Neovim, so I can pretend these problems don't exist fo
|
||||
(λ read-header [in ?header]
|
||||
"Reads the header of a JSON-RPC message"
|
||||
(let [header (or ?header {})]
|
||||
(match (in:read)
|
||||
(case (in:read)
|
||||
"\r" header ;; hit an empty line, I'm done reading
|
||||
nil nil ;; hit end of stream, return nil
|
||||
;; reading an actual line
|
||||
@ -33,7 +33,7 @@ If there aren't enough bytes, return nil"
|
||||
(local buffer (or ?buffer []))
|
||||
(if (<= len 0)
|
||||
(table.concat buffer)
|
||||
(match (in:read len)
|
||||
(case (in:read len)
|
||||
content
|
||||
(read-n in
|
||||
(- len (length content))
|
||||
@ -52,7 +52,6 @@ Returns a table with the message if it succeeded, or a string with the parse err
|
||||
(pcall decode))]
|
||||
result))
|
||||
|
||||
|
||||
(λ write [out msg]
|
||||
"Serializes and writes a JSON-RPC message to the given output stream"
|
||||
(let [content (encode msg)
|
||||
|
||||
@ -57,8 +57,8 @@ to look to fix this in the future."
|
||||
:end {:line el :character ec}})
|
||||
|
||||
(λ ast->range [?ast file]
|
||||
(match (values (utils.get-ast-info ?ast :bytestart)
|
||||
(utils.get-ast-info ?ast :byteend))
|
||||
(case (values (utils.get-ast-info ?ast :bytestart)
|
||||
(utils.get-ast-info ?ast :byteend))
|
||||
(i j)
|
||||
(let [(start-line start-col) (utils.byte->pos file.text i)
|
||||
(end-line end-col) (utils.byte->pos file.text (+ j 1))]
|
||||
@ -66,7 +66,7 @@ to look to fix this in the future."
|
||||
|
||||
(λ range-and-uri [?ast {: uri &as file}]
|
||||
"if possible, returns the location of a symbol"
|
||||
(match (ast->range ?ast file)
|
||||
(case (ast->range ?ast file)
|
||||
range {: range : uri}))
|
||||
|
||||
(λ log [msg]
|
||||
|
||||
@ -36,8 +36,8 @@ I suspect this file may be gone after a bit of refactoring."
|
||||
(table.concat result ";")))
|
||||
|
||||
(λ lookup [{:configuration {: fennel-path} : root-uri} mod]
|
||||
(match (or ;; TODO support lua ;; (fennel.searchModule mod (add-workspaces-to-path luapath [root-uri]))
|
||||
(fennel.searchModule mod (add-workspaces-to-path fennel-path [root-uri])))
|
||||
(case (or ;; TODO support lua ;; (fennel.searchModule mod (add-workspaces-to-path luapath [root-uri]))
|
||||
(fennel.searchModule mod (add-workspaces-to-path fennel-path [root-uri])))
|
||||
modname (utils.path->uri modname)
|
||||
nil nil))
|
||||
|
||||
|
||||
@ -22,19 +22,9 @@
|
||||
(set o16 (+ o16 a16))))
|
||||
(if (= o8 unit8)
|
||||
o16
|
||||
(error :utf8-error)))
|
||||
(error :utf8-error))))
|
||||
|
||||
|
||||
(let [byte (or ?byte (length str))
|
||||
substr (str:sub 1 byte)]
|
||||
(accumulate
|
||||
[total (accumulate
|
||||
[total byte
|
||||
_ (substr:gmatch "[\192-\223]")]
|
||||
(- total 1))
|
||||
_ (substr:gmatch "[\224-\247]")]
|
||||
(- total 2))))
|
||||
|
||||
(fn unit16->byte [str unit16]
|
||||
"convert from utf16 garbage to normal units"
|
||||
(var o8 0)
|
||||
|
||||
@ -20,7 +20,7 @@ These functions are all pure functions, which makes me happy."
|
||||
(λ next-line [str ?from]
|
||||
"Find the start of the next line from a given byte offset, or from the start of the string."
|
||||
(let [from (or ?from 1)]
|
||||
(match (str:find "[\r\n]" from)
|
||||
(case (str:find "[\r\n]" from)
|
||||
i (+ i (length (str:match "\r?\n?" i)))
|
||||
nil nil)))
|
||||
|
||||
@ -59,14 +59,12 @@ These functions are all pure functions, which makes me happy."
|
||||
(accumulate
|
||||
[contents initial-text
|
||||
_ change (ipairs contentChanges)]
|
||||
(match change
|
||||
(case change
|
||||
;; Handle a change
|
||||
{:range {: start : end} : text}
|
||||
(replace contents
|
||||
start.line
|
||||
start.character
|
||||
end.line
|
||||
end.character
|
||||
start.line start.character
|
||||
end.line end.character
|
||||
text)
|
||||
;; A replacment of the entire body
|
||||
{: text}
|
||||
|
||||
@ -11,13 +11,6 @@
|
||||
;; test for multiline edits
|
||||
;; test for unicode utf8 utf16 nightmare
|
||||
|
||||
;; (it "can handle unicode"
|
||||
;; (utils.apply-changes ""
|
||||
;; [{:range (range 0 0 0 0) :text "どれみふぁそらてぃど")
|
||||
;; (document.replace my-document 0 1 0 3 "😀")
|
||||
;; (document.replace my-document 0 11 0 11 "end")
|
||||
;; (is-matching my-document {:text "ど😀ふぁそらてぃどend"})))
|
||||
|
||||
(describe "apply-changes"
|
||||
|
||||
(fn range [start-line start-col end-line end-col]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user