Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syntax highlighting support for bsdoc tags #586

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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