Skip to content

Commit

Permalink
Add syntax highlighting support for bsdoc tags (#586)
Browse files Browse the repository at this point in the history
* Add syntax highlighting support for bsdoc tags

* Support multiple single quotes in a row

* Fix @param and @type color
  • Loading branch information
TwitchBronBron authored Sep 6, 2024
1 parent 1e0495d commit 805d59d
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
121 changes: 121 additions & 0 deletions src/grammar/brightscript.tmLanguage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ describe('brightscript.tmlanguage.json', () => {
`);
});

/**
* @param test comment 123
*/

it('handles comments following interface fields', async () => {
await testGrammar(`
interface Person
Expand Down Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions syntaxes/brightscript.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
{
"include": "#regex"
},
{
"include": "#bsdoc"
},
{
"include": "#if_with_paren"
},
Expand Down Expand Up @@ -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": [
{
Expand Down

0 comments on commit 805d59d

Please sign in to comment.