Skip to content

Commit 5f8569c

Browse files
committed
wit: prepare for filtering interface contents
1 parent b5396fd commit 5f8569c

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

wit/wit.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,23 +321,15 @@ func (*Interface) WITKind() string { return "interface" }
321321
//
322322
// [WIT]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md
323323
func (i *Interface) WIT(ctx Node, name string) string {
324+
// filter, _ := ctx.(*witFilter)
325+
324326
if i.Name != nil && name == "" {
325327
name = *i.Name
326328
}
327329

328330
var b strings.Builder
329331

330332
switch ctx := ctx.(type) {
331-
case *Package:
332-
b.WriteString(i.Docs.WIT(ctx, ""))
333-
if i.Stability != nil {
334-
b.WriteString(i.Stability.WIT(ctx, ""))
335-
b.WriteRune('\n')
336-
}
337-
b.WriteString("interface ")
338-
b.WriteString(escape(name))
339-
b.WriteRune(' ')
340-
341333
case worldImport:
342334
rname := relativeName(i, ctx.Package)
343335
if rname != "" {
@@ -361,13 +353,26 @@ func (i *Interface) WIT(ctx Node, name string) string {
361353
b.WriteString("export ")
362354
b.WriteString(escape(name))
363355
b.WriteString(": interface ")
356+
357+
default: // e.g. *Package
358+
b.WriteString(i.Docs.WIT(ctx, ""))
359+
if i.Stability != nil {
360+
b.WriteString(i.Stability.WIT(ctx, ""))
361+
b.WriteRune('\n')
362+
}
363+
b.WriteString("interface ")
364+
b.WriteString(escape(name))
365+
b.WriteRune(' ')
364366
}
365367

366368
b.WriteRune('{')
367369
n := 0
368370

369371
// Emit use statements first
370372
i.TypeDefs.All()(func(name string, td *TypeDef) bool {
373+
// if filter.filter(td) {
374+
// return true
375+
// }
371376
if td.Root().Owner == td.Owner {
372377
return true // Skip declarations
373378
}
@@ -382,6 +387,9 @@ func (i *Interface) WIT(ctx Node, name string) string {
382387

383388
// Declarations
384389
i.TypeDefs.All()(func(name string, td *TypeDef) bool {
390+
// if filter.filter(td) {
391+
// return true
392+
// }
385393
if td.Root().Owner != td.Owner {
386394
return true // Skip use statements
387395
}
@@ -396,6 +404,9 @@ func (i *Interface) WIT(ctx Node, name string) string {
396404

397405
// Functions
398406
i.Functions.All()(func(name string, f *Function) bool {
407+
// if filter.filter(f) {
408+
// return true
409+
// }
399410
if !f.IsFreestanding() {
400411
return true
401412
}
@@ -1126,9 +1137,9 @@ func (p *Package) WIT(ctx Node, name string) string {
11261137
}
11271138
b.WriteRune('\n')
11281139
if multi {
1129-
b.WriteString(indent(face.WIT(p, name)))
1140+
b.WriteString(indent(face.WIT(ctx, name)))
11301141
} else {
1131-
b.WriteString(face.WIT(p, name))
1142+
b.WriteString(face.WIT(ctx, name))
11321143
}
11331144
b.WriteRune('\n')
11341145
i++
@@ -1140,9 +1151,9 @@ func (p *Package) WIT(ctx Node, name string) string {
11401151
}
11411152
b.WriteRune('\n')
11421153
if multi {
1143-
b.WriteString(indent(w.WIT(filter, name)))
1154+
b.WriteString(indent(w.WIT(ctx, name)))
11441155
} else {
1145-
b.WriteString(w.WIT(filter, name))
1156+
b.WriteString(w.WIT(ctx, name))
11461157
}
11471158
b.WriteRune('\n')
11481159
i++

0 commit comments

Comments
 (0)