|
8 | 8 | [clojure.tools.logging :as log] |
9 | 9 | [neovim-client.message :as message] |
10 | 10 | [neovim-client.nvim :as nvim] |
| 11 | + [socket-repl.nrepl :as nrepl] |
11 | 12 | [socket-repl.repl-log :as repl-log] |
12 | 13 | [socket-repl.socket-repl :as socket-repl] |
13 | 14 | [socket-repl.util :refer [log-start log-stop]])) |
|
43 | 44 | \n"######################\n"))) |
44 | 45 |
|
45 | 46 | (defn run-command |
46 | | - [{:keys [nvim socket-repl]} f] |
| 47 | + [{:keys [nvim nrepl socket-repl]} f] |
47 | 48 | (fn [msg] |
48 | | - (if-not (socket-repl/connected? socket-repl) |
| 49 | + (if-not (or (socket-repl/connected? socket-repl) |
| 50 | + (nrepl/connected? nrepl)) |
49 | 51 | (async/thread |
50 | 52 | (nvim/vim-command |
51 | 53 | nvim ":echo 'Use :Connect host:port to connect to a socket repl'")) |
|
77 | 79 | (:code-channel plugin)) |
78 | 80 |
|
79 | 81 | (defn start |
80 | | - [{:keys [nvim repl-log socket-repl code-channel] :as plugin}] |
| 82 | + [{:keys [nvim nrepl repl-log socket-repl code-channel] :as plugin}] |
81 | 83 |
|
82 | 84 | ;; Wire sub-component io. |
83 | 85 | (log-start |
84 | 86 | "plugin" |
85 | 87 | (let [mult (async/mult code-channel)] |
86 | 88 | (async/tap mult (socket-repl/input-channel socket-repl)) |
87 | | - (async/tap mult (repl-log/input-channel repl-log))) |
| 89 | + (async/tap mult (repl-log/input-channel repl-log)) |
| 90 | + (async/tap mult (nrepl/input-channel nrepl))) |
88 | 91 |
|
89 | 92 | ;; Setup plugin functions. |
90 | 93 | (nvim/register-method! |
|
104 | 107 | ":echo 'Unable to connect to socket repl.'")))) |
105 | 108 | :done))) |
106 | 109 |
|
| 110 | + (nvim/register-method! |
| 111 | + nvim |
| 112 | + "connect-nrepl" |
| 113 | + (fn [msg] |
| 114 | + ;; TODO - reuse this |
| 115 | + (let [[host port] (-> msg |
| 116 | + message/params |
| 117 | + first |
| 118 | + (string/split #":"))] |
| 119 | + (try |
| 120 | + (nrepl/connect nrepl host port) |
| 121 | + (catch Throwable t |
| 122 | + (log/error t "Error connecting to nrepl") |
| 123 | + (async/thread (nvim/vim-command |
| 124 | + nvim |
| 125 | + ":echo 'Unable to connect to nrepl.'")))) |
| 126 | + :done))) |
| 127 | + |
107 | 128 | (nvim/register-method! |
108 | 129 | nvim |
109 | 130 | "eval-code" |
|
196 | 217 | plugin)) |
197 | 218 |
|
198 | 219 | (defn new |
199 | | - [nvim repl-log socket-repl] |
| 220 | + [nvim nrepl repl-log socket-repl] |
200 | 221 | {:nvim nvim |
| 222 | + :nrepl nrepl |
201 | 223 | :repl-log repl-log |
202 | 224 | :socket-repl socket-repl |
203 | 225 | :code-channel (async/chan 1024)}) |
0 commit comments