Skip to content

Commit e964764

Browse files
Remove single_file from config, create isPublic() helper function
1 parent b844dc1 commit e964764

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

test-crawler/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Config struct {
2121
Language string `yaml:"lang_mode"`
2222
IndentJSON bool `yaml:"indent_json"`
2323
Ignore []string `yaml:"ignore"`
24-
SingleFile string `yaml:"single_file"`
2524
}
2625

2726
const filename string = "config.yaml"

test-crawler/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ lang_mode: go
1010
indent_json: true
1111
# ignore paths
1212
ignore: ["extern"]
13-
single_file: ../repo-to-crawl/venus-gateway/proofevent/proof_event.go # for example, replace with different one

test-crawler/extractor/extractor.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,13 @@ func getFunctionNodes(content string, treeCursor *sitter.TreeCursor, parser *a.P
253253
policy *types2.ProofRegisterPolicy)
254254
(<-chan *types2.RequestEvent, error){...}
255255
*********
256-
First iteration through children nodes:
257-
Child.Type = method_declaration
258-
Child.Value = whole function body func(*x)(a,b)c{...}
259-
260-
child.Child(1) is a first part of function declaration, and has type of parameter_list: (e *ProofEventStream)
261-
child.Child(2): has type of field_identifier and represents function's name: ListenProofEvent
262-
child.Child(3): has type parameter_list and represents input parameters: (ctx context.Context, policy *types2.ProofRegisterPolicy)
263-
child.Child(4): has type parameter_list and represent return parameters: (<-chan *types2.RequestEvent, error)
256+
child.Child(1) is a first part of function declaration (e *ProofEventStream)
257+
child.Child(2): field_identifier 'ListenProofEvent'
258+
child.Child(3): parameter_list: (ctx context.Context, policy *types2.ProofRegisterPolicy)
259+
child.Child(4): parameter_list: (<-chan *types2.RequestEvent, error)
264260
*/
265261
if child.Type() == string(METHOD_DECLARATION) {
266262
funcName = content[child.Child(2).StartByte():child.Child(2).EndByte()]
267-
public := unicode.IsUpper(rune(funcName[0]))
268263
params := ""
269264
returnValues := ""
270265
if child.Child(1).Type() == string(PARAMETER_LIST) {
@@ -275,7 +270,7 @@ func getFunctionNodes(content string, treeCursor *sitter.TreeCursor, parser *a.P
275270
Node: child,
276271
Function: c.FunctionAnnotation{
277272
Name: funcName,
278-
Public: public,
273+
Public: isPublic(funcName),
279274
InputParams: params,
280275
ReturnValues: returnValues,
281276
},
@@ -381,3 +376,7 @@ func parseContentForFunctions(content string, cursor *sitter.TreeCursor) ([]c.Fu
381376

382377
return fnsAnno, nil
383378
}
379+
380+
func isPublic(funcName string) bool {
381+
return unicode.IsUpper(rune(funcName[0]))
382+
}

test-crawler/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func main() {
2626

2727
config := NewConfig()
2828

29-
// crawlRepoBehaviorsAndSaveToJSON(config)
30-
crawlSingleFileForMethods(config)
29+
crawlRepoBehaviorsAndSaveToJSON(config)
30+
crawlSingleFileForMethods("../repo-to-crawl/system/subsystem/file.go") // // ex: ../repo-to-crawl/venus-gateway/proofevent/proof_event.go
3131
}
3232

3333
func crawlRepoBehaviorsAndSaveToJSON(config Config) {
@@ -78,8 +78,10 @@ func crawlRepoBehaviorsAndSaveToJSON(config Config) {
7878
Save(result, config.OutputMode, config.OutputDir, config.IndentJSON)
7979
}
8080

81-
func crawlSingleFileForMethods(config Config) {
82-
fns, err := extractPublicMethodsFromFile(context.Background(), config.SingleFile)
81+
// crawlSingleFileForMethods accepts path of single go file,
82+
// and prints extracted methods out of it.
83+
func crawlSingleFileForMethods(path string) {
84+
fns, err := extractPublicMethodsFromFile(context.Background(), path)
8385
if err != nil {
8486
fmt.Print(err)
8587
os.Exit(1)

0 commit comments

Comments
 (0)