From 16ecdbba950678028cbc033b6c0eb3d9d3317465 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 6 Sep 2024 09:41:06 -0400 Subject: [PATCH 1/3] Add syntax highlighting support for bsdoc tags --- src/grammar/brightscript.tmLanguage.spec.ts | 121 ++++++++++++++++++++ syntaxes/brightscript.tmLanguage.json | 59 ++++++++++ 2 files changed, 180 insertions(+) diff --git a/src/grammar/brightscript.tmLanguage.spec.ts b/src/grammar/brightscript.tmLanguage.spec.ts index df7d9327..08e28166 100644 --- a/src/grammar/brightscript.tmLanguage.spec.ts +++ b/src/grammar/brightscript.tmLanguage.spec.ts @@ -224,6 +224,10 @@ describe('brightscript.tmlanguage.json', () => { `); }); + /** + * @param test comment 123 + */ + it('handles comments following interface fields', async () => { await testGrammar(` interface Person @@ -254,6 +258,123 @@ describe('brightscript.tmlanguage.json', () => { `); }); + describe('bsdoc', () => { + //the grammar tester doesn't like testing standalone comments, so prefix all of the testable lines of code in this block with a single `t` identifier + + it('colorizes generic tags correctly', async () => { + await testGrammar(` + t'@unknownparam just comments + ' ^^^^^^^^^^^^^ comment.block.documentation.brs + ' ^^^^^^^^^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + /** + * @param p1 comment one + * @param {string} p1 comment one + */ + it('colorizes @param without type', async () => { + await testGrammar(` + t'@param p1 + ' ^^ variable.other.bsdoc + ' ^^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param', async () => { + await testGrammar(` + t'@param {boolean} p1 + ' ^^ variable.other.bsdoc + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param without name', async () => { + await testGrammar(` + t'@param {boolean} + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param with comment', async () => { + await testGrammar(` + t'@param {boolean} p1 this is a comment + ' ^^^^^^^^^^^^^^^^^ comment.block.documentation.brs + ' ^^ variable.other.bsdoc + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @type without type', async () => { + await testGrammar(` + t'@type p1 + ' ^^ variable.other.bsdoc + ' ^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param', async () => { + await testGrammar(` + t'@type {boolean} p1 + ' ^^ variable.other.bsdoc + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param without name', async () => { + await testGrammar(` + t'@type {boolean} + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + it('colorizes @param with comment', async () => { + await testGrammar(` + t'@type {boolean} p1 this is a comment + ' ^^^^^^^^^^^^^^^^^ comment.block.documentation.brs + ' ^^ variable.other.bsdoc + ' ^ punctuation.definition.bracket.curly.end.bsdoc + ' ^^^^^^^ entity.name.type.instance.bsdoc + ' ^ punctuation.definition.bracket.curly.begin.bsdoc + ' ^^^^ storage.type.class.bsdoc + ' ^ storage.type.class.bsdoc + '^ comment.line.apostrophe.brs + `); + }); + + }); + it.skip('handles `as Function` parameters properly', async () => { await testGrammar(` function getStyle(builderFunc as Function, processorFunc as Function) as object diff --git a/syntaxes/brightscript.tmLanguage.json b/syntaxes/brightscript.tmLanguage.json index cb841980..3f68a14b 100644 --- a/syntaxes/brightscript.tmLanguage.json +++ b/syntaxes/brightscript.tmLanguage.json @@ -19,6 +19,9 @@ { "include": "#regex" }, + { + "include": "#bsdoc" + }, { "include": "#if_with_paren" }, @@ -997,6 +1000,62 @@ "match": "('\\s*vscode_rale_tracker_entry[^\\S\\r\\n]*)", "name": "keyword.preprocessor.brs" }, + "bsdoc": { + "patterns": [ + { + "include": "#bsdoc_param_and_type" + }, + { + "include": "#bsdoc_generic" + } + ] + }, + "bsdoc_generic": { + "match": "(?i:\\s*(rem|')\\s*(@)(\\w+)(.*$))", + "captures": { + "1": { + "name": "comment.line.apostrophe.brs" + }, + "2": { + "name": "punctuation.definition.block.tag.bsdoc storage.type.class.bsdoc" + }, + "3": { + "name": "punctuation.definition.block.tag.bsdoc storage.type.class.bsdoc" + }, + "4": { + "name": "comment.block.documentation.brs" + } + } + }, + "bsdoc_param_and_type": { + "match": "(?i:\\s*(rem|')\\s*(@)(param|type)\\s*(?:(\\{)\\s*([^\\}]+)\\s*(\\}))?\\s*([a-z0-9_.]+)?(.*))", + "captures": { + "1": { + "name": "comment.line.apostrophe.brs" + }, + "2": { + "name": "punctuation.definition.block.tag.bsdoc storage.type.class.bsdoc" + }, + "3": { + "name": "punctuation.definition.block.tag.bsdoc storage.type.class.bsdoc" + }, + "4": { + "name": "punctuation.definition.bracket.curly.begin.bsdoc" + }, + "5": { + "name": " comment.block.documentation.brs entity.name.type.instance.bsdoc" + }, + "6": { + "name": "punctuation.definition.bracket.curly.end.bsdoc" + }, + "7": { + "name": "variable.other.bsdoc" + }, + "8": { + "name": "comment.block.documentation.brs" + } + } + }, "annotation": { "patterns": [ { From c7489e1487e07f9e26b729eae7e901b33d8586fa Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 6 Sep 2024 09:58:30 -0400 Subject: [PATCH 2/3] Support multiple single quotes in a row --- syntaxes/brightscript.tmLanguage.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntaxes/brightscript.tmLanguage.json b/syntaxes/brightscript.tmLanguage.json index 3f68a14b..fc341990 100644 --- a/syntaxes/brightscript.tmLanguage.json +++ b/syntaxes/brightscript.tmLanguage.json @@ -1011,7 +1011,7 @@ ] }, "bsdoc_generic": { - "match": "(?i:\\s*(rem|')\\s*(@)(\\w+)(.*$))", + "match": "(?i:\\s*(rem|'+)\\s*(@)(\\w+)(.*$))", "captures": { "1": { "name": "comment.line.apostrophe.brs" @@ -1028,7 +1028,7 @@ } }, "bsdoc_param_and_type": { - "match": "(?i:\\s*(rem|')\\s*(@)(param|type)\\s*(?:(\\{)\\s*([^\\}]+)\\s*(\\}))?\\s*([a-z0-9_.]+)?(.*))", + "match": "(?i:\\s*(rem|'+)\\s*(@)(param|type)\\s*(?:(\\{)\\s*([^\\}]+)\\s*(\\}))?\\s*([a-z0-9_.]+)?(.*))", "captures": { "1": { "name": "comment.line.apostrophe.brs" From e5a82612618cea0783a3a10a156abdccbf4c4130 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 6 Sep 2024 10:31:14 -0400 Subject: [PATCH 3/3] Fix @param and @type color --- syntaxes/brightscript.tmLanguage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntaxes/brightscript.tmLanguage.json b/syntaxes/brightscript.tmLanguage.json index fc341990..eae517a4 100644 --- a/syntaxes/brightscript.tmLanguage.json +++ b/syntaxes/brightscript.tmLanguage.json @@ -1028,7 +1028,7 @@ } }, "bsdoc_param_and_type": { - "match": "(?i:\\s*(rem|'+)\\s*(@)(param|type)\\s*(?:(\\{)\\s*([^\\}]+)\\s*(\\}))?\\s*([a-z0-9_.]+)?(.*))", + "match": "(?i:\\s*(rem|'+)\\s*(@)(param|type)\\s+(?:(\\{)\\s*([^\\}]+)\\s*(\\}))?\\s*([a-z0-9_.]+)?(.*))", "captures": { "1": { "name": "comment.line.apostrophe.brs"