Skip to content

Commit 12f0eed

Browse files
committed
Fix extractor logic and tests
1 parent 007c6cf commit 12f0eed

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

test-crawler/crawler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ func TestCrawlSingleFileForFunctions(t *testing.T) {
2121
t.Errorf("got %q, expected %q methods", len(fnsAnn), 2)
2222
}
2323

24-
assert.Equal(t, "", fnsAnn[0].Description)
24+
assert.Equal(t, "// HelloEvent simple method that just formats message.", fnsAnn[0].Description)
2525
assert.Equal(t, "HelloEvent", fnsAnn[0].Name)
2626
assert.Equal(t, "()", fnsAnn[0].InputParams) // input param
2727
assert.Equal(t, "string", fnsAnn[0].ReturnValues) // return param
2828

29-
assert.Equal(t, "", fnsAnn[1].Description)
29+
assert.Equal(t, "// HelloEventWithParameter accepts one param that got formated in message.", fnsAnn[1].Description)
3030
assert.Equal(t, "HelloEventWithParameter", fnsAnn[1].Name)
3131
assert.Equal(t, "(param string)", fnsAnn[1].InputParams)
3232
assert.Equal(t, "(string, error)", fnsAnn[1].ReturnValues)
3333

34-
assert.Equal(t, "", fnsAnn[2].Description)
34+
assert.Equal(t, "// FunctionWithoutParameters...", fnsAnn[2].Description)
3535
assert.Equal(t, "FunctionWithoutParameters", fnsAnn[2].Name)
3636
assert.Equal(t, "()", fnsAnn[2].InputParams)
3737
assert.Equal(t, "", fnsAnn[2].ReturnValues)
3838

39-
assert.Equal(t, "", fnsAnn[3].Description)
39+
assert.Equal(t, "// FunctionWithPointerReturnValue returns a simple pointer value.", fnsAnn[3].Description)
4040
assert.Equal(t, "FunctionWithPointerReturnValue", fnsAnn[3].Name)
4141
assert.Equal(t, "()", fnsAnn[3].InputParams)
4242
assert.Equal(t, "*Event", fnsAnn[3].ReturnValues)

test-crawler/extractor/extractor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ func getFunctionNodes(content string, treeCursor *sitter.TreeCursor, parser *a.P
260260
child.Child(4): parameter_list: (<-chan *types2.RequestEvent, error)
261261
*/
262262
if child.Type() == string(METHOD_DECLARATION) {
263+
comment := content[prevNode.StartByte():prevNode.EndByte()]
263264
if prevNode.Type() == string(COMMENT) {
264-
value, annotationType, _ := parser.Parse(content[prevNode.StartByte():prevNode.EndByte()])
265+
value, annotationType, _ := parser.Parse(comment)
265266
if value != nil && annotationType == a.Ignore {
266267
isIgnored = value.(bool)
267268
}
@@ -288,6 +289,7 @@ func getFunctionNodes(content string, treeCursor *sitter.TreeCursor, parser *a.P
288289
funcAnnoPair = append(funcAnnoPair, FunctionAnnotationNode{
289290
Node: child,
290291
Function: c.FunctionAnnotation{
292+
Description: comment,
291293
Name: funcName,
292294
Public: isPublic(funcName),
293295
InputParams: params,

0 commit comments

Comments
 (0)