Skip to content

Commit 814ba9c

Browse files
feat: add clojure support (#1520)
* feat: add `clojure` support * test: add clojure example file * feat: add support for more clojure dialect filetypes * fix(comments): give test more descriptive name --------- Co-authored-by: Elijah Potter <[email protected]>
1 parent 21888aa commit 814ba9c

File tree

7 files changed

+101
-1
lines changed

7 files changed

+101
-1
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harper-comments/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tree-sitter-swift = "0.7.1"
3535
tree-sitter-toml-ng = "0.7.0"
3636
tree-sitter-typescript = "0.23.2"
3737
harper-tree-sitter-dart = "0.0.5"
38+
tree-sitter-clojure = "0.1.0"
3839

3940
[dev-dependencies]
4041
paste = "1.0.15"

harper-comments/src/comment_parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl CommentParser {
4646
"toml" => tree_sitter_toml_ng::LANGUAGE,
4747
"typescriptreact" => tree_sitter_typescript::LANGUAGE_TSX,
4848
"typescript" => tree_sitter_typescript::LANGUAGE_TYPESCRIPT,
49+
"clojure" => tree_sitter_clojure::LANGUAGE,
4950
_ => return None,
5051
};
5152

@@ -105,6 +106,7 @@ impl CommentParser {
105106
"toml" => "toml",
106107
"ts" => "typescript",
107108
"tsx" => "typescriptreact",
109+
"clj" | "cljs" | "cljc" | "bb" => "clojure",
108110
_ => return None,
109111
})
110112
}

harper-comments/tests/language_support.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ create_test!(ignore_shebang_3.sh, 0);
5858
create_test!(ignore_shebang_4.sh, 1);
5959
create_test!(common.mill, 1);
6060
create_test!(basic_kotlin.kt, 0);
61+
create_test!(basic.clj, 12);
6162

6263
// Checks that some comments are masked out
6364
create_test!(ignore_comments.rs, 1);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(ns clean
2+
"It is actually possible to document a ns.
3+
It's a nice place to describe the purpose of the namespace and maybe even
4+
the overall conventions used. Note how _not_ indenting the docstring makes
5+
it easier for tooling to display it correctly.")
6+
7+
;;;; Section Comment/Heading
8+
9+
;;; Foo...
10+
;;; Bar...
11+
;;; Baz...
12+
13+
;; good
14+
(defn foo
15+
"This funtion doesn't do much."
16+
[]
17+
nil)
18+
19+
;; bad
20+
(defn bar
21+
^{:doc "This function doesn't do much."}
22+
[]
23+
nil)
24+
25+
;; good
26+
(defn qzuf-number
27+
"Computes the [Qzuf number](https://wikipedia.org/qzuf) of the `coll`.
28+
Supported options in `opts`:
29+
30+
| key | description |
31+
| --------------|-------------|
32+
| `:finite-uni?`| Assume finite universe; default: `false`
33+
| `:complex?` | If OK to return a [complex number](https://en.wikipedia.org/wiki/Complex_number); default: `false`
34+
| `:timeout` | Throw an exception if the computation doesn't finish within `:timeout` milliseconds; default: `nil`
35+
36+
Example:
37+
```clojure
38+
(when (neg? (qzuf-number [1 2 3] {:finite-uni? true}))
39+
(throw (RuntimeException. \"Error in the Universe!\")))
40+
```"
41+
[coll opts]
42+
nil)
43+
44+
(defprotocol MyProtocol
45+
"MyProtocol docstring"
46+
(foo [this x y z]
47+
"foo docstring")
48+
(bar [this]
49+
"bar docstring"))
50+
51+
;; good
52+
(defn some-fun
53+
[]
54+
;; FIXME: This has crashed occasionally since v1.2.3. It may
55+
;; be related to the BarBazUtil upgrade. (xz 13-1-31)
56+
#_(baz))
57+
58+
;;;; Frob Grovel
59+
60+
;;; This section of code has some important implications:
61+
;;; 1. Foo.
62+
;;; 2. Bar.
63+
;;; 3. Baz.
64+
65+
(defn fnord [zarquon]
66+
;; If zob, then veeblefitz.
67+
(quux zot
68+
mumble ; Zibblefrotz.
69+
frotz))
70+
71+
(defn foo [x]
72+
x ; I'm a line/code fragment comment.
73+
)
74+
75+
;;; I'm a top-level comment.
76+
;;; I live outside any definition.
77+
78+
(defn foo [])
79+
80+
(def ^{:deprecated "0.5"} foo
81+
"Use `bar` instead."
82+
42)

packages/vscode-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"onLanguage:toml",
5454
"onLanguage:typescript",
5555
"onLanguage:typescriptreact",
56-
"onLanguage:typst"
56+
"onLanguage:typst",
57+
"onLanguage:clojure"
5758
],
5859
"main": "./build/extension.js",
5960
"contributes": {

packages/web/src/routes/docs/integrations/language-server/+page.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ These configs are under the `markdown` key:
289289
| TypeScript React | `typescriptreact` ||
290290
| Typst | `typst` | |
291291
| Kotlin | `kotlin` ||
292+
| Clojure | `clojure` ||
292293

293294
Want your language added?
294295
Let us know by [commenting on this issue](https://github.com/Automattic/harper/issues/79).

0 commit comments

Comments
 (0)