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

Method execute

internal/tool/code_search.go:41–67  ·  view source on GitHub ↗
(ctx context.Context, args map[string]any)

Source from the content-addressed store, hash-verified

39}
40
41func (p *CodeSearchProvider) execute(ctx context.Context, args map[string]any) (string, error) {
42 searchText, _ := args["search_text"].(string)
43 caseSensitive, _ := args["case_sensitive"].(bool)
44 usePerlRegexp, _ := args["use_perl_regexp"].(bool)
45
46 filePatternsIface, _ := args["file_patterns"].([]any)
47 var patterns []string
48 for _, item := range filePatternsIface {
49 if s, ok := item.(string); ok && s != "" {
50 if hasTraversalPathComponent(s) {
51 return "Error: file_patterns must not contain ..", nil
52 }
53 // Treat backslashes as separators so Windows pathspecs match.
54 patterns = append(patterns, strings.ReplaceAll(s, "\\", "/"))
55 }
56 }
57
58 if strings.TrimSpace(searchText) == "" {
59 return "Error: search_text is blank", nil
60 }
61
62 result, err := p.gitGrep(ctx, searchText, caseSensitive, usePerlRegexp, patterns)
63 if err != nil {
64 return "", err
65 }
66 return result, nil
67}
68
69func (p *CodeSearchProvider) buildGrepArgs(searchText string, caseSensitive bool, usePerlRegexp bool, noIndex bool, pathspec []string) []string {
70 // core.quotepath=false reports non-ASCII paths literally instead of as

Callers 1

ExecuteMethod · 0.45

Calls 2

gitGrepMethod · 0.95

Tested by

no test coverage detected