Skip to content

Commit e02152e

Browse files
author
Bruce Hauman
committed
Add .cljd (ClojureDart) support and consolidate Clojure file detection
- Add .cljd extension to valid_paths/clojure-file? (canonical check) - Remove duplicate clojure-file? from paren_repair, delegate to valid-paths - Add .cljd and .lpy to project namespace filter and extension regex - Update error messages in form_edit tools to include .cljd - Add test coverage for .cljd and .lpy in valid_paths_test and file_write_test - Document test runner -n and -v flags in CLAUDE.md
1 parent d6175d0 commit e02152e

8 files changed

Lines changed: 21 additions & 17 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Build Commands
44
- Run REPL with MCP server: `clojure -X:mcp` (starts on port 7888)
55
- Run all tests: `clojure -M:test`
6+
- Run specific namespace tests: `clojure -M:test -n clojure-mcp.utils.valid-paths-test`
7+
- Run specific test var: `clojure -M:test -v clojure-mcp.utils.valid-paths-test/clojure-file?-test`
68
- Run linter: `clj-kondo --lint src` or `clj-kondo --lint src test` for both
79

810
## Code Style Guidelines

src/clojure_mcp/tools/form_edit/combined_edit_tool.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(throw (ex-info "Missing required parameter: file_path"
1717
{:inputs inputs})))
1818
(when-not (valid-paths/clojure-file? file_path)
19-
(throw (ex-info "File must have a Clojure extension (.clj, .cljs, .cljc, .bb, .edn)"
19+
(throw (ex-info "File must have a Clojure extension (.clj, .cljs, .cljc, .cljd, .bb, .edn)"
2020
{:file_path file_path})))
2121
;; Use the utils/validate-path-with-client function to ensure path is valid
2222
(valid-paths/validate-path-with-client file_path nrepl-client)))

src/clojure_mcp/tools/form_edit/tool.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(throw (ex-info "Missing required parameter: file_path"
2222
{:inputs inputs})))
2323
(when-not (valid-paths/clojure-file? file_path)
24-
(throw (ex-info "File must have a Clojure extension (.clj, .cljs, .cljc, .bb, .edn)"
24+
(throw (ex-info "File must have a Clojure extension (.clj, .cljs, .cljc, .cljd, .bb, .edn)"
2525
{:file_path file_path})))
2626
;; Use the utils/validate-path-with-client function to ensure path is valid
2727
(valid-paths/validate-path-with-client file_path nrepl-client)))

src/clojure_mcp/tools/paren_repair/core.clj

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88
[clojure-mcp.sexp.paren-utils :as paren-utils]
99
[clojure-mcp.tools.form-edit.core :as form-edit-core]
1010
[clojure-mcp.utils.diff :as diff]
11-
[clojure-mcp.utils.file :as file-utils]))
12-
13-
(def clojure-extensions
14-
"Set of file extensions considered Clojure files."
15-
#{".clj" ".cljs" ".cljc" ".edn"})
16-
17-
(defn clojure-file?
18-
"Returns true if the file path has a Clojure file extension."
19-
[file-path]
20-
(let [path-str (str file-path)]
21-
(some #(string/ends-with? path-str %) clojure-extensions)))
11+
[clojure-mcp.utils.file :as file-utils]
12+
[clojure-mcp.utils.valid-paths :as valid-paths]))
2213

2314
(defn repair-file!
2415
"Repairs delimiter errors in a Clojure file and optionally formats it.
@@ -47,7 +38,7 @@
4738
:diff nil}
4839

4940
;; Not a Clojure file
50-
(not (clojure-file? file-path))
41+
(not (valid-paths/clojure-file? file-path))
5142
{:success false
5243
:file-path file-path
5344
:message "Not a Clojure file (skipping)"

src/clojure_mcp/tools/project/core.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@
272272
processed-namespaces (->> source-files
273273
(filter #(or (str/ends-with? % ".clj")
274274
(str/ends-with? % ".cljs")
275-
(str/ends-with? % ".cljc")))
275+
(str/ends-with? % ".cljc")
276+
(str/ends-with? % ".cljd")
277+
(str/ends-with? % ".lpy")))
276278
(map (fn [file-path]
277279
;; Remove source path prefix from file path
278280
(let [relative-path (reduce (fn [path src-path]
@@ -284,7 +286,7 @@
284286
(-> relative-path
285287
(str/replace "/" ".")
286288
(str/replace "_" "-")
287-
(str/replace #"\.(clj|cljs|cljc)$" "")))))
289+
(str/replace #"\.(clj|cljs|cljc|cljd|lpy)$" "")))))
288290
;; Sort namespaces alphabetically
289291
sort
290292
(into []))]

src/clojure_mcp/utils/valid_paths.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@
9999
- .clj (Clojure)
100100
- .cljs (ClojureScript)
101101
- .cljc (Clojure/ClojureScript shared)
102+
- .cljd (ClojureDart)
102103
- .bb (Babashka)
103104
- .edn (Extensible Data Notation)
104105
- .lpy (Librepl)
105-
106+
106107
Also detects files starting with a Babashka shebang (`bb`)."
107108
[file-path]
108109
(when file-path
109110
(let [lower-path (str/lower-case file-path)]
110111
(or (str/ends-with? lower-path ".clj")
111112
(str/ends-with? lower-path ".cljs")
112113
(str/ends-with? lower-path ".cljc")
114+
(str/ends-with? lower-path ".cljd")
113115
(str/ends-with? lower-path ".bb")
114116
(str/ends-with? lower-path ".lpy")
115117
(str/ends-with? lower-path ".edn")

test/clojure_mcp/tools/file_write/core_test.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
(is (file-write-core/is-clojure-file? "test.clj"))
4949
(is (file-write-core/is-clojure-file? "test.cljs"))
5050
(is (file-write-core/is-clojure-file? "test.cljc"))
51+
(is (file-write-core/is-clojure-file? "test.cljd"))
5152
(is (file-write-core/is-clojure-file? "test.edn"))
5253
(is (file-write-core/is-clojure-file? "test.bb"))
5354
(is (file-write-core/is-clojure-file? "/path/to/file.clj"))

test/clojure_mcp/utils/valid_paths_test.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
(valid-paths/preprocess-path "..")))))
104104

105105
(deftest clojure-file?-test
106+
(testing "Detect ClojureDart extension"
107+
(is (valid-paths/clojure-file? "test.cljd"))
108+
(is (valid-paths/clojure-file? "/path/to/file.cljd")))
109+
(testing "Detect Basilisp extension"
110+
(is (valid-paths/clojure-file? "test.lpy"))
111+
(is (valid-paths/clojure-file? "/path/to/file.lpy")))
106112
(testing "Detect Babashka shebang"
107113
(let [tmp (io/file (System/getProperty "java.io.tmpdir") "bb-script.sh")]
108114
(spit tmp "#!/usr/bin/env bb\n(println :hi)")

0 commit comments

Comments
 (0)