Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 3c1dc51

Browse files
author
Max Brunsfeld
authored
Merge pull request #629 from atom/mb-add-jsdoc
Add JSDoc injection w/ tree-sitter-jsdoc
2 parents 5aa901b + 7a37772 commit 3c1dc51

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

grammars/tree-sitter-javascript.cson

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parser: 'tree-sitter-javascript'
55

66
fileTypes: ['js', 'jsx']
77

8-
injectionRegex: 'js|javascript'
8+
injectionRegex: '^js$|^JS$|javascript|JavaScript'
99

1010
firstLineRegex: [
1111
# shebang line

grammars/tree-sitter-jsdoc.cson

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'JSDoc'
2+
scopeName: 'source.jsdoc'
3+
type: 'tree-sitter'
4+
parser: 'tree-sitter-jsdoc'
5+
6+
injectionRegex: '^jsdoc$'
7+
8+
scopes:
9+
'tag_name': 'keyword.control'
10+
'identifier': 'variable.other.jsdoc'
11+
'type': 'support.type'
12+
'path_expression > identifier': 'string'
13+
'"."': 'meta.delimiter.period'
14+
'":"': 'meta.delimiter.colon'
15+
'"/"': 'meta.delimiter.slash'
16+
'"#", "~"': 'meta.delimiter'

lib/main.js

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ exports.activate = function () {
4949
language (regex) { return 'regex' },
5050
content (regex) { return regex }
5151
})
52+
53+
for (const scopeName of ['source.js', 'source.flow', 'source.ts']) {
54+
atom.grammars.addInjectionPoint(scopeName, {
55+
type: 'comment',
56+
language (comment) {
57+
if (comment.text.startsWith('/**')) return 'jsdoc'
58+
},
59+
content (comment) {
60+
return comment
61+
}
62+
})
63+
}
5264
}
5365

5466
const STYLED_REGEX = /\bstyled\b/i

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"dependencies": {
2626
"tree-sitter-javascript": "^0.13.8",
27+
"tree-sitter-jsdoc": "^0.13.4",
2728
"tree-sitter-regex": "^0.13.1"
2829
}
2930
}

0 commit comments

Comments
 (0)