Hello! I like clojure-lsp format provides cljfmt. I've got some large edn files in my repo (test resources) that I'd like to exclude from formatting. I'm supplying the paths I'd like . This works when calling cljfmt directly, but not when using clojure-lsp format . I believe clojure-lsp is ignoring this and using the paths it derives from my deps.edn instead. I'm I correct in my assumption? Is there currently a way to have clojure-lsp format ignore directories that are otherwise included in the project?
Example:
% cat deps.edn
{:paths ["src" "resources"]}
% cat .cljfmt.edn
{:paths ["src"]}
% cat resources/data.edn
{:not
"formatted"}
% cat src/com/grzm/ex/cljlsp_format.clj
(ns com.grzm.ex.cljlsp-format)
(defn -main
"please format me!"
[& _args]
(println "Hello, world!"))Yes, you can exclude the edn files from the source-paths, there are some ways to do that:
% clojure-lsp format
[ 99%] Project analyzed Formatting namespaces...
Formatted data
Formatted com.grzm.ex.cljlsp-format
Formatted 2 namespaces
# reset
% git co .
Updated 2 paths from the index
% cljfmt fix
Reformatted src/com/grzm/ex/cljlsp_format.clj
I believe the best here is configure :paths-ignore-regex clojure-lsp config
Cheers. It looks like I'm not spelling something right:
% cat .lsp/config.edn
{:paths-ignore-regex ["resources/.*"]}
% clojure-lsp format
[ 99%] Project analyzed Formatting namespaces...
Formatted data
Formatted com.grzm.ex.cljlsp-format
Formatted 2 namespaces
% tree .
.
├── deps.edn
├── resources
│ └── data.edn
└── src
└── com
└── grzm
└── ex
└── cljlsp_format.clj
6 directories, 3 filesDoes the config look right to you?
yes it does
it might be the regex
Looks like I should use :source-paths-ignore-regex if I want to use paths relative to the project:
% cat .lsp/config.edn
{:source-paths-ignore-regex ["resources"]}
% clojure-lsp format
[ 99%] Project analyzed Formatting namespaces...
Formatted com.grzm.ex.cljlsp-format
Formatted 1 namespaces
we apply https://github.com/clojure-lsp/clojure-lsp/blob/f555e4b89a1a3aa8aa9f66809f0d5e4dc034c61d/lib/src/clojure_lsp/shared.clj#L587 on the whole abs path, so maybe .*resources/.*
yeah, that sound best for your case
Kinda surprised that if I include the / it doesn't work:
% cat .lsp/config.edn
{:source-paths-ignore-regex ["resources/"]}
% clojure-lsp format
[ 99%] Project analyzed Formatting namespaces...
Formatted data
Formatted com.grzm.ex.cljlsp-format
Formatted 2 namespacesyeah that's always tricky, we should add examples I guess
Thanks for the assist! (and it was good to meet you at the Conj!)