Skip to content

Commit 21fbb1b

Browse files
committed
Go: Only initialise module if there are source files
1 parent f48b1e5 commit 21fbb1b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

go/extractor/project/project.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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{{

0 commit comments

Comments
 (0)