Skip to content

Commit 45ab65e

Browse files
committed
internal/cmd/cue-ast: use cue/load with SkipImports=true
Otherwise, using the tool when the imports are broken leads to failures even though we can still join the syntax tree files without an issue. One example is using `cue-ast join` underneath cue.mod/pkg; imports in those dirs don't work, but the CUE syntax is still valid. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I7f6bbeecd9be459445c572c268d2619d253414ef Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218469 Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent e4cdcd3 commit 45ab65e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/cmd/cue-ast/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ See 'cue help inputs' as well.
5858
flag.Usage()
5959
os.Exit(1)
6060
}
61+
lcfg := &load.Config{
62+
// cue-ast only cares about syntax trees; loading the imports just causes
63+
// extra work and may lead to errors we don't care about.
64+
SkipImports: true,
65+
}
6166
name, args := os.Args[1], os.Args[2:]
6267
switch name {
6368
case "print":
@@ -96,7 +101,7 @@ See 'cue help inputs' as well.
96101
// more clearly separating the AST for each file?
97102
// [ast.File.Filename] already has the full filename,
98103
// but as one of the first fields it's not a great separator.
99-
insts := load.Instances(flag.Args(), &load.Config{})
104+
insts := load.Instances(flag.Args(), lcfg)
100105
for _, inst := range insts {
101106
if err := inst.Err; err != nil {
102107
log.Fatal(errors.Details(err, nil))
@@ -112,7 +117,7 @@ See 'cue help inputs' as well.
112117

113118
var jointImports []*ast.ImportSpec
114119
var jointFields []ast.Decl
115-
insts := load.Instances(flag.Args(), &load.Config{})
120+
insts := load.Instances(flag.Args(), lcfg)
116121
if len(insts) != 1 {
117122
log.Fatal("joining multiple instances is not possible yet")
118123
}

0 commit comments

Comments
 (0)