Skip to content
This repository was 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 1 commit
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
30 changes: 30 additions & 0 deletions spec/jsdoc-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,36 @@ 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']

{tokens} = grammar.tokenizeLine('/** @param {\nnumber\n} variable this is the description */')
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using \n, could you please use grammar.tokenizeLines and multiline quotes? See https://github.com/atom/language-javascript/blob/master/spec/jsdoc-spec.coffee#L1300 for an example.

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: '\nnumber\n', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
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']

{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']

{tokens} = grammar.tokenizeLine('/** @param {{\n * number\n * }} 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[8]).toEqual value: ' *', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'comment.block.documentation.jsdoc']
expect(tokens[9]).toEqual value: ' number\n', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(tokens[10]).toEqual value: ' *', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'comment.block.documentation.jsdoc']
expect(tokens[12]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc']
expect(tokens[13]).toEqual value: '}', scopes: ['source.js', 'comment.block.documentation.js', 'entity.name.type.instance.jsdoc', 'punctuation.definition.bracket.curly.end.jsdoc']
expect(tokens[15]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'variable.other.jsdoc']

{tokens} = grammar.tokenizeLine('/** @param {{\n */ foo')
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[8]).toEqual value: '*/', scopes: ['source.js', 'comment.block.documentation.js', 'punctuation.section.end.comment.js']
expect(tokens[9]).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