MCPcopy Create free account
hub / github.com/alibaba/open-code-review / Execute

Method Execute

internal/tool/file_read_diff.go:66–102  ·  view source on GitHub ↗
(_ context.Context, args map[string]any)

Source from the content-addressed store, hash-verified

64func (p *FileReadDiffProvider) Tool() Tool { return FileReadDiff }
65
66func (p *FileReadDiffProvider) Execute(_ context.Context, args map[string]any) (string, error) {
67 pathArray, _ := args["path_array"].([]any)
68 if len(pathArray) == 0 {
69 return "Error: no files found", nil
70 }
71
72 var sb strings.Builder
73 var missing []string
74 for _, item := range pathArray {
75 path, ok := item.(string)
76 if !ok {
77 continue
78 }
79 if d, exists := p.diffMap.Get(path); exists {
80 sb.WriteString("==== FILE: ")
81 sb.WriteString(path)
82 sb.WriteString(" ====\n")
83 sb.WriteString(d)
84 sb.WriteString("\n")
85 continue
86 }
87 missing = append(missing, path)
88 }
89
90 if len(missing) > 0 {
91 if sb.Len() > 0 {
92 sb.WriteString("\n")
93 }
94 sb.WriteString(p.notFoundMessage(missing))
95 }
96
97 result := sb.String()
98 if result == "" {
99 return "Error: diff not found for the requested paths", nil
100 }
101 return result, nil
102}
103
104// notFoundMessage names the paths that had no diff and, when the snapshot
105// holds other paths, names those too: a request for a path outside the change

Callers

nothing calls this directly

Calls 4

notFoundMessageMethod · 0.95
LenMethod · 0.80
GetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected