File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -284,7 +284,19 @@ func getBuildRoots(emitDiagnostics bool) (goWorkspaces []GoWorkspace, totalModul
284284 // If there are no `go.mod` files at all, create one in line with https://go.dev/blog/migrating-to-go-modules
285285 if totalModuleFiles == 0 {
286286 // If we have no `go.mod` files, then the project appears to be a legacy project without
287- // a `go.mod` file. Try to initialize one automatically.
287+ // a `go.mod` file. Check that there are actually Go source files before initializing a module
288+ // so that we correctly fail the extraction later.
289+ if ! util .FindGoFiles ("." ) {
290+ goWorkspaces = []GoWorkspace {{
291+ BaseDir : "." ,
292+ DepMode : GoGetNoModules ,
293+ ModMode : ModUnset ,
294+ }}
295+ totalModuleFiles = 0
296+ return
297+ }
298+
299+ // Try to initialize a `go.mod` file automatically.
288300 initGoModForLegacyProject ("." )
289301
290302 goWorkspaces = []GoWorkspace {{
You can’t perform that action at this time.
0 commit comments