|
8 | 8 | "context"
|
9 | 9 | "errors"
|
10 | 10 | "fmt"
|
11 |
| - "io/fs" |
12 | 11 | "path/filepath"
|
13 |
| - "strings" |
14 | 12 |
|
15 | 13 | "golang.org/x/mod/modfile"
|
16 | 14 | "golang.org/x/tools/gopls/internal/file"
|
@@ -74,50 +72,3 @@ var errExhausted = errors.New("exhausted")
|
74 | 72 | // Note: per golang/go#56496, the previous limit of 1M files was too slow, at
|
75 | 73 | // which point this limit was decreased to 100K.
|
76 | 74 | const fileLimit = 100_000
|
77 |
| - |
78 |
| -// findModules recursively walks the root directory looking for go.mod files, |
79 |
| -// returning the set of modules it discovers. If modLimit is non-zero, |
80 |
| -// searching stops once modLimit modules have been found. |
81 |
| -// |
82 |
| -// TODO(rfindley): consider overlays. |
83 |
| -func findModules(root protocol.DocumentURI, excludePath func(string) bool, modLimit int) (map[protocol.DocumentURI]struct{}, error) { |
84 |
| - // Walk the view's folder to find all modules in the view. |
85 |
| - modFiles := make(map[protocol.DocumentURI]struct{}) |
86 |
| - searched := 0 |
87 |
| - errDone := errors.New("done") |
88 |
| - err := filepath.WalkDir(root.Path(), func(path string, info fs.DirEntry, err error) error { |
89 |
| - if err != nil { |
90 |
| - // Probably a permission error. Keep looking. |
91 |
| - return filepath.SkipDir |
92 |
| - } |
93 |
| - // For any path that is not the workspace folder, check if the path |
94 |
| - // would be ignored by the go command. Vendor directories also do not |
95 |
| - // contain workspace modules. |
96 |
| - if info.IsDir() && path != root.Path() { |
97 |
| - suffix := strings.TrimPrefix(path, root.Path()) |
98 |
| - switch { |
99 |
| - case checkIgnored(suffix), |
100 |
| - strings.Contains(filepath.ToSlash(suffix), "/vendor/"), |
101 |
| - excludePath(suffix): |
102 |
| - return filepath.SkipDir |
103 |
| - } |
104 |
| - } |
105 |
| - // We're only interested in go.mod files. |
106 |
| - uri := protocol.URIFromPath(path) |
107 |
| - if isGoMod(uri) { |
108 |
| - modFiles[uri] = struct{}{} |
109 |
| - } |
110 |
| - if modLimit > 0 && len(modFiles) >= modLimit { |
111 |
| - return errDone |
112 |
| - } |
113 |
| - searched++ |
114 |
| - if fileLimit > 0 && searched >= fileLimit { |
115 |
| - return errExhausted |
116 |
| - } |
117 |
| - return nil |
118 |
| - }) |
119 |
| - if err == errDone { |
120 |
| - return modFiles, nil |
121 |
| - } |
122 |
| - return modFiles, err |
123 |
| -} |
0 commit comments