Skip to content

Commit d99ad01

Browse files
committed
Go: Add module files which don't belong to a workspace, if there are workspaces
1 parent 251888a commit d99ad01

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

go/extractor/project/project.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,43 @@ func discoverWorkspaces(emitDiagnostics bool) []GoWorkspace {
283283
for i, workFilePath := range goWorkFiles {
284284
results[i] = discoverWorkspace(workFilePath)
285285
}
286+
287+
// Add all stray `go.mod` files (i.e. those not referenced by `go.work` files)
288+
// as separate workspaces.
289+
goModFiles := findGoModFiles(".")
290+
291+
for _, goModFile := range goModFiles {
292+
// Check to see whether we already have this module file under an existing workspace.
293+
found := false
294+
for _, workspace := range results {
295+
if workspace.Modules == nil {
296+
break
297+
}
298+
299+
for _, module := range workspace.Modules {
300+
if module.Path == goModFile {
301+
found = true
302+
break
303+
}
304+
}
305+
306+
if found {
307+
break
308+
}
309+
}
310+
311+
// If not, add it to the array.
312+
if !found {
313+
log.Printf("Module %s is not referenced by any go.work file; adding it separately.\n", goModFile)
314+
results = append(results, GoWorkspace{
315+
BaseDir: filepath.Dir(goModFile),
316+
Modules: loadGoModules([]string{goModFile}),
317+
DepMode: GoGetWithModules,
318+
ModMode: getModMode(GoGetWithModules, filepath.Dir(goModFile)),
319+
})
320+
}
321+
}
322+
286323
return results
287324
}
288325
}

0 commit comments

Comments
 (0)