MCPcopy Create free account
hub / github.com/diillson/chatcli / parseStackFrame

Function parseStackFrame

operator/controllers/source_controller.go:665–717  ·  view source on GitHub ↗

parseStackFrame extracts file path and line number from a stack frame string.

(frame, language string)

Source from the content-addressed store, hash-verified

663
664// parseStackFrame extracts file path and line number from a stack frame string.
665func parseStackFrame(frame, language string) (string, int) {
666 frame = strings.TrimSpace(frame)
667
668 switch language {
669 case "go":
670 // format: package/file.go:123
671 if idx := strings.LastIndex(frame, ":"); idx > 0 {
672 path := frame[:idx]
673 return path, leadingInt(frame[idx+1:])
674 }
675
676 case "java":
677 // format: at com.example.MyClass.method(MyClass.java:42)
678 frame = strings.TrimPrefix(frame, "at ")
679 if start := strings.LastIndex(frame, "("); start > 0 {
680 if end := strings.LastIndex(frame, ")"); end > start {
681 fileInfo := frame[start+1 : end]
682 parts := strings.SplitN(fileInfo, ":", 2)
683 if len(parts) == 2 {
684 return parts[0], leadingInt(parts[1])
685 }
686 }
687 }
688
689 case "python":
690 // format: File "/path/to/file.py", line 42, in function
691 if strings.HasPrefix(frame, "File \"") {
692 parts := strings.SplitN(frame, "\"", 3)
693 if len(parts) >= 2 {
694 path := parts[1]
695 var line int
696 if lineIdx := strings.Index(frame, "line "); lineIdx > 0 {
697 line = leadingInt(frame[lineIdx+5:])
698 }
699 return path, line
700 }
701 }
702
703 case "nodejs":
704 // format: at functionName (/path/to/file.js:42:10)
705 frame = strings.TrimPrefix(frame, "at ")
706 if start := strings.Index(frame, "("); start >= 0 {
707 frame = frame[start+1:]
708 }
709 frame = strings.TrimSuffix(frame, ")")
710 parts := strings.SplitN(frame, ":", 3)
711 if len(parts) >= 2 {
712 return parts[0], leadingInt(parts[1])
713 }
714 }
715
716 return "", 0
717}
718
719// findFileInRepo searches for a file within the cloned repo.
720func findFileInRepo(localPath, fileName string, relevantPaths []string) string {

Callers 2

TestParseStackFrameFunction · 0.85
extractRelevantCodeFunction · 0.85

Calls 1

leadingIntFunction · 0.85

Tested by 1

TestParseStackFrameFunction · 0.68