Skip to content

Commit 730dc3c

Browse files
committed
gopls/internal/settings: add a hidden option to disable zero config
Fixes golang/go#65515 Change-Id: If9786c00eb7629ec8d488cf8483144514d28786b Reviewed-on: https://go-review.googlesource.com/c/tools/+/562856 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 95f04f4 commit 730dc3c

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

gopls/internal/cache/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func selectViewDefs(ctx context.Context, fs file.Source, folders []*Folder, open
480480
checkFiles:
481481
for _, uri := range openFiles {
482482
folder := folderForFile(uri)
483-
if folder == nil {
483+
if folder == nil || !folder.Options.ZeroConfig {
484484
continue // only guess views for open files
485485
}
486486
fh, err := fs.ReadFile(ctx, uri)

gopls/internal/settings/default.go

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func DefaultOptions(overrides ...func(*Options)) *Options {
116116
TelemetryPrompt: false,
117117
LinkifyShowMessage: false,
118118
IncludeReplaceInWorkspace: true,
119+
ZeroConfig: true,
119120
},
120121
Hooks: Hooks{
121122
URLRegexp: urlRegexp(),

gopls/internal/settings/settings.go

+8
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ type InternalOptions struct {
559559
// Or in other words, if a go.mod file with local replaces behaves like a
560560
// go.work file.
561561
IncludeReplaceInWorkspace bool
562+
563+
// ZeroConfig enables the zero-config algorithm for workspace layout,
564+
// dynamically creating build configurations for different modules,
565+
// directories, and GOOS/GOARCH combinations to cover open files.
566+
ZeroConfig bool
562567
}
563568

564569
type SubdirWatchPatterns string
@@ -1159,6 +1164,9 @@ func (o *Options) set(name string, value interface{}, seen map[string]struct{})
11591164
case "includeReplaceInWorkspace":
11601165
result.setBool(&o.IncludeReplaceInWorkspace)
11611166

1167+
case "zeroConfig":
1168+
result.setBool(&o.ZeroConfig)
1169+
11621170
// Replaced settings.
11631171
case "experimentalDisabledAnalyses":
11641172
result.deprecated("analyses")

gopls/internal/test/integration/workspace/zero_config_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,37 @@ const B = 1
234234
})
235235
}
236236
}
237+
238+
func TestDisableZeroConfig(t *testing.T) {
239+
// This test checks that we treat locally replaced modules as workspace
240+
// modules, according to the "includeReplaceInWorkspace" setting.
241+
const files = `
242+
-- moda/go.mod --
243+
module golang.org/a
244+
245+
go 1.20
246+
247+
-- moda/a.go --
248+
package a
249+
250+
-- modb/go.mod --
251+
module golang.org/b
252+
253+
go 1.20
254+
255+
-- modb/b.go --
256+
package b
257+
258+
`
259+
260+
WithOptions(
261+
Settings{"zeroConfig": false},
262+
).Run(t, files, func(t *testing.T, env *Env) {
263+
env.OpenFile("moda/a.go")
264+
env.OpenFile("modb/b.go")
265+
env.AfterChange()
266+
if got := env.Views(); len(got) != 1 || got[0].Type != cache.AdHocView.String() {
267+
t.Errorf("Views: got %v, want one adhoc view", got)
268+
}
269+
})
270+
}

0 commit comments

Comments
 (0)