MCPcopy
hub / github.com/golang/tools / goWorkModules

Function goWorkModules

gopls/internal/cache/workspace.go:25–45  ·  view source on GitHub ↗

goWorkModules returns the URIs of go.mod files named by the go.work file.

(ctx context.Context, gowork protocol.DocumentURI, fs file.Source)

Source from the content-addressed store, hash-verified

23
24// goWorkModules returns the URIs of go.mod files named by the go.work file.
25func goWorkModules(ctx context.Context, gowork protocol.DocumentURI, fs file.Source) (map[protocol.DocumentURI]unit, error) {
26 fh, err := fs.ReadFile(ctx, gowork)
27 if err != nil {
28 return nil, err // canceled
29 }
30 content, err := fh.Content()
31 if err != nil {
32 return nil, err
33 }
34 filename := gowork.Path()
35 dir := filepath.Dir(filename)
36 workFile, err := modfile.ParseWork(filename, content, nil)
37 if err != nil {
38 return nil, fmt.Errorf("parsing go.work: %w", err)
39 }
40 var usedDirs []string
41 for _, use := range workFile.Use {
42 usedDirs = append(usedDirs, use.Path)
43 }
44 return localModFiles(dir, usedDirs), nil
45}
46
47// localModFiles builds a set of local go.mod files referenced by
48// goWorkOrModPaths, which is a slice of paths as contained in a go.work 'use'

Callers 1

defineViewFunction · 0.85

Calls 8

appendFunction · 0.85
localModFilesFunction · 0.85
PathMethod · 0.80
DirMethod · 0.80
ParseWorkMethod · 0.80
ReadFileMethod · 0.65
ContentMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…