File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments