Skip to content

Commit 5d263fa

Browse files
committed
Use jsonrpc4clj instead of lsp4clj.
1 parent 2b9bdcf commit 5d263fa

File tree

7 files changed

+49
-48
lines changed

7 files changed

+49
-48
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+
- Use jsonrpc4clj instead of lsp4clj.
6+
57
## 0.54.3
68

79
- Avoid errors on multiple same MCP server calls in parallel.

bb.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:deps {borkdude/gh-release-artifact {:git/url "https://github.com/borkdude/gh-release-artifact"
33
:git/sha "4a9a74f0e50e897c45df8cc70684360eb30fce80"}
44
nubank/matcher-combinators {:mvn/version "3.9.1"}
5-
com.github.clojure-lsp/lsp4clj {:mvn/version "1.13.1"}
5+
com.github.clojure-lsp/jsonrpc4clj {:mvn/version "1.0.2"}
66
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
77
:git/sha "b6eb0f2208ab036c0a5d0e7235cb0b09d2feabb7"}}
88
:min-bb-version "0.8.156"

deps-lock.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,14 @@
581581
"hash": "sha256-LJtr0GODzbfGpqiiuZTVljWvRy9fmKb5XdFD9gFyG+M="
582582
},
583583
{
584-
"mvn-path": "com/github/clojure-lsp/lsp4clj/1.13.1/lsp4clj-1.13.1.jar",
584+
"mvn-path": "com/github/clojure-lsp/jsonrpc4clj/1.0.2/jsonrpc4clj-1.0.2.jar",
585585
"mvn-repo": "https://repo.clojars.org/",
586-
"hash": "sha256-mTdYK2aauuY1ZIfENWiReUEHCrTzhrnwwG/5OhbQ9oI="
586+
"hash": "sha256-NFZy2vQz6tJWNC4ScwvO2vDnVx6USnQKODVqxB5AGgk="
587587
},
588588
{
589-
"mvn-path": "com/github/clojure-lsp/lsp4clj/1.13.1/lsp4clj-1.13.1.pom",
589+
"mvn-path": "com/github/clojure-lsp/jsonrpc4clj/1.0.2/jsonrpc4clj-1.0.2.pom",
590590
"mvn-repo": "https://repo.clojars.org/",
591-
"hash": "sha256-/OcjA/xV4B0mO/fVwKgDI8M1sQZSuH2bZ3da+/ME720="
591+
"hash": "sha256-8xL3N0pNBtDqUFrNCskBJiv4aHQSnFJyQ93H9Tj5plA="
592592
},
593593
{
594594
"mvn-path": "com/github/ericdallo/deps-bin/1.0.0/deps-bin-1.0.0.jar",

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
33
org.clojure/core.async {:mvn/version "1.8.741"}
44
org.babashka/cli {:mvn/version "0.8.65"}
5-
com.github.clojure-lsp/lsp4clj {:mvn/version "1.13.1"}
5+
com.github.clojure-lsp/jsonrpc4clj {:mvn/version "1.0.2"}
66
io.modelcontextprotocol.sdk/mcp {:mvn/version "0.12.1"}
77
borkdude/dynaload {:mvn/version "0.3.5"}
88
babashka/fs {:mvn/version "0.5.26"}

docs/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The ECA codebase follows a pragmatic **layered layout** that separates concerns
3636
──└─ `util.clj` | misc helpers shared by tools.
3737
`src/eca/messenger.clj` | To send back to client requests/notifications over stdio.
3838
`src/eca/handlers.clj` | Entrypoint for all features.
39-
`src/eca/server.clj` | stdio **entry point**; wires everything together via `lsp4clj`.
39+
`src/eca/server.clj` | stdio **entry point**; wires everything together via `jsonrpc4clj`.
4040
`src/eca/main.clj` | The CLI interface.
4141
`src/eca/nrepl.clj` | Starts an nREPL when `:debug` flag is passed.
4242

integration-test/integration/client.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
(:require
33
[clojure.core.async :as async]
44
[clojure.string :as string]
5-
[lsp4clj.coercer :as coercer]
6-
[lsp4clj.io-chan :as lsp.io-chan]
7-
[lsp4clj.lsp.requests :as lsp.requests]
8-
[lsp4clj.lsp.responses :as lsp.responses]
9-
[lsp4clj.protocols.endpoint :as protocols.endpoint])
5+
[jsonrpc4clj.coercer :as coercer]
6+
[jsonrpc4clj.io-chan :as jsonrpc.io-chan]
7+
[jsonrpc4clj.requests :as jsonrpc.requests]
8+
[jsonrpc4clj.responses :as jsonrpc.responses]
9+
[jsonrpc4clj.protocols.endpoint :as protocols.endpoint])
1010
(:import
1111
[java.time LocalDateTime]
1212
[java.time.format DateTimeFormatter]))
@@ -78,7 +78,6 @@
7878
(let [pipeline (async/pipeline-blocking
7979
1 ;; no parallelism preserves server message order
8080
output
81-
;; TODO: return error until initialize request is received? https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
8281
;; `keep` means we do not reply to responses and notifications
8382
(keep #(receive-message this context %))
8483
input)]
@@ -103,7 +102,7 @@
103102
(log [this color msg params]
104103
(async/put! log-ch (format-log this color msg params)))
105104
(send-request [this method body]
106-
(let [req (lsp.requests/request (swap! request-id inc) method body)
105+
(let [req (jsonrpc.requests/request (swap! request-id inc) method body)
107106
p (promise)
108107
start-ns (System/nanoTime)]
109108
(protocols.endpoint/log this :cyan "sending request:" req)
@@ -114,7 +113,7 @@
114113
(async/>!! output req)
115114
p))
116115
(send-notification [this method body]
117-
(let [notif (lsp.requests/notification method body)]
116+
(let [notif (jsonrpc.requests/notification method body)]
118117
(protocols.endpoint/log this :blue "sending notification:" notif)
119118
(async/>!! output notif)))
120119
(receive-response [this {:keys [id] :as resp}]
@@ -130,7 +129,7 @@
130129
(protocols.endpoint/log this :magenta "received request:" req)
131130
(swap! received-requests conj req)
132131
(when-let [mock-resp (get @mock-responses (keyword method))]
133-
(let [resp (lsp.responses/response id mock-resp)]
132+
(let [resp (jsonrpc.responses/response id mock-resp)]
134133
(protocols.endpoint/log this :magenta "sending mock response:" resp)
135134
resp)))
136135
(receive-notification [this _ notif]
@@ -147,8 +146,8 @@
147146
(defn client [server-in server-out]
148147
(map->Client
149148
{:client-id (swap! client-id inc)
150-
:input (lsp.io-chan/input-stream->input-chan server-out {:keyword-function keyword})
151-
:output (lsp.io-chan/output-stream->output-chan server-in)
149+
:input (jsonrpc.io-chan/input-stream->input-chan server-out {:keyword-function keyword})
150+
:output (jsonrpc.io-chan/output-stream->output-chan server-in)
152151
:log-ch (async/chan (async/sliding-buffer 20))
153152
:join (promise)
154153
:request-id (atom 0)

src/eca/server.clj

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[eca.messenger :as messenger]
99
[eca.nrepl :as nrepl]
1010
[eca.shared :as shared :refer [assoc-some]]
11-
[lsp4clj.io-server :as io-server]
12-
[lsp4clj.liveness-probe :as liveness-probe]
13-
[lsp4clj.server :as lsp.server]))
11+
[jsonrpc4clj.io-server :as io-server]
12+
[jsonrpc4clj.liveness-probe :as liveness-probe]
13+
[jsonrpc4clj.server :as jsonrpc.server]))
1414

1515
(set! *warn-on-reflection* true)
1616

@@ -21,55 +21,55 @@
2121
(defn ^:private exit [server]
2222
(logger/logging-task
2323
:eca/exit
24-
(lsp.server/shutdown server) ;; blocks, waiting up to 10s for previously received messages to be processed
24+
(jsonrpc.server/shutdown server) ;; blocks, waiting up to 10s for previously received messages to be processed
2525
(shutdown-agents)
2626
(System/exit 0)))
2727

2828
(defn ^:private with-config [components]
2929
(assoc components :config (config/all @(:db* components))))
3030

31-
(defmethod lsp.server/receive-request "initialize" [_ {:keys [server] :as components} params]
31+
(defmethod jsonrpc.server/receive-request "initialize" [_ {:keys [server] :as components} params]
3232
(when-let [parent-process-id (:process-id params)]
3333
(liveness-probe/start! parent-process-id log-wrapper-fn #(exit server)))
3434
(handlers/initialize components params))
3535

36-
(defmethod lsp.server/receive-notification "initialized" [_ components _params]
36+
(defmethod jsonrpc.server/receive-notification "initialized" [_ components _params]
3737
(handlers/initialized (with-config components)))
3838

39-
(defmethod lsp.server/receive-request "shutdown" [_ components _params]
39+
(defmethod jsonrpc.server/receive-request "shutdown" [_ components _params]
4040
(handlers/shutdown (with-config components)))
4141

42-
(defmethod lsp.server/receive-notification "exit" [_ {:keys [server]} _params]
42+
(defmethod jsonrpc.server/receive-notification "exit" [_ {:keys [server]} _params]
4343
(exit server))
4444

45-
(defmethod lsp.server/receive-request "chat/prompt" [_ components params]
45+
(defmethod jsonrpc.server/receive-request "chat/prompt" [_ components params]
4646
(handlers/chat-prompt (with-config components) params))
4747

48-
(defmethod lsp.server/receive-request "chat/queryContext" [_ components params]
48+
(defmethod jsonrpc.server/receive-request "chat/queryContext" [_ components params]
4949
(handlers/chat-query-context (with-config components) params))
5050

51-
(defmethod lsp.server/receive-request "chat/queryCommands" [_ components params]
51+
(defmethod jsonrpc.server/receive-request "chat/queryCommands" [_ components params]
5252
(handlers/chat-query-commands (with-config components) params))
5353

54-
(defmethod lsp.server/receive-notification "chat/toolCallApprove" [_ components params]
54+
(defmethod jsonrpc.server/receive-notification "chat/toolCallApprove" [_ components params]
5555
(handlers/chat-tool-call-approve (with-config components) params))
5656

57-
(defmethod lsp.server/receive-notification "chat/toolCallReject" [_ components params]
57+
(defmethod jsonrpc.server/receive-notification "chat/toolCallReject" [_ components params]
5858
(handlers/chat-tool-call-reject (with-config components) params))
5959

60-
(defmethod lsp.server/receive-notification "chat/promptStop" [_ components params]
60+
(defmethod jsonrpc.server/receive-notification "chat/promptStop" [_ components params]
6161
(handlers/chat-prompt-stop (with-config components) params))
6262

63-
(defmethod lsp.server/receive-request "chat/delete" [_ components params]
63+
(defmethod jsonrpc.server/receive-request "chat/delete" [_ components params]
6464
(handlers/chat-delete (with-config components) params))
6565

66-
(defmethod lsp.server/receive-notification "mcp/stopServer" [_ components params]
66+
(defmethod jsonrpc.server/receive-notification "mcp/stopServer" [_ components params]
6767
(handlers/mcp-stop-server (with-config components) params))
6868

69-
(defmethod lsp.server/receive-notification "mcp/startServer" [_ components params]
69+
(defmethod jsonrpc.server/receive-notification "mcp/startServer" [_ components params]
7070
(handlers/mcp-start-server (with-config components) params))
7171

72-
(defmethod lsp.server/receive-notification "chat/selectedBehaviorChanged" [_ components params]
72+
(defmethod jsonrpc.server/receive-notification "chat/selectedBehaviorChanged" [_ components params]
7373
(handlers/chat-selected-behavior-changed (with-config components) params))
7474

7575
(defn ^:private monitor-server-logs [log-ch]
@@ -99,20 +99,20 @@
9999
messenger/IMessenger
100100

101101
(chat-content-received [_this content]
102-
(lsp.server/discarding-stdout
103-
(lsp.server/send-notification server "chat/contentReceived" content)))
102+
(jsonrpc.server/discarding-stdout
103+
(jsonrpc.server/send-notification server "chat/contentReceived" content)))
104104
(config-updated [_this params]
105-
(lsp.server/discarding-stdout
106-
(lsp.server/send-notification server "config/updated" params)))
105+
(jsonrpc.server/discarding-stdout
106+
(jsonrpc.server/send-notification server "config/updated" params)))
107107
(tool-server-updated [_this params]
108-
(lsp.server/discarding-stdout
109-
(lsp.server/send-notification server "tool/serverUpdated" params)))
108+
(jsonrpc.server/discarding-stdout
109+
(jsonrpc.server/send-notification server "tool/serverUpdated" params)))
110110
(showMessage [_this msg]
111-
(lsp.server/discarding-stdout
112-
(lsp.server/send-notification server "$/showMessage" msg)))
111+
(jsonrpc.server/discarding-stdout
112+
(jsonrpc.server/send-notification server "$/showMessage" msg)))
113113
(editor-diagnostics [_this uri]
114-
(lsp.server/discarding-stdout
115-
(lsp.server/send-request server "editor/getDiagnostics" (assoc-some {} :uri uri)))))
114+
(jsonrpc.server/discarding-stdout
115+
(jsonrpc.server/send-request server "editor/getDiagnostics" (assoc-some {} :uri uri)))))
116116

117117
(defn start-server! [server]
118118
(let [db* (atom db/initial-db)
@@ -122,10 +122,10 @@
122122
(logger/info "[server]" "Starting server...")
123123
(monitor-server-logs (:log-ch server))
124124
(setup-dev-environment db* components)
125-
(lsp.server/start server components)))
125+
(jsonrpc.server/start server components)))
126126

127127
(defn run-io-server! [verbose?]
128-
(lsp.server/discarding-stdout
128+
(jsonrpc.server/discarding-stdout
129129
(let [log-ch (async/chan (async/sliding-buffer 20))
130130
server (io-server/stdio-server {:log-ch log-ch
131131
:trace-ch log-ch

0 commit comments

Comments
 (0)