Skip to content

Commit 270ab67

Browse files
authored
Merge pull request #2 from markwpearce/feature/allow_annotations
Feature/allow annotations
2 parents 0acd831 + 035a2cc commit 270ab67

File tree

6 files changed

+1939
-83
lines changed

6 files changed

+1939
-83
lines changed

convert-brighterscript-docs.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ function paramOrReturnDescriptionHelper(desc = "") {
9191

9292
/**
9393
* Finds the comment that ends the line above the given statement
94+
* If the statement has annotations, the comment should be BEFORE the annotations
9495
*
9596
* @param {bs.CommentStatement[]} comments List of comments to search
9697
* @param {bs.Statement} stmt The statement in question
9798
* @returns {bs.CommentStatement} the correct comment, if found, otherwise undefined
9899
*/
99100
function getCommentForStatement(comments, stmt) {
100101
return comments.find((comment) => {
101-
return comment.range.end.line + 1 === stmt.range.start.line
102+
const commentEndLine = comment.range.end.line;
103+
let targetStartLine = stmt.range.start.line
104+
if (stmt.annotations && stmt.annotations.length > 0) {
105+
targetStartLine = stmt.annotations[0].range.start.line;
106+
}
107+
return commentEndLine + 1 === targetStartLine || commentEndLine === stmt.range.start.line
102108
})
103109
}
104110

examples/source/TestCustomTypes.bs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
class MyClass
22
end class
33

4+
45
class CustomTypesTest
56

67
someProp as MyClass
8+
'
9+
710

11+
'
12+
'
13+
' @param {MyClass} klass
14+
' @return {MyClass}
815
function someFunc(klass as MyClass) as MyClass
9-
return klass
16+
k = "hello"
17+
j = 0
18+
jj = j + k
19+
1020
end function
1121
end class

examples/source/TestDecorators.bs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
' Comments should go before annotations and decorators
4+
'
5+
' @param {string} param1 A no op value
6+
' @return {string} whatever was included as param1
7+
@someDecorator("func")
8+
function funcWithDecorator(param1 as string) as string
9+
return param1
10+
end function
11+
12+
' Description of the class - this is before the annotation
13+
@someDecorator("class")
14+
class DecoratorsTestKlass
15+
16+
@someDecorator("property")
17+
property as float = 3.14 ' yum, pi!
18+
19+
' Member function comments come before decorators
20+
'
21+
' @param {} num
22+
' @return {string}
23+
@someDecorator({"method"})
24+
function someFunc(num) as string
25+
return `hello ${num}`
26+
end function
27+
end class

examples/source/TestKlass.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace TestDoc
5858

5959
' Test comment overriding parser
6060
' @param {TestKlass} klass an actual klass name in the comments
61-
function testCommentsWithClasses(klass) as object
61+
function testCommentsWithClasses(klass = {} as MyClass) as MyClass
6262
return klass
6363
end function
6464

0 commit comments

Comments
 (0)