Skip to content

Commit 3f5ae8f

Browse files
committed
Move most logic to jsonrpc4clj
1 parent 4dd6d62 commit 3f5ae8f

21 files changed

+13
-2244
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Move most logic to jsonrpc4clj library.
6+
57
## v1.13.1
68

79
- Fix coercers

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
org.clojure/core.async {:mvn/version "1.5.648"}
33
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
44
cheshire/cheshire {:mvn/version "5.11.0"}
5-
funcool/promesa {:mvn/version "10.0.594"}}
5+
funcool/promesa {:mvn/version "10.0.594"}
6+
com.github.clojure-lsp/jsonrpc4clj {:mvn/version "1.0.1"}}
67
:paths ["src" "resources"]
78
:aliases {:dev {:extra-paths ["test"]}
89
:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.64.1010"}}

scripts/lsp4clj/ci.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(string/replace $ regex content)
99
(spit file $)))
1010

11-
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
11+
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
1212
(defn tag [& [tag]]
1313
(shell "git fetch origin")
1414
(shell "git pull origin HEAD")

src/lsp4clj/coercer.clj

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -479,51 +479,3 @@
479479
:server-capabilities/semantic-tokens-provider
480480
:server-capabilities/signature-help-provider
481481
:server-capabilities/text-document-sync]))
482-
483-
(s/def :json-rpc.message/jsonrpc #{"2.0"})
484-
(s/def :json-rpc.message/method string?)
485-
(s/def :json-rpc.message/id (s/and (s/or :s string? :i nat-int? :n nil?)
486-
(s/conformer second)))
487-
488-
(s/def ::json-rpc.request
489-
(s/keys :req-un [:json-rpc.message/jsonrpc
490-
:json-rpc.message/id
491-
:json-rpc.message/method]
492-
:opt-un [:json-rpc.message/params]))
493-
(s/def ::json-rpc.notification
494-
(s/keys :req-un [:json-rpc.message/jsonrpc
495-
:json-rpc.message/method]
496-
:opt-un [:json-rpc.message/params]))
497-
(s/def ::json-rpc.response.result
498-
(s/keys :req-un [:json-rpc.message/jsonrpc
499-
:json-rpc.message/id
500-
:json-rpc.message/result]))
501-
(s/def ::json-rpc.response.error
502-
(s/keys :req-un [:json-rpc.message/jsonrpc
503-
:json-rpc.message/id
504-
::error]))
505-
506-
(s/def ::json-rpc.input
507-
(s/or :request ::json-rpc.request
508-
:notification ::json-rpc.notification
509-
:response.result ::json-rpc.response.result
510-
:response.error ::json-rpc.response.error))
511-
512-
(defn input-message-type [message]
513-
(if (identical? :parse-error message)
514-
:parse-error
515-
(let [conformed-message (s/conform ::json-rpc.input message)]
516-
(if (identical? ::s/invalid conformed-message)
517-
:invalid-request
518-
(first conformed-message)))))
519-
520-
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
521-
(defn conform-or-log [log spec value]
522-
(when value
523-
(try
524-
(let [result (s/conform spec value)]
525-
(if (identical? ::s/invalid result)
526-
(log "Conformation error" (s/explain-data spec value))
527-
result))
528-
(catch Exception ex
529-
(log ex "Conformation exception" spec value)))))

src/lsp4clj/io_chan.clj

Lines changed: 0 additions & 137 deletions
This file was deleted.

src/lsp4clj/io_server.clj

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/lsp4clj/liveness_probe.clj

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/lsp4clj/lsp/errors.clj

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
(ns lsp4clj.lsp.errors)
1+
(ns lsp4clj.lsp.errors
2+
(:require
3+
[jsonrpc4clj.errors :as errors]))
24

35
(set! *warn-on-reflection* true)
46

57
(def by-key
68
;; https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#errorCodes
7-
{;; JSON-RPC errors
8-
;; Is it possible to respond if you have a parse error? How could you reply
9-
;; to a request if you weren't able to parse it?
10-
:parse-error {:code -32700, :message "Parse error"}
11-
;; Similarly for invalid-request. How could you reply to a request if it
12-
;; doesn't look like a request?
13-
:invalid-request {:code -32600, :message "Invalid Request"}
14-
:method-not-found {:code -32601, :message "Method not found"}
15-
:invalid-params {:code -32602, :message "Invalid params"}
16-
:internal-error {:code -32603, :message "Internal error"}
17-
18-
;; LSP errors
9+
{;; LSP errors
1910
:server-not-initialized {:code -32002, :message "Server not initialized"}
2011
:unknown-error-code {:code -32001, :message "Unknown error"}
2112
:request-failed {:code -32803, :message "Request failed"}
@@ -33,7 +24,8 @@
3324
be an integer, excluding the ranges -32000 to -32099 and -32800 to -32899,
3425
which are reserved."
3526
[code-or-key]
36-
(or (get by-key code-or-key)
27+
(or (get errors/by-key code-or-key)
28+
(get by-key code-or-key)
3729
{:code code-or-key}))
3830

3931
(defn body
@@ -45,11 +37,3 @@
4537
(cond-> (by-code code)
4638
message (assoc :message message)
4739
data (assoc :data data)))
48-
49-
(defn internal-error [data]
50-
(-> (by-code :internal-error)
51-
(assoc :data data)))
52-
53-
(defn not-found [method]
54-
(-> (by-code :method-not-found)
55-
(assoc :data {:method method})))

src/lsp4clj/lsp/requests.clj

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,10 @@
22

33
(set! *warn-on-reflection* true)
44

5-
(defn request [id method params]
6-
{:jsonrpc "2.0"
7-
:method method
8-
:params params
9-
:id id})
10-
11-
(defn notification [method params]
12-
{:jsonrpc "2.0"
13-
:method method
14-
:params params})
15-
16-
;; TODO: The following are helpers used by servers, but not by lsp4clj itself.
17-
;; Perhaps they belong in a utils namespace.
18-
19-
(defn clamp [n n-min n-max]
5+
(defn ^:private clamp [n n-min n-max]
206
(-> n (max n-min) (min n-max)))
217

22-
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
8+
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
239
(defn work-done-progress
2410
"Returns the params for a WorkDone $/progress notification.
2511

0 commit comments

Comments
 (0)