From 3f0b22ca1967704ceca6b5c5d13d97341c1221a3 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Fri, 2 Jun 2017 18:33:05 -0600 Subject: [PATCH 1/4] Add support for multi-line types in jsdoc. --- grammars/jsdoc.cson | 9 ++++----- spec/jsdoc-spec.coffee | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/grammars/jsdoc.cson b/grammars/jsdoc.cson index 1cb84a2a..e546c079 100644 --- a/grammars/jsdoc.cson +++ b/grammars/jsdoc.cson @@ -410,6 +410,10 @@ } ] } + { + 'match': '^\\s*\\*(?!/)' + 'name': 'comment.block.documentation.jsdoc' + } ] 'inline-tags': 'patterns': [ @@ -483,11 +487,6 @@ # {type} 'type': 'patterns': [ - { - # {unclosed - 'match': '\\G{(?:[^}*]|\\*[^/}])+$' - 'name': 'invalid.illegal.type.jsdoc' - } { 'begin': '\\G({)' 'beginCaptures': diff --git a/spec/jsdoc-spec.coffee b/spec/jsdoc-spec.coffee index 6163992d..800d8ad3 100644 --- a/spec/jsdoc-spec.coffee +++ b/spec/jsdoc-spec.coffee @@ -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 */') + 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'] From 185648b27057b445a0c1af8e3bd615c968dab25d Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Thu, 8 Jun 2017 08:21:41 -0600 Subject: [PATCH 2/4] Update spec to use tokenizeLines --- spec/jsdoc-spec.coffee | 56 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/spec/jsdoc-spec.coffee b/spec/jsdoc-spec.coffee index 800d8ad3..2d2e34e5 100644 --- a/spec/jsdoc-spec.coffee +++ b/spec/jsdoc-spec.coffee @@ -936,11 +936,16 @@ 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 */') - 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'] + 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/) + 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'] @@ -950,21 +955,32 @@ describe "JSDoc grammar", -> 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'] + 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} */') From bc1c3577edd68630aaac9bed472c149cbd20fdb1 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Tue, 27 Jun 2017 16:03:03 -0600 Subject: [PATCH 3/4] Update scope for comment continuations --- grammars/jsdoc.cson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammars/jsdoc.cson b/grammars/jsdoc.cson index e546c079..fd30453a 100644 --- a/grammars/jsdoc.cson +++ b/grammars/jsdoc.cson @@ -412,7 +412,7 @@ } { 'match': '^\\s*\\*(?!/)' - 'name': 'comment.block.documentation.jsdoc' + 'name': 'punctuation.section.continuation.comment.js' } ] 'inline-tags': From 541392a14a04d1a5e15258bdd345ca149c9a44d0 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Tue, 11 Jul 2017 16:59:27 -0600 Subject: [PATCH 4/4] Fix test --- spec/jsdoc-spec.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/jsdoc-spec.coffee b/spec/jsdoc-spec.coffee index 2d2e34e5..acd2fb8b 100644 --- a/spec/jsdoc-spec.coffee +++ b/spec/jsdoc-spec.coffee @@ -964,10 +964,10 @@ describe "JSDoc grammar", -> """) 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][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', 'comment.block.documentation.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']