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

Commit e60992f

Browse files
author
Wliu
authored
Merge pull request #411 from bgriffith/feature/jsdoc
Add improved JSDoc support for @returns
2 parents c4f7a5f + 2a24cc2 commit e60992f

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

grammars/javascript.cson

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,16 +1677,38 @@
16771677
'name': 'storage.type.class.jsdoc'
16781678
}
16791679
{
1680-
'match': '({(?:\\*|(?:\\?|\\!|\\.{3})?[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*)*(?:\\[\\])?=?)})\\s+(\\[(?:[a-zA-Z_$]+(?:=[\\w][\\s\\w$]*)?)\\]|(?:[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*)*))\\s*((?:(?!\\*\\/).)*)'
1680+
'match': '''(?x)
1681+
({(?:\\*|(?:\\?|\\!|\\.{3})?[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*)*(?:\\[\\])?=?)})
1682+
\\s+
1683+
(\\[(?:[a-zA-Z_$]+(?:=[\\w][\\s\\w$]*)?)\\]|(?:[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*)*))
1684+
\\s+
1685+
((?:(?!\\*\\/).)*)
1686+
'''
1687+
'captures':
1688+
'0':
1689+
'name': 'other.meta.jsdoc'
1690+
'1':
1691+
'name': 'entity.name.type.instance.jsdoc'
1692+
'2':
1693+
'name': 'variable.other.jsdoc'
1694+
'3':
1695+
'name': 'other.description.jsdoc'
1696+
}
1697+
{
1698+
'match': '''(?x)
1699+
(?:(?<=@returns)|(?<=@return))
1700+
\\s+
1701+
({(?:\\*|(?:\\?|\\!|\\.{3})?[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*)*(?:\\[\\])?=?)})
1702+
\\s+
1703+
((?:(?!\\*\\/).)*)
1704+
'''
16811705
'captures':
1682-
0:
1683-
'name': 'other.meta.jsdoc'
1684-
1:
1685-
'name': 'entity.name.type.instance.jsdoc'
1686-
2:
1687-
'name': 'variable.other.jsdoc'
1688-
3:
1689-
'name': 'other.description.jsdoc'
1706+
'0':
1707+
'name': 'other.meta.jsdoc'
1708+
'1':
1709+
'name': 'entity.name.type.instance.jsdoc'
1710+
'2':
1711+
'name': 'other.description.jsdoc'
16901712
}
16911713
]
16921714
'comments':

spec/javascript-spec.coffee

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,20 @@ describe "Javascript grammar", ->
15731573
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
15741574
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
15751575

1576+
{tokens} = grammar.tokenizeLine('/** @return {object} this is the description */')
1577+
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
1578+
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
1579+
1580+
{tokens} = grammar.tokenizeLine('/** @return {object} */')
1581+
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
1582+
1583+
{tokens} = grammar.tokenizeLine('/** @returns {object} this is the description */')
1584+
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
1585+
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
1586+
1587+
{tokens} = grammar.tokenizeLine('/** @returns {object} */')
1588+
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
1589+
15761590
it "tokenizes // comments", ->
15771591
{tokens} = grammar.tokenizeLine('// comment')
15781592
expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']

0 commit comments

Comments
 (0)