MCPcopy Index your code
hub / github.com/google/go-github / visitFileMethods

Function visitFileMethods

tools/metadata/metadata.go:382–429  ·  view source on GitHub ↗
(updateFile bool, filename string, visit nodeVisitor)

Source from the content-addressed store, hash-verified

380}
381
382func visitFileMethods(updateFile bool, filename string, visit nodeVisitor) error {
383 content, err := os.ReadFile(filename)
384 if err != nil {
385 return err
386 }
387 content = bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n"))
388
389 fset := token.NewFileSet()
390 fileNode, err := parser.ParseFile(fset, "", content, parser.ParseComments)
391 if err != nil {
392 return err
393 }
394 cmap := ast.NewCommentMap(fset, fileNode, fileNode.Comments)
395
396 ast.Inspect(fileNode, func(n ast.Node) bool {
397 fn, ok := n.(*ast.FuncDecl)
398 if !ok {
399 return true
400 }
401 serviceMethod := nodeServiceMethod(fn)
402 if serviceMethod == "" {
403 return true
404 }
405 e := visit(serviceMethod, fn, cmap)
406 err = errors.Join(err, e)
407 return true
408 })
409 if err != nil {
410 return err
411 }
412 if !updateFile {
413 return nil
414 }
415 fileNode.Comments = cmap.Filter(fileNode).Comments()
416 var buf bytes.Buffer
417 err = printer.Fprint(&buf, fset, fileNode)
418 if err != nil {
419 return err
420 }
421 updatedContent, err := format.Source(buf.Bytes())
422 if err != nil {
423 return err
424 }
425 if bytes.Equal(content, updatedContent) {
426 return nil
427 }
428 return os.WriteFile(filename, updatedContent, 0o600)
429}
430
431var (
432 metaOpRe = regexp.MustCompile(`(?i)\s*//\s*meta:operation\s+(\S.+)`)

Callers 1

visitServiceMethodsFunction · 0.85

Calls 2

nodeServiceMethodFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…