Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: add `clojure` support (#1520)

Jeriel Baptista Verissimo814ba9c18796
diff --git a/Cargo.lock b/Cargo.lock
index a2745d650..147c66435 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -856,6 +856,7 @@ dependencies = [
"tree-sitter-bash",
"tree-sitter-c",
"tree-sitter-c-sharp",
+ "tree-sitter-clojure",
"tree-sitter-cmake",
"tree-sitter-cpp",
"tree-sitter-go",
@@ -2792,6 +2793,17 @@ dependencies = [
"tree-sitter-language",
]
+[[package]]
+name = "tree-sitter-clojure"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4004884cc509449a1d78fa3e1f02b4e953d0a8065984445304795e72e885338c"
+dependencies = [
+ "cc",
+ "tree-sitter",
+ "tree-sitter-language",
+]
+
[[package]]
name = "tree-sitter-cmake"
version = "0.7.1"
diff --git a/harper-comments/Cargo.toml b/harper-comments/Cargo.toml
index f7e07dc98..d9467e2a2 100644
--- a/harper-comments/Cargo.toml
+++ b/harper-comments/Cargo.toml
@@ -35,6 +35,7 @@ tree-sitter-swift = "0.7.1"
tree-sitter-toml-ng = "0.7.0"
tree-sitter-typescript = "0.23.2"
harper-tree-sitter-dart = "0.0.5"
+tree-sitter-clojure = "0.1.0"
[dev-dependencies]
paste = "1.0.15"
diff --git a/harper-comments/src/comment_parser.rs b/harper-comments/src/comment_parser.rs
index 7a6383a39..5d09fc27c 100644
--- a/harper-comments/src/comment_parser.rs
+++ b/harper-comments/src/comment_parser.rs
@@ -46,6 +46,7 @@ impl CommentParser {
"toml" => tree_sitter_toml_ng::LANGUAGE,
"typescriptreact" => tree_sitter_typescript::LANGUAGE_TSX,
"typescript" => tree_sitter_typescript::LANGUAGE_TYPESCRIPT,
+ "clojure" => tree_sitter_clojure::LANGUAGE,
_ => return None,
};
@@ -105,6 +106,7 @@ impl CommentParser {
"toml" => "toml",
"ts" => "typescript",
"tsx" => "typescriptreact",
+ "clj" | "cljs" | "cljc" | "bb" => "clojure",
_ => return None,
})
}
diff --git a/harper-comments/tests/language_support.rs b/harper-comments/tests/language_support.rs
index eaddded22..328b4b519 100644
--- a/harper-comments/tests/language_support.rs
+++ b/harper-comments/tests/language_support.rs
@@ -58,6 +58,7 @@ create_test!(ignore_shebang_3.sh, 0);
create_test!(ignore_shebang_4.sh, 1);
create_test!(common.mill, 1);
create_test!(basic_kotlin.kt, 0);
+create_test!(basic.clj, 12);
// Checks that some comments are masked out
create_test!(ignore_comments.rs, 1);
diff --git a/harper-comments/tests/language_support_sources/basic.clj b/harper-comments/tests/language_support_sources/basic.clj
new file mode 100644
index 000000000..bf233632d
--- /dev/null
+++ b/harper-comments/tests/language_support_sources/basic.clj
@@ -0,0 +1,82 @@
+(ns clean
+ "It is actually possible to document a ns.
+ It's a nice place to describe the purpose of the namespace and maybe even
+ the overall conventions used. Note how _not_ indenting the docstring makes
+ it easier for tooling to display it correctly.")
+
+;;;; Section Comment/Heading
+
+;;; Foo...
+;;; Bar...
+;;; Baz...
+
+;; good
+(defn foo
+ "This funtion doesn't do much."
+ []
+ nil)
+
+;; bad
+(defn bar
+ ^{:doc "This function doesn't do much."}
+ []
+ nil)
+
+;; good
+(defn qzuf-number
+ "Computes the [Qzuf number](https://wikipedia.org/qzuf) of the `coll`.
+ Supported options in `opts`:
+
+ | key | description |
+ | --------------|-------------|
+ | `:finite-uni?`| Assume finite universe; default: `false`
+ | `:complex?` | If OK to return a [complex number](https://en.wikipedia.org/wiki/Complex_number); default: `false`
+ | `:timeout` | Throw an exception if the computation doesn't finish within `:timeout` milliseconds; default: `nil`
+
+ Example:
+ ```clojure
+ (when (neg? (qzuf-number [1 2 3] {:finite-uni? true}))
+ (throw (RuntimeException. \"Error in the Universe!\")))
+ ```"
+ [coll opts]
+ nil)
+
+(defprotocol MyProtocol
+ "MyProtocol docstring"
+ (foo [this x y z]
+ "foo docstring")
+ (bar [this]
+ "bar docstring"))
+
+;; good
+(defn some-fun
+ []
+ ;; FIXME: This has crashed occasionally since v1.2.3. It may
+ ;; be related to the BarBazUtil upgrade. (xz 13-1-31)
+ #_(baz))
+
+;;;; Frob Grovel
+
+;;; This section of code has some important implications:
+;;; 1. Foo.
+;;; 2. Bar.
+;;; 3. Baz.
+
+(defn fnord [zarquon]
+ ;; If zob, then veeblefitz.
+ (quux zot
+ mumble ; Zibblefrotz.
+ frotz))
+
+(defn foo [x]
+ x ; I'm a line/code fragment comment.
+ )
+
+;;; I'm a top-level comment.
+;;; I live outside any definition.
+
+(defn foo [])
+
+(def ^{:deprecated "0.5"} foo
+ "Use `bar` instead."
+ 42)
diff --git a/packages/vscode-plugin/package.json b/packages/vscode-plugin/package.json
index 28d5695aa..47a458f2b 100644
--- a/packages/vscode-plugin/package.json
+++ b/packages/vscode-plugin/package.json
@@ -53,7 +53,8 @@
"onLanguage:toml",
"onLanguage:typescript",
"onLanguage:typescriptreact",
- "onLanguage:typst"
+ "onLanguage:typst",
+ "onLanguage:clojure"
],
"main": "./build/extension.js",
"contributes": {
diff --git a/packages/web/src/routes/docs/integrations/language-server/+page.md b/packages/web/src/routes/docs/integrations/language-server/+page.md
index e70ac102b..d429db031 100644
--- a/packages/web/src/routes/docs/integrations/language-server/+page.md
+++ b/packages/web/src/routes/docs/integrations/language-server/+page.md
@@ -289,6 +289,7 @@ These configs are under the `markdown` key:
| TypeScript React | `typescriptreact` | ✅ |
| Typst | `typst` | |
| Kotlin | `kotlin` | ✅ |
+| Clojure | `clojure` | ✅ |
Want your language added?
Let us know by [commenting on this issue](https://github.com/Automattic/harper/issues/79).