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 2 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 @@ -410,6 +410,10 @@
}
]
}
{
'match': '^\\s*\\*(?!/)'
'name': 'comment.block.documentation.jsdoc'

Choose a reason for hiding this comment

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

Comment. #114

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what you mean. Do you want me to add a comment describing this rule? I don't see what this has to do with issue 114.

Copy link
Contributor

Choose a reason for hiding this comment

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

We occasionally get spammers due to the popularity of the Atom project. I think this comment is safe to ignore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong scope-name. It should be punctuation.section.continuation.comment.js, or at least just punctuation.section.comment.js. See here.

But this pattern isn't enclosing any content of its own, so it's incorrect to scope it as a comment.

}
]
'inline-tags':
'patterns': [
Expand Down Expand Up @@ -483,11 +487,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 @@ -936,6 +936,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', 'comment.block.documentation.jsdoc']
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', 'comment.block.documentation.jsdoc']
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