clojure開發環境配置git, vscode插件配置


萬事開頭難,全是犄角旮旯的細節。

1 安裝lein

參見 https://www.cnblogs.com/xuanmanstein/p/10504401.html

2 創建工程 lein 

參考https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md

lein new my-project

3 關聯git

因為lein必須從沒有文件夾的狀態開始創建,所以不能直接從遠程庫創建好pull下來。

前置條件:

  1在遠程倉庫創建了工程

  2在本地用lein創建了工程

關聯:

cd my-project
git init
git remote add origin git@XXX:YYY/my-project.git

git init 在工程里建立空的git庫。然后關聯到遠程倉庫

后面再提交就和別的工程一樣了。

——還是不如ng-cli舒服,這種就應該可以在非空文件夾,或者包含.git的文件夾創建工程,可以省去 關聯這一步

 4 安裝code插件

主要是calva和 clojure

這2個各有利弊,最上面這個clojure好像對ClojureScript支持的一般,沒有calva好。但是啟動好像稍微簡單點,所以裝機量也多。

4.1 Clojure

直接叫clojure  https://github.com/avli/clojureVSCode

改porject.clj里 :profiles部分 

  :profiles {:uberjar {:aot :all}
             :repl {:plugins [[cider/cider-nrepl "0.21.1"]] :dependencies [[nrepl "0.6.0"] [cider/piggieback "0.4.0"] [figwheel-sidecar "0.5.18"]] :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}  :user {:plugins [[cider/cider-nrepl "0.21.1"]] :dependencies [[org.clojure/tools.nrepl "0.2.13"] [cljfmt "0.5.7"]]} })

如果正常,應該每次開啟vscode的clojure項目時,在下面自動連接nrepl:過幾秒鍾:

這就表示連上了

如何運行腳本

在sublime里習慣ctrl+B運行py了,那么要運行clj呢?

參考https://spin.atomicobject.com/2017/06/22/clojure-development-with-visual-studio-code/

在文件-首選項-鍵盤快捷方式里

先搜索ctrl+B  vscode默認是顯隱側邊欄,這個我不常用,直接用鼠標按側邊按鈕代替,所以刪除這個

然后搜索 Clojure 會有個 eval and show the result 命令, 把Ctrl+B綁這個上

 隨便新建個文件,然后寫兩筆,按ctrl+B就能在下面看到運行結果了:

美中不足,每次運行不會清屏,類似matlab,而不是sublime。 

 

 

4.2 Calva

 

 

然后,參考https://github.com/BetterThanTomorrow/calva/wiki/Getting-Started

把porject.clj里 :profiles部分修改成

  :profiles {:uberjar {:aot :all}
 :repl {:plugins [[cider/cider-nrepl "0.21.2-SNAPSHOT"]] :dependencies [[nrepl "0.6.0"] [cider/piggieback "0.4.0"] [figwheel-sidecar "0.5.18"]] :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}
             })

退出在重新開啟code,點開任何1個clj文件,會開始安裝這些玩意

然后 :

1 ctrl+` 啟動控制台

2在控制台lein repl 啟動環境 這時候會隨機分配1個端口號

nREPL server started on port 37749 on host 127.0.0.1 - nrepl://127.0.0.1:37749

3 點擊code下邊欄 nREPL標志,彈出對話框,端口應該已經輸入進去了 enter確認

如果上面不彈窗,就先同時按ctrl+alt+v  再按 c

 

看到變成彩色的,說明成功

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM