From d64a27da9564f241af8f2f7bf63c32ca898ec1f2 Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Fri, 23 Sep 2016 10:59:18 +0100 Subject: [PATCH 1/4] :bug: Add JSDoc support for function return type --- grammars/javascript.cson | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grammars/javascript.cson b/grammars/javascript.cson index 352e20bf..2c2704e5 100644 --- a/grammars/javascript.cson +++ b/grammars/javascript.cson @@ -1911,8 +1911,8 @@ )? \\s* \\) - )? - | + (?:\\s*:\\s*[a-zA-Z_$]+\\s*)? # {function(): string} function return type + )? | (?: \\( # Opening bracket of multiple types with parenthesis {(string|number)} [a-zA-Z_$]+ @@ -2029,8 +2029,8 @@ )? \\s* \\) - )? - | + (?:\\s*:\\s*[a-zA-Z_$]+\\s*)? # {function(): string} function return type + )? | (?: \\( # Opening bracket of multiple types with parenthesis {(string|number)} [a-zA-Z_$]+ From 76fda8f204a9b125448d34c8bd3ce46f3c6fa8cb Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Fri, 23 Sep 2016 11:02:25 +0100 Subject: [PATCH 2/4] :white_check_mark: Add specs for JSDoc function return type support --- spec/javascript-spec.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/javascript-spec.coffee b/spec/javascript-spec.coffee index 2be5b6d6..0507ba93 100644 --- a/spec/javascript-spec.coffee +++ b/spec/javascript-spec.coffee @@ -1999,6 +1999,17 @@ describe "JavaScript grammar", -> expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc'] expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + {tokens} = grammar.tokenizeLine('/** @param {function():number} variable this is the description */') + expect(tokens[4]).toEqual value: '{function():number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc'] + expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + + {tokens} = grammar.tokenizeLine('/** @param {function(string): number} variable this is the description */') + expect(tokens[4]).toEqual value: '{function(string): number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc'] + expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + + {tokens} = grammar.tokenizeLine('/** @return {object} this is the description */') expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] @@ -2039,6 +2050,14 @@ describe "JavaScript grammar", -> expect(tokens[4]).toEqual value: '{function(string, number)}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + {tokens} = grammar.tokenizeLine('/** @return {function():number} this is the description */') + expect(tokens[4]).toEqual value: '{function():number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + + {tokens} = grammar.tokenizeLine('/** @return {function(string): number} this is the description */') + expect(tokens[4]).toEqual value: '{function(string): number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + it "tokenizes // comments", -> {tokens} = grammar.tokenizeLine('// comment') expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js'] From 6dc401534f012f10b416e8ae26c8e9ddfb13e9d1 Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Tue, 1 Nov 2016 15:18:53 +0000 Subject: [PATCH 3/4] :art: Refactor for clarity --- grammars/javascript.cson | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/grammars/javascript.cson b/grammars/javascript.cson index 2c2704e5..78c82e1c 100644 --- a/grammars/javascript.cson +++ b/grammars/javascript.cson @@ -1911,8 +1911,12 @@ )? \\s* \\) - (?:\\s*:\\s*[a-zA-Z_$]+\\s*)? # {function(): string} function return type - )? | + (?: # {function(): string} function return type + \\s*:\\s* + [a-zA-Z_$][\\w$]* + )? + )? + | (?: \\( # Opening bracket of multiple types with parenthesis {(string|number)} [a-zA-Z_$]+ @@ -2029,8 +2033,12 @@ )? \\s* \\) - (?:\\s*:\\s*[a-zA-Z_$]+\\s*)? # {function(): string} function return type - )? | + (?: # {function(): string} function return type + \\s*:\\s* + [a-zA-Z_$][\\w$]* + )? + )? + | (?: \\( # Opening bracket of multiple types with parenthesis {(string|number)} [a-zA-Z_$]+ From 2e551b88d6270f7c20ea99173e989069b3f9dd7a Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Tue, 1 Nov 2016 15:51:50 +0000 Subject: [PATCH 4/4] :white_check_mark: Add extra tests to spec --- spec/javascript-spec.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/javascript-spec.coffee b/spec/javascript-spec.coffee index 0507ba93..392e78d4 100644 --- a/spec/javascript-spec.coffee +++ b/spec/javascript-spec.coffee @@ -2009,6 +2009,10 @@ describe "JavaScript grammar", -> expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc'] expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + {tokens} = grammar.tokenizeLine('/** @param {function(string) : number} variable this is the description */') + expect(tokens[4]).toEqual value: '{function(string) : number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc'] + expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] {tokens} = grammar.tokenizeLine('/** @return {object} this is the description */') expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] @@ -2058,6 +2062,10 @@ describe "JavaScript grammar", -> expect(tokens[4]).toEqual value: '{function(string): number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + {tokens} = grammar.tokenizeLine('/** @return {function(string) : number} this is the description */') + expect(tokens[4]).toEqual value: '{function(string) : number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc'] + expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc'] + it "tokenizes // comments", -> {tokens} = grammar.tokenizeLine('// comment') expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']