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

Method execute

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

Source from the content-addressed store, hash-verified

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