cue/build: get rid of ParseOptions

Pretty much only used for adding comments,
which is always done. Done by default now.

Not parsing comments by default also led to
a bunch of gotchas.

Also get rid of PurgeCache

Change-Id: I0f2be529814a356d2403e5c3af3c7ee89b541892
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2366
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index e4e179e..a41c350 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -24,7 +24,6 @@
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/load"
-	"cuelang.org/go/cue/parser"
 	"github.com/spf13/cobra"
 	"golang.org/x/text/language"
 	"golang.org/x/text/message"
@@ -82,15 +81,9 @@
 	return buildInstances(cmd, binst)
 }
 
-var (
-	config = &load.Config{
-		Context: build.NewContext(build.ParseOptions(parser.ParseComments)),
-	}
-)
-
 func loadFromArgs(cmd *cobra.Command, args []string) []*build.Instance {
 	log.SetOutput(cmd.OutOrStderr())
-	binst := load.Instances(args, config)
+	binst := load.Instances(args, nil)
 	if len(binst) == 0 {
 		return nil
 	}
diff --git a/cue/build/context.go b/cue/build/context.go
index 4f810e8..3c20f1d 100644
--- a/cue/build/context.go
+++ b/cue/build/context.go
@@ -27,16 +27,13 @@
 
 import (
 	"context"
-
-	"cuelang.org/go/cue/parser"
 )
 
 // A Context keeps track of state of building instances and caches work.
 type Context struct {
 	ctxt context.Context
 
-	loader       LoadFunc
-	parseOptions []parser.Option
+	loader LoadFunc
 
 	initialized bool
 
@@ -101,21 +98,9 @@
 	return c
 }
 
-// PurgeCache purges the instance cache.
-func (c *Context) PurgeCache() {
-	for name := range c.imports {
-		delete(c.imports, name)
-	}
-}
-
 // Option define build options.
 type Option func(c *Context)
 
-// ParseOptions sets parsing options.
-func ParseOptions(mode ...parser.Option) Option {
-	return func(c *Context) { c.parseOptions = mode }
-}
-
 // Loader sets parsing options.
 func Loader(f LoadFunc) Option {
 	return func(c *Context) { c.loader = f }
diff --git a/cue/build/instance.go b/cue/build/instance.go
index 7b3ab18..c40cf1d 100644
--- a/cue/build/instance.go
+++ b/cue/build/instance.go
@@ -178,8 +178,7 @@
 // It does not process the file's imports. The package name of the file must
 // match the package name of the instance.
 func (inst *Instance) AddFile(filename string, src interface{}) error {
-	c := inst.ctxt
-	file, err := parser.ParseFile(filename, src, c.parseOptions...)
+	file, err := parser.ParseFile(filename, src, parser.ParseComments)
 	if err != nil {
 		// should always be an errors.List, but just in case.
 		switch x := err.(type) {
diff --git a/cue/build_test.go b/cue/build_test.go
index 5ce6a10..4369f43 100644
--- a/cue/build_test.go
+++ b/cue/build_test.go
@@ -21,7 +21,6 @@
 
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/build"
-	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/cue/token"
 )
 
@@ -183,7 +182,7 @@
 
 func makeInstances(insts []*bimport) (instances []*build.Instance) {
 	b := builder{
-		ctxt:    build.NewContext(build.ParseOptions(parser.ParseComments)),
+		ctxt:    build.NewContext(),
 		imports: map[string]*bimport{},
 	}
 	for _, bi := range insts {
diff --git a/encoding/openapi/openapi_test.go b/encoding/openapi/openapi_test.go
index 2376a40..33a15e6 100644
--- a/encoding/openapi/openapi_test.go
+++ b/encoding/openapi/openapi_test.go
@@ -23,18 +23,12 @@
 	"testing"
 
 	"cuelang.org/go/cue"
-	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/load"
-	"cuelang.org/go/cue/parser"
 	"github.com/kylelemons/godebug/diff"
 )
 
 var update *bool = flag.Bool("update", false, "update the test output")
 
-var config = &load.Config{
-	Context: build.NewContext(build.ParseOptions(parser.ParseComments)),
-}
-
 func TestParseDefinitions(t *testing.T) {
 	defaultConfig := &Config{}
 	resolveRefs := &Config{ExpandReferences: true}
@@ -59,7 +53,7 @@
 		t.Run(tc.out, func(t *testing.T) {
 			filename := filepath.Join("testdata", filepath.FromSlash(tc.in))
 
-			inst := cue.Build(load.Instances([]string{filename}, config))[0]
+			inst := cue.Build(load.Instances([]string{filename}, nil))[0]
 
 			b, err := Gen(inst, tc.config)
 			var out = &bytes.Buffer{}