在VSCode中格式化Clojure代码的推荐方法是使用Clojure LSP插件结合cljfmt工具,通过安装Calva和Clojure LSP扩展,确保cljfmt在项目或全局依赖中可用,并配置VSCode的格式化设置(如开启format on save),即可实现保存时自动格式化;进一步可通过项目根目录下的.cljfmt.edn文件自定义缩进等风格规则,实现团队统一的代码风格。

在VSCode中格式化Clojure代码,最直接且推荐的方式是利用Clojure LSP(Language Server Protocol)插件,并结合
cljfmt
要在VSCode中配置并使用
cljfmt
安装必要的VSCode扩展 首先,你需要在VSCode中安装两个核心扩展:
cljfmt
cljfmt
确保cljfmt
cljfmt
deps.edn
project.clj
deps.edn
cljfmt
cljfmt
;; deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}}
:aliases
{:dev {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main"]}}}然后,你可能需要配置一个VSCode任务来运行它,或者让Clojure LSP来自动调用。
cljfmt
tools.edn
;; ~/.clojure/tools.edn
{:aliases
{:cljfmt {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main"]}}}这样你就可以在任何地方通过
clj -A:cljfmt check
clj -A:cljfmt fix
cljfmt
配置VSCode设置 打开VSCode的设置(
Ctrl+,
Cmd+,
[clojure]
通常情况下,只要
cljfmt
.clj
.cljc
cljfmt
说实话,Clojure社区在格式化工具的选择上,
cljfmt
cljfmt
.cljfmt.edn
另外,
cljfmt
cljfmt
.cljfmt.edn
cljfmt
这里有一些我经常会用到,也觉得非常实用的配置选项:
:indentation
:indentation
{^:defn [[_ & body]]
^:defmacro [[_ & body]]
^:fn [[_ & body]]
^:let [[_ bindings & body]]
^:with-open [[_ bindings & body]]
^:binding [[_ bindings & body]]
^:try [[_ & body]]
^:catch [[_ & body]]
^:finally [[_ & body]]
^:loop [[_ bindings & body]]
^:for [[_ bindings & body]]
^:if [[_ & body]]
^:cond [[_ & body]]
^:case [[_ & body]]
^:doseq [[_ bindings & body]]
^:dotimes [[_ bindings & body]]
^:deftest [[_ & body]]
^:testing [[_ & body]]
^:extend [[_ & body]]
^:extend-type [[_ & body]]
^:extend-protocol [[_ & body]]
^:reify [[_ & body]]
^:defrecord [[_ & body]]
^:deftype [[_ & body]]
^:gen-class [[_ & body]]
^:proxy [[_ & body]]
^:future [[_ & body]]
^:comment [[_ & body]]
^:when [[_ & body]]
^:when-let [[_ bindings & body]]
^:if-let [[_ bindings & body]]
^:doto [[_ & body]]
^:with-redefs [[_ bindings & body]]
^:with-local-vars [[_ bindings & body]]
^:locking [[_ & body]]
^:ns [[_ & body]]
^:require [[_ & body]]
^:import [[_ & body]]
^:use [[_ & body]]
^:refer [[_ & body]]
^:gen-interface [[_ & body]]
^:definterface [[_ & body]]
^:defprotocol [[_ & body]]
^:deftransient [[_ & body]]
^:volatile! [[_ & body]]
^:eval [[_ & body]]
^:macroexpand [[_ & body]]
^:macroexpand-1 [[_ & body]]
^:time [[_ & body]]
^:with-out-str [[_ & body]]
^:with-in-str [[_ & body]]
^:with-precision [[_ & body]]
^:with-loading-context [[_ & body]]
^:with-meta [[_ & body]]
^:with-bindings [[_ bindings & body]]
^:with-bindings* [[_ bindings & body]]
^:with-local-vars [[_ bindings & body]]
^:with-open [[_ bindings & body]]
^:with-redefs [[_ bindings & body]]
^:with-test [[_ & body]]
^:with-timeout [[_ & body]]
^:with-profile [[_ & body]]
^:with-config [[_ & body]]
^:with-logger [[_ & body]]
^:with-out-writer [[_ & body]]
^:with-system [[_ & body]]
^:with-handler [[_ & body]]
^:with-services [[_ & body]]
^:with-server [[_ & body]]
^:with-connection [[_ & body]]
^:with-session [[_ & body]]
^:with-transaction [[_ & body]]
^:with-pool [[_ & body]]
^:with-resource [[_ & body]]
^:with-env [[_ & body]]
^:with-parameters [[_ & body]]
^:with-context [[_ & body]]
^:with-credentials [[_ & body]]
^:with-request [[_ & body]]
^:with-response [[_ & body]]
^:with-middleware [[_ & body]]
^:with-component [[_ & body]]
^:with-reader [[_ & body]]
^:with-writer [[_ & body]]
^:with-buffer [[_ & body]]
^:with-channel [[_ & body]]
^:with-stream [[_ & body]]
^:with-socket [[_ & body]]
^:with-server-socket [[_ & body]]
^:with-client-socket [[_ & body]]
^:with-http-client [[_ & body]]
^:with-http-server [[_ & body]]
^:with-jetty [[_ & body]]
^:with-aleph [[_ & body]]
^:with-http-request [[_ & body]]
^:with-http-response [[_ & body]]
^:with-http-handler [[_ & body]]
^:with-http-middleware [[_ & body]]
^:with-http-server-opts [[_ & body]]
^:with-http-client-opts [[_ & body]]
^:with-websocket [[_ & body]]
^:with-async-handler [[_ & body]]
^:with-async-middleware [[_ & body]]
^:with-async-server [[_ & body]]
^:with-async-client [[_ & body]]
^:with-async-http [[_ & body]]
^:with-async-websocket [[_ & body]]
^:with-manifold [[_ & body]]
^:with-sente [[_ & body]]
^:with-immutant [[_ & body]]
^:with-pedestal [[_ & body]]
^:with-ring [[_ & body]]
^:with-compojure [[_ & body]]
^:with-liberator [[_ & body]]
^:with-reitit [[_ & body]]
^:with-bidi [[_ & body]]
^:with-buddy [[_ & body]]
^:with-cljs-repl [[_ & body]]
^:with-figwheel [[_ & body]]
^:with-shadow-cljs [[_ & body]]
^:with-boot [[_ & body]]
^:with-lein [[_ & body]]
^:with-deps [[_ & body]]
^:with-tools [[_ & body]]
^:with-env-vars [[_ & body]]
^:with-system-properties [[_ & body]]
^:with-jvm-opts [[_ & body]]
^:with-classpath [[_ & body]]
^:with-resource-paths [[_ & body]]
^:with-source-paths [[_ & body]]
^:with-test-paths [[_ & body]]
^:with-target-path [[_ & body]]
^:with-output-path [[_ & body]]
^:with-foreign-libs [[_ & body]]
^:with-asset-paths [[_ & body]]
^:with-asset-dirs [[_ & body]]
^:with-npm-deps [[_ & body]]
^:with-js-deps [[_ & body]]
^:with-css-deps [[_ & body]]
^:with-sass-deps [[_ & body]]
^:with-less-deps [[_ & body]]
^:with-stylus-deps [[_ & body]]
^:with-closure-deps [[_ & body]]
^:with-goog-deps [[_ & body]]
^:with-compiler-opts [[_ & body]]
^:with-optimizations [[_ & body]]
^:with-pretty-print [[_ & body]]
^:with-source-map [[_ & body]]
^:with-verbose [[_ & body]]
^:with-warnings [[_ & body]]
^:with-reader-macros [[_ & body]]
^:with-syntax-quote [[_ & body]]
^:with-line-numbers [[_ & body]]
^:with-column-numbers [[_ & body]]
^:with-docstrings [[_ & body]]
^:with-metadata [[_ & body]]
^:with-annotations [[_ & body]]
^:with-type-hints [[_ & body]]
^:with-tag [[_ & body]]
^:with-macro [[_ & body]]
^:with-inline [[_ & body]]
^:with-no-doc [[_ & body]]
^:with-private [[_ & body]]
^:with-dynamic [[_ & body]]
^:with-static [[_ & body]]
^:with-final [[_ & body]]
^:with-transient [[_ & body]]
^:with-volatile [[_ & body]]
^:with-thread-local [[_ & body]]
^:with-thread-bound [[_ & body]]
^:with-agent [[_ & body]]
^:with-ref [[_ & body]]
^:with-atom [[_ & body]]
^:with-promise [[_ & body]]
^:with-future [[_ & body]]
^:with-delay [[_ & body]]
^:with-lazy [[_ & body]]
^:with-memo [[_ & body]]
^:with-cache [[_ & body]]
^:with-throttle [[_ & body]]
^:with-debounce [[_ & body]]
^:with-rate-limit [[_ & body]]
^:with-circuit-breaker [[_ & body]]
^:with-retry [[_ & body]]
^:with-timeout-handler [[_ & body]]
^:with-fallback [[_ & body]]
^:with-metrics [[_ & body]]
^:with-tracing [[_ & body]]
^:with-logging [[_ & body]]
^:with-exceptions [[_ & body]]
^:with-error-handling [[_ & body]]
^:with-validation [[_ & body]]
^:with-schema [[_ & body]]
^:with-spec [[_ & body]]
^:with-instrumentation [[_ & body]]
^:with-test-runner [[_ & body]]
^:with-test-reporter [[_ & body]]
^:with-test-fixtures [[_ & body]]
^:with-test-selectors [[_ & body]]
^:with-test-namespaces [[_ & body]]
^:with-test-fns [[_ & body]]
^:with-test-macros [[_ & body]]
^:with-test-vars [[_ & body]]
^:with-test-data [[_ & body]]
^:with-test-assertions [[_ & body]]
^:with-test-check [[_ & body]]
^:with-test-generators [[_ & body]]
^:with-test-properties [[_ & body]]
^:with-test-framework [[_ & body]]
^:with-test-suite [[_ & body]]
^:with-test-plan [[_ & body]]
^:with-test-summary [[_ & body]]
^:with-test-coverage [[_ & body]]
^:with-test-report [[_ & body]]
^:with-test-results [[_ & body]]
^:with-test-failures [[_ & body]]
^:with-test-errors [[_ & body]]
^:with-test-skips [[_ & body]]
^:with-test-passes [[_ & body]]
^:with-test-duration [[_ & body]]
^:with-test-timestamp [[_ & body]]
^:with-test-environment [[_ & body]]
^:with-test-config [[_ & body]]
^:with-test-profile [[_ & body]]
^:with-test-alias [[_ & body]]
^:with-test-main [[_ & body]]
^:with-test-runner-opts [[_ & body]]
^:with-test-reporter-opts [[_ & body]]
^:with-test-selector-opts [[_ & body]]
^:with-test-namespace-opts [[_ & body]]
^:with-test-fn-opts [[_ & body]]
^:with-test-macro-opts [[_ & body]]
^:with-test-var-opts [[_ & body]]
^:with-test-data-opts [[_ & body]]
^:with-test-assertion-opts [[_ & body]]
^:with-test-check-opts [[_ & body]]
^:with-test-generator-opts [[_ & body]]
^:with-test-property-opts [[_ & body]]
^:with-test-framework-opts [[_ & body]]
^:with-test-suite-opts [[_ & body]]
^:with-test-plan-opts [[_ & body]]
^:with-test-summary-opts [[_ & body]]
^:with-test-coverage-opts [[_ & body]]
^:with-test-report-opts [[_ & body]]
^:with-test-result-opts [[_ & body]]
^:with-test-failure-opts [[_ & body]]
^:with-test-error-opts [[_ & body]]
^:with-test-skip-opts [[_ & body]]以上就是如何在VSCode中格式化Clojure代码?配置cljfmt的详细步骤的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号