File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -439,8 +439,9 @@ func getBuildRoots(emitDiagnostics bool) (goWorkspaces []GoWorkspace, totalModul
439
439
for _ , component := range components {
440
440
path = filepath .Join (path , component )
441
441
442
- // Try to initialize a `go.mod` file automatically for the stray source files.
443
- if ! slices .Contains (goModDirs , path ) {
442
+ // Try to initialize a `go.mod` file automatically for the stray source files if
443
+ // doing so would not place it in a parent directory of an existing `go.mod` file.
444
+ if ! startsWithAnyOf (path , goModDirs ) {
444
445
goWorkspaces = append (goWorkspaces , GoWorkspace {
445
446
BaseDir : path ,
446
447
DepMode : GoGetNoModules ,
@@ -477,6 +478,16 @@ func getBuildRoots(emitDiagnostics bool) (goWorkspaces []GoWorkspace, totalModul
477
478
return
478
479
}
479
480
481
+ // Determines whether `str` starts with any of `prefixes`.
482
+ func startsWithAnyOf (str string , prefixes []string ) bool {
483
+ for _ , prefix := range prefixes {
484
+ if strings .HasPrefix (str , prefix ) {
485
+ return true
486
+ }
487
+ }
488
+ return false
489
+ }
490
+
480
491
// Finds Go workspaces in the current working directory.
481
492
func GetWorkspaceInfo (emitDiagnostics bool ) []GoWorkspace {
482
493
bazelPaths := slices .Concat (
You can’t perform that action at this time.
0 commit comments