|
63 | 63 | (:code-channel plugin))
|
64 | 64 |
|
65 | 65 | (defn start
|
66 |
| - [{:keys [nvim nrepl repl-log socket-repl code-channel] :as plugin}] |
| 66 | + [{:keys [nvim nrepl repl-log socket-repl internal-socket-repl code-channel] :as plugin}] |
67 | 67 |
|
68 | 68 | ;; Wire sub-component io.
|
69 | 69 | (log-start
|
|
83 | 83 | (string/split #":"))]
|
84 | 84 | (try
|
85 | 85 | (socket-repl/connect socket-repl host port)
|
| 86 | + (socket-repl/connect internal-socket-repl host port) |
| 87 | + (async/>!! (socket-repl/input-channel internal-socket-repl) |
| 88 | + '(do |
| 89 | + (ns srepl.injection |
| 90 | + (:refer-clojure :rename {eval core-eval})) |
| 91 | + (defn eval |
| 92 | + ([form] (eval form nil)) |
| 93 | + ([form options] |
| 94 | + (let [result (core-eval form)] |
| 95 | + (merge |
| 96 | + #:socket-repl{:result (pr-str result) |
| 97 | + :form (pr-str form)} |
| 98 | + options)))))) |
86 | 99 | (catch Throwable t
|
87 | 100 | (log/error t "Error connecting to socket repl")
|
88 | 101 | (async/thread (api/command
|
|
115 | 128 | plugin
|
116 | 129 | (fn [msg]
|
117 | 130 | (try
|
118 |
| - (async/>!! code-channel (parser/read-next |
119 |
| - (-> msg |
120 |
| - message/params |
121 |
| - ffirst) |
122 |
| - 0 0)) |
| 131 | + (async/>!! (socket-repl/input-channel socket-repl) |
| 132 | + (parser/read-next |
| 133 | + (-> msg |
| 134 | + message/params |
| 135 | + ffirst) |
| 136 | + 0 0)) |
123 | 137 | (catch Throwable t
|
124 | 138 | (log/error t "Error evaluating form")
|
125 | 139 | (write-error repl-log t))))))
|
|
133 | 147 | (let [[row col] (api-ext/get-cursor-location nvim)
|
134 | 148 | buffer-text (api-ext/get-current-buffer-text nvim)]
|
135 | 149 | (try
|
136 |
| - (async/>!! code-channel (parser/read-next buffer-text row (inc col))) |
| 150 | + (async/>!! (socket-repl/input-channel socket-repl) |
| 151 | + (parser/read-next buffer-text row (inc col))) |
137 | 152 | (catch Throwable t
|
138 | 153 | (log/error t "Error evaluating a form")
|
139 | 154 | (write-error repl-log t)))))))
|
|
147 | 162 | (let [buffer (api/get-current-buf nvim)]
|
148 | 163 | (let [code (string/join "\n" (api.buffer-ext/get-lines
|
149 | 164 | nvim buffer 0 -1))]
|
150 |
| - (async/>!! code-channel (format "(eval '(do %s))" code))))))) |
| 165 | + (async/>!! (socket-repl/input-channel socket-repl) |
| 166 | + (format "(eval '(do %s))" code))))))) |
151 | 167 |
|
152 | 168 | (nvim/register-method!
|
153 | 169 | nvim
|
|
158 | 174 | (let [code (format "(clojure.repl/doc %s)" (-> msg
|
159 | 175 | message/params
|
160 | 176 | ffirst))]
|
161 |
| - (async/>!! code-channel code))))) |
| 177 | + (async/>!! (socket-repl/input-channel socket-repl) code))))) |
162 | 178 |
|
163 | 179 | (nvim/register-method!
|
164 | 180 | nvim
|
|
170 | 186 | nvim
|
171 | 187 | (fn [word]
|
172 | 188 | (let [code (format "(clojure.repl/doc %s)" word)]
|
173 |
| - (async/>!! code-channel code))))))) |
| 189 | + (async/>!! (socket-repl/input-channel socket-repl) code))))))) |
174 | 190 |
|
175 | 191 | (nvim/register-method!
|
176 | 192 | nvim
|
|
181 | 197 | (let [code (format "(clojure.repl/source %s)" (-> msg
|
182 | 198 | message/params
|
183 | 199 | ffirst))]
|
184 |
| - (async/>!! code-channel code))))) |
| 200 | + (async/>!! (socket-repl/input-channel socket-repl) code))))) |
185 | 201 |
|
186 | 202 | (nvim/register-method!
|
187 | 203 | nvim
|
|
193 | 209 | nvim
|
194 | 210 | (fn [word]
|
195 | 211 | (let [code (format "(clojure.repl/source %s)" word)]
|
196 |
| - (async/>!! code-channel code))))))) |
| 212 | + (async/>!! (socket-repl/input-channel socket-repl) code))))))) |
| 213 | + |
| 214 | + (nvim/register-method! |
| 215 | + nvim |
| 216 | + "cp" |
| 217 | + (run-command |
| 218 | + plugin |
| 219 | + (fn [msg] |
| 220 | + (let [code-form "(map #(.getAbsolutePath %) (clojure.java.classpath/classpath))"] |
| 221 | + (log/info msg) |
| 222 | + (async/>!! (socket-repl/input-channel internal-socket-repl) |
| 223 | + code-form) |
| 224 | + (log/info "I'm in!") |
| 225 | + (async/thread |
| 226 | + (let [res-chan (async/chan 1 (filter #(= (:form %) code-form)))] |
| 227 | + (socket-repl/subscribe-output internal-socket-repl res-chan) |
| 228 | + (let [res (async/<!! res-chan)] |
| 229 | + (log/info (:ns res)) |
| 230 | + (log/info (:ms res)) |
| 231 | + (log/info (:val res)) |
| 232 | + (.close res-chan)))))))) |
197 | 233 |
|
198 | 234 | (nvim/register-method!
|
199 | 235 | nvim
|
|
244 | 280 | plugin))
|
245 | 281 |
|
246 | 282 | (defn new
|
247 |
| - [nvim nrepl repl-log socket-repl] |
| 283 | + [nvim nrepl repl-log socket-repl internal-socket-repl] |
248 | 284 | {:nvim nvim
|
249 | 285 | :nrepl nrepl
|
250 | 286 | :repl-log repl-log
|
251 | 287 | :socket-repl socket-repl
|
| 288 | + :internal-socket-repl internal-socket-repl |
252 | 289 | :code-channel (async/chan 1024)})
|
0 commit comments