mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
cmd/viewer, types/views, util/codegen: add viewer support for custom container types
This adds support for container-like types such as Container[T] that don't explicitly specify a view type for T. Instead, a package implementing a container type should also implement and export a ContainerView[T, V] type and a ContainerViewOf(*Container[T]) ContainerView[T, V] function, which returns a view for the specified container, inferring the element view type V from the element type T. Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -111,6 +111,14 @@ func (it *ImportTracker) QualifiedName(t types.Type) string {
|
||||
return types.TypeString(t, it.qualifier)
|
||||
}
|
||||
|
||||
// PackagePrefix returns the prefix to be used when referencing named objects from pkg.
|
||||
func (it *ImportTracker) PackagePrefix(pkg *types.Package) string {
|
||||
if s := it.qualifier(pkg); s != "" {
|
||||
return s + "."
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Write prints all the tracked imports in a single import block to w.
|
||||
func (it *ImportTracker) Write(w io.Writer) {
|
||||
fmt.Fprintf(w, "import (\n")
|
||||
|
Reference in New Issue
Block a user