MCPcopy Create free account
hub / github.com/JordanCoin/codemap / extractFunctionName

Function extractFunctionName

scanner/astgrep.go:430–569  ·  view source on GitHub ↗
(text string, lang string)

Source from the content-addressed store, hash-verified

428}
429
430func extractFunctionName(text string, lang string) string {
431 text = strings.TrimSpace(text)
432
433 switch lang {
434 case "go":
435 // func Name(...) or func (r Receiver) Name(...)
436 if strings.HasPrefix(text, "func ") {
437 text = strings.TrimPrefix(text, "func ")
438 // Skip receiver if present
439 if strings.HasPrefix(text, "(") {
440 if idx := strings.Index(text, ")"); idx > 0 {
441 text = strings.TrimSpace(text[idx+1:])
442 }
443 }
444 // Get function name (up to paren)
445 if idx := strings.Index(text, "("); idx > 0 {
446 return text[:idx]
447 }
448 }
449
450 case "typescript", "javascript":
451 // function name(...) or async function name(...)
452 if strings.Contains(text, "function ") {
453 idx := strings.Index(text, "function ") + 9
454 text = text[idx:]
455 if paren := strings.Index(text, "("); paren > 0 {
456 return strings.TrimSpace(text[:paren])
457 }
458 }
459 // Method definitions: [modifiers] name(...) or get/set name(...)
460 if paren := strings.Index(text, "("); paren > 0 {
461 name := strings.TrimSpace(text[:paren])
462 // Strip TypeScript/JS modifiers
463 for _, mod := range []string{"public ", "private ", "protected ", "static ", "readonly ", "async ", "get ", "set ", "override "} {
464 name = strings.TrimPrefix(name, mod)
465 }
466 // Skip control flow keywords
467 if name == "if" || name == "for" || name == "while" || name == "switch" || name == "catch" || name == "" {
468 return ""
469 }
470 if isValidIdentifier(name) {
471 return name
472 }
473 }
474
475 case "python":
476 // def name(...):
477 if strings.HasPrefix(text, "def ") {
478 text = strings.TrimPrefix(text, "def ")
479 if paren := strings.Index(text, "("); paren > 0 {
480 return text[:paren]
481 }
482 }
483
484 case "rust":
485 // fn name(...) or pub fn name(...)
486 if idx := strings.Index(text, "fn "); idx >= 0 {
487 text = text[idx+3:]

Callers 1

ScanDirectoryMethod · 0.85

Calls 1

isValidIdentifierFunction · 0.85

Tested by

no test coverage detected