|
217 | 217 | "For example if you wanted to manipulate Figwheel compilers you have to use Figwheel's own interface for that:\n" |
218 | 218 | "=> https://github.com/bhauman/lein-figwheel#repl-figwheel-control-functions.")) |
219 | 219 |
|
| 220 | +(defn ^:dynamic make-retargeting-warning-msg [] |
| 221 | + (str "You are in a joined Dirac session. This command is being executed as if it was entered in the target session.")) |
| 222 | + |
| 223 | +(defn ^:dynamic warn-about-retargeting-if-needed [session] |
| 224 | + (if (not= session (state/get-current-session)) |
| 225 | + (println (make-retargeting-warning-msg)))) |
| 226 | + |
220 | 227 | ; == special REPL commands ================================================================================================== |
221 | 228 |
|
222 | 229 | ; we are forgiving when reading the sub-command argument, |
|
250 | 257 |
|
251 | 258 | ; -- (dirac! :status) ------------------------------------------------------------------------------------------------------- |
252 | 259 |
|
253 | | -(defn get-target-session [session] |
254 | | - (if-let [target-session-descriptor (sessions/find-target-dirac-session-descriptor session)] |
255 | | - (sessions/get-dirac-session-descriptor-session target-session-descriptor))) |
256 | | - |
257 | 260 | (defn prepare-session-description [session] |
258 | 261 | (cond |
259 | 262 | (sessions/dirac-session? session) |
|
270 | 273 |
|
271 | 274 | (sessions/joined-session? session) |
272 | 275 | (let [target-info (sessions/get-target-session-info session) |
273 | | - target-session (get-target-session session)] |
| 276 | + target-session (sessions/get-target-session session)] |
274 | 277 | (str "joined Dirac session (ClojureScript) which targets '" target-info "'\n" |
275 | 278 | (if (some? target-session) |
276 | 279 | (str "which is currently forwarding commands to the " (prepare-session-description target-session)) |
|
287 | 290 | ; -- (dirac! :ls) ----------------------------------------------------------------------------------------------------------- |
288 | 291 |
|
289 | 292 | (defmethod dirac! :ls [_ & _] |
290 | | - (let [session (state/get-current-session) |
291 | | - target-session (if (sessions/joined-session? session) |
292 | | - (get-target-session session) |
293 | | - session) |
| 293 | + (let [target-session (sessions/get-current-retargeted-session) |
294 | 294 | tags (sessions/get-dirac-session-tags target-session) |
295 | 295 | current-tag (sessions/get-current-session-tag target-session) |
296 | 296 | avail-compilers (compilers/collect-all-available-compiler-descriptors target-session) |
297 | 297 | selected-compiler-id (compilers/get-selected-compiler-id target-session) |
298 | | - marker (if (= session target-session) "->" "~>")] |
| 298 | + marker (if (= target-session (state/get-current-session)) "->" "~>")] |
299 | 299 | (println (make-list-dirac-sessions-msg tags current-tag marker)) |
300 | 300 | (println) |
301 | 301 | (println (make-list-compilers-msg avail-compilers selected-compiler-id marker))) |
|
354 | 354 | :else ::invalid-input)) |
355 | 355 |
|
356 | 356 | (defmethod dirac! :switch [_ & [user-input]] |
357 | | - (let [selected-compiler (validate-selected-compiler user-input) |
358 | | - session (state/get-current-session)] |
| 357 | + (let [selected-compiler (validate-selected-compiler user-input)] |
359 | 358 | (if (= ::invalid-input selected-compiler) |
360 | 359 | (error-println (make-invalid-compiler-error-msg user-input)) |
361 | | - (do |
| 360 | + (let [session (sessions/get-current-retargeted-session)] |
| 361 | + (warn-about-retargeting-if-needed session) |
362 | 362 | (compilers/select-compiler! session selected-compiler) |
363 | 363 | (let [matched-compiler-descriptor (compilers/find-available-matching-compiler-descriptor session selected-compiler)] |
364 | 364 | (if (nil? matched-compiler-descriptor) |
|
369 | 369 | ; -- (dirac! :spawn) -------------------------------------------------------------------------------------------------------- |
370 | 370 |
|
371 | 371 | (defmethod dirac! :spawn [_ & [options]] |
372 | | - (let [session (sessions/get-current-session)] |
| 372 | + (let [session (sessions/get-current-retargeted-session)] |
| 373 | + (warn-about-retargeting-if-needed session) |
373 | 374 | (cond |
374 | 375 | (not (sessions/dirac-session? session)) (error-println (make-cannot-spawn-outside-dirac-session-msg)) |
375 | 376 | :else (utils/spawn-compiler! state/*nrepl-message* options))) |
|
378 | 379 | ; -- (dirac! ::kill) -------------------------------------------------------------------------------------------------------- |
379 | 380 |
|
380 | 381 | (defmethod dirac! :kill [_ & [user-input]] |
381 | | - (let [selected-compiler (validate-selected-compiler user-input) |
382 | | - session (state/get-current-session)] |
| 382 | + (let [selected-compiler (validate-selected-compiler user-input)] |
383 | 383 | (if (= ::invalid-input selected-compiler) |
384 | 384 | (error-println (make-invalid-compiler-error-msg user-input)) |
385 | | - (let [[killed-compiler-ids invalid-compiler-ids] (utils/kill-matching-compilers! selected-compiler)] |
386 | | - (if (empty? killed-compiler-ids) |
387 | | - (error-println (make-no-killed-compilers-msg user-input)) |
388 | | - (do |
389 | | - (println (make-report-killed-compilers-msg user-input killed-compiler-ids)) |
390 | | - (if-not (compilers/get-selected-compiler-id session) ; switch to first available compiler the current one got killed |
391 | | - (compilers/select-compiler! session nil)) ; note that this still might not guarantee valid compiler selection, the compiler list might be empty |
392 | | - (state/send-response! (utils/prepare-current-env-info-response)))) |
393 | | - (if-not (empty? invalid-compiler-ids) |
394 | | - (error-println (make-report-invalid-compilers-not-killed-msg user-input invalid-compiler-ids)))))) |
| 385 | + (let [session (sessions/get-current-retargeted-session)] |
| 386 | + (warn-about-retargeting-if-needed session) |
| 387 | + (let [[killed-compiler-ids invalid-compiler-ids] (utils/kill-matching-compilers! selected-compiler)] |
| 388 | + (if (empty? killed-compiler-ids) |
| 389 | + (error-println (make-no-killed-compilers-msg user-input)) |
| 390 | + (do |
| 391 | + (println (make-report-killed-compilers-msg user-input killed-compiler-ids)) |
| 392 | + (if-not (compilers/get-selected-compiler-id session) ; switch to first available compiler the current one got killed |
| 393 | + (compilers/select-compiler! session nil)) ; note that this still might not guarantee valid compiler selection, the compiler list might be empty |
| 394 | + (state/send-response! (utils/prepare-current-env-info-response)))) |
| 395 | + (if-not (empty? invalid-compiler-ids) |
| 396 | + (error-println (make-report-invalid-compilers-not-killed-msg user-input invalid-compiler-ids))))))) |
395 | 397 | ::no-result) |
396 | 398 |
|
397 | 399 | ; -- default handler -------------------------------------------------------------------------------------------------------- |
|
0 commit comments