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

Add support for multi-line types in jsdoc. #515

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions grammars/jsdoc.cson
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@
}
]
}
{
'match': '^\\s*\\*(?!/)'
'name': 'punctuation.section.continuation.comment.js'
}
]
'inline-tags':
'patterns': [
Expand Down Expand Up @@ -487,11 +491,6 @@
# {type}
'type':
'patterns': [
{
# {unclosed
'match': '\\G{(?:[^}*]|\\*[^/}])+$'
'name': 'invalid.illegal.type.jsdoc'
}
{
'begin': '\\G({)'
'beginCaptures':
Expand Down
46 changes: 46 additions & 0 deletions spec/jsdoc-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,52 @@ describe "JSDoc grammar", ->
expect(tokens[7]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.end.jsdoc']
expect(tokens[9]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'variable.other.jsdoc']

lines = grammar.tokenizeLines("""
/** @param {
number
} variable this is the description */
""")
expect(lines[0][5]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.begin.jsdoc']
expect(lines[1][0].value).toMatch(/number/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use the .toEqual style? Same on L1177.

expect(lines[1][0].scopes).toEqual ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(lines[2][1]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.end.jsdoc']
expect(lines[2][3]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'variable.other.jsdoc']

{tokens} = grammar.tokenizeLine('/** @param {{number}} variable this is the description */')
expect(tokens[5]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.begin.jsdoc']
expect(tokens[6]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(tokens[7]).toEqual value: 'number', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(tokens[8]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(tokens[9]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.end.jsdoc']
expect(tokens[11]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'variable.other.jsdoc']

lines = grammar.tokenizeLines("""
/**
* @param {{
* number
* }} variable this is the description
*/
""")
expect(lines[1][4]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.begin.jsdoc']
expect(lines[1][5]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(lines[2][0]).toEqual value: ' *', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.section.continuation.comment.js']
expect(lines[2][1].value).toMatch(/number/)
expect(lines[2][1].scopes).toEqual ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(lines[3][0]).toEqual value: ' *', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.section.continuation.comment.js']
expect(lines[3][2]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(lines[3][3]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.end.jsdoc']
expect(lines[3][5]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'variable.other.jsdoc']

lines = grammar.tokenizeLines("""
/** @param {{
*/ foo
""")
{tokens} = grammar.tokenizeLine('/')
expect(lines[0][5]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.begin.jsdoc']
expect(lines[0][6]).toEqual value: '{', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(lines[1][1]).toEqual value: '*/', scopes: ['source.js', 'comment.block.documentation.js', 'punctuation.section.end.comment.js']
expect(lines[1][2]).toEqual value: ' foo', scopes: ['source.js']

it "tokenises @return tags without descriptions", ->
{tokens} = grammar.tokenizeLine('/** @return {object} */')
expect(tokens[0]).toEqual value: '/**', scopes: ['source.js', 'comment.block.documentation.js', 'punctuation.section.begin.comment.js']
Expand Down