goWorkModules returns the URIs of go.mod files named by the go.work file.
(ctx context.Context, gowork protocol.DocumentURI, fs file.Source)
| 23 | |
| 24 | // goWorkModules returns the URIs of go.mod files named by the go.work file. |
| 25 | func 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' |
no test coverage detected
searching dependent graphs…