Skip to content

Commit 2f83b44

Browse files
committed
wit: prepare for filtering interface contents
1 parent ea3f170 commit 2f83b44

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
@@ -318,23 +318,15 @@ func (*Interface) WITKind() string { return "interface" }
318318
//
319319
// [WIT]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md
320320
func (i *Interface) WIT(ctx Node, name string) string {
321+
// filter, _ := ctx.(*witFilter)
322+
321323
if i.Name != nil && name == "" {
322324
name = *i.Name
323325
}
324326

325327
var b strings.Builder
326328

327329
switch ctx := ctx.(type) {
328-
case *Package:
329-
b.WriteString(i.Docs.WIT(ctx, ""))
330-
if i.Stability != nil {
331-
b.WriteString(i.Stability.WIT(ctx, ""))
332-
b.WriteRune('\n')
333-
}
334-
b.WriteString("interface ")
335-
b.WriteString(escape(name))
336-
b.WriteRune(' ')
337-
338330
case worldImport:
339331
rname := relativeName(i, ctx.Package)
340332
if rname != "" {
@@ -358,13 +350,26 @@ func (i *Interface) WIT(ctx Node, name string) string {
358350
b.WriteString("export ")
359351
b.WriteString(escape(name))
360352
b.WriteString(": interface ")
353+
354+
default: // e.g. *Package
355+
b.WriteString(i.Docs.WIT(ctx, ""))
356+
if i.Stability != nil {
357+
b.WriteString(i.Stability.WIT(ctx, ""))
358+
b.WriteRune('\n')
359+
}
360+
b.WriteString("interface ")
361+
b.WriteString(escape(name))
362+
b.WriteRune(' ')
361363
}
362364

363365
b.WriteRune('{')
364366
n := 0
365367

366368
// Emit use statements first
367369
i.TypeDefs.All()(func(name string, td *TypeDef) bool {
370+
// if filter.filter(td) {
371+
// return true
372+
// }
368373
if td.Root().Owner == td.Owner {
369374
return true // Skip declarations
370375
}
@@ -379,6 +384,9 @@ func (i *Interface) WIT(ctx Node, name string) string {
379384

380385
// Declarations
381386
i.TypeDefs.All()(func(name string, td *TypeDef) bool {
387+
// if filter.filter(td) {
388+
// return true
389+
// }
382390
if td.Root().Owner != td.Owner {
383391
return true // Skip use statements
384392
}
@@ -393,6 +401,9 @@ func (i *Interface) WIT(ctx Node, name string) string {
393401

394402
// Functions
395403
i.Functions.All()(func(name string, f *Function) bool {
404+
// if filter.filter(f) {
405+
// return true
406+
// }
396407
if !f.IsFreestanding() {
397408
return true
398409
}
@@ -1123,9 +1134,9 @@ func (p *Package) WIT(ctx Node, name string) string {
11231134
}
11241135
b.WriteRune('\n')
11251136
if multi {
1126-
b.WriteString(indent(face.WIT(p, name)))
1137+
b.WriteString(indent(face.WIT(ctx, name)))
11271138
} else {
1128-
b.WriteString(face.WIT(p, name))
1139+
b.WriteString(face.WIT(ctx, name))
11291140
}
11301141
b.WriteRune('\n')
11311142
i++
@@ -1137,9 +1148,9 @@ func (p *Package) WIT(ctx Node, name string) string {
11371148
}
11381149
b.WriteRune('\n')
11391150
if multi {
1140-
b.WriteString(indent(w.WIT(filter, name)))
1151+
b.WriteString(indent(w.WIT(ctx, name)))
11411152
} else {
1142-
b.WriteString(w.WIT(filter, name))
1153+
b.WriteString(w.WIT(ctx, name))
11431154
}
11441155
b.WriteRune('\n')
11451156
i++

0 commit comments

Comments
 (0)