diff --git a/gopls/internal/regtest/misc/settings_test.go b/gopls/internal/regtest/misc/settings_test.go new file mode 100644 index 0000000000..7704c3c043 --- /dev/null +++ b/gopls/internal/regtest/misc/settings_test.go @@ -0,0 +1,36 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package misc + +import ( + "testing" + + . "golang.org/x/tools/internal/lsp/regtest" +) + +func TestEmptyDirectoryFilters_Issue51843(t *testing.T) { + const src = ` +-- go.mod -- +module mod.com + +go 1.12 +-- main.go -- +package main + +func main() { +} +` + + WithOptions( + EditorConfig{ + Settings: map[string]interface{}{ + "directoryFilters": []string{""}, + }, + }, + ).Run(t, src, func(t *testing.T, env *Env) { + // No need to do anything. Issue golang/go#51843 is triggered by the empty + // directory filter above. + }) +} diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index 319f77e6d9..9688d8c7e0 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -820,7 +820,7 @@ func (o *Options) set(name string, value interface{}, seen map[string]struct{}) var filters []string for _, ifilter := range ifilters { filter := fmt.Sprint(ifilter) - if filter[0] != '+' && filter[0] != '-' { + if filter == "" || (filter[0] != '+' && filter[0] != '-') { result.errorf("invalid filter %q, must start with + or -", filter) return result }