使用 Clojure CLI 时无法使用 fireplace.vim 评估 ClojureScript

Unable to evaluate ClojureScript using fireplace.vim when using the Clojure CLI

我很期待用 the new release of ClojureScript 进行试验,但我 运行 在尝试评估代码时遇到了问题。

我有一个 nREPL 服务器 运行 并且我(似乎?)能够使用 :Fireplaceconnect localhost:$PORT 连接到它。但是,当我尝试评估代码(使用 :Eval:CljsEval)时,我看到一条错误消息,上面写着 "Fireplace: no default ClojureScript REPL"。

fireplace.vim 存储库中有 an issue 提到了这个问题,但它已被 RTFM 关闭——我已经解决了,但我仍然找不到解决方案。

~/.clojure/deps.edn

{
  :aliases {:nREPL
             {:extra-deps
               {nrepl/nrepl {:mvn/version "0.7.0"}
                cider/piggieback {:mvn/version "0.4.2"}}}}
}

正在启动 nrepl

> clj -R:nREPL -m nrepl.cmdline --middleware "[cider.piggieback/wrap-cljs-repl]"

我找到了可行的解决方案并记录了整个工作流程here:

deps.edn:

{
 :aliases {:rebel {:main-opts ["-m" "rebel-readline.main"]}}
 :paths ["src" "resources" "target"]
 :deps {cider/cider-nrepl {:mvn/version "0.25.0-alpha1"}
        cider/piggieback {:mvn/version "0.5.0"}
        com.bhauman/figwheel-main {:mvn/version "0.2.6"}
        com.bhauman/rebel-readline {:mvn/version "0.1.4"}
        com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
        nrepl/nrepl {:mvn/version "0.7.0"}
        org.clojure/clojure {:mvn/version "1.10.1"}
        org.clojure/clojurescript {:mvn/version "1.10.773"}
        reagent {:mvn/version "0.10.0"
                 :exclusions [cljsjs/react cljsjs/react-dom]}}}

在 Clojure REPL 中 运行 以下命令启动 nREPL 服务器、ClojureScript REPL 和 Figwheel 构建:

(require '[fullstack.helpers :refer :all])  ;; import nREPL helpers
(start-nrepl-server!)                       ;; start nREPL server on 7888

;; Some people run the following commands using Vim-Fireplace's `:CljEval`
;; command but I found that to be a little clunky.
;; If I do end up using this workflow regularly, I'll consider packaging these
;; steps up in a VimScript helper function.
;; Out of habit, I send them from this document inside vim to a parallel tmux
;; pane using vim-slime.

(require 'figwheel.main.api)    ;; require Figwheel's scripting API
(figwheel.main.api/start "dev") ;; start Figwheel build (using dev.cljs.edn) and REPL

在 Vim、运行 中,在 CLI 提示符下执行以下命令(在命令模式下点击 :)以连接到 运行ning ClojureScript REPL:

:Piggieback (figwheel.main.api/repl-env "dev") " connect to the CLJS REPL

主要区别是将依赖项移动到本地 deps.edn(这不是必需的,但我认为这是一种更好、更灵活的方法)、升级 Piggieback 并依靠更高级别的 Figwheel 脚本 API,而不是 CLI 标志。