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

Method Execute

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

Source from the content-addressed store, hash-verified

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