`const MultiLineConst = ...`, // Multi line constant.
`var MultiLineVar = map\[struct{ ... }\]struct{ ... }{ ... }`, // Multi line variable.
`func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function.
+ `var LongLine = newLongLine\(("someArgument[1-4]", ){4}...\)`, // Long list of arguments.
`type T1 = T2`, // Type alias
},
[]string{
`unexportedTypedConstant`, // No unexported typed constant.
`Field`, // No fields.
`Method`, // No methods.
- `type T1 T2`, // Type alias does not display as type declaration.
+ `someArgument[5-8]`, // No truncated arguments.
+ `type T1 T2`, // Type alias does not display as type declaration.
},
},
// Package dump -u
// Type T1 dump (alias).
{
"type T1",
- []string{p+".T1"},
+ []string{p + ".T1"},
[]string{
`type T1 = T2`,
},
}
}
- param := strings.Join(params, ", ")
+ param := joinStrings(params)
if len(results) == 0 {
return fmt.Sprintf("func(%s)", param)
}
- result := strings.Join(results, ", ")
+ result := joinStrings(results)
if !needParens {
return fmt.Sprintf("func(%s) %s", param, result)
}
for _, arg := range n.Args {
args = append(args, pkg.oneLineNodeDepth(arg, depth))
}
- return fmt.Sprintf("%s(%s)", fnc, strings.Join(args, ", "))
+ return fmt.Sprintf("%s(%s)", fnc, joinStrings(args))
case *ast.UnaryExpr:
return fmt.Sprintf("%s%s", n.Op, pkg.oneLineNodeDepth(n.X, depth))
if len(names) == 0 {
return pkg.oneLineNodeDepth(field.Type, depth)
}
- return strings.Join(names, ", ") + " " + pkg.oneLineNodeDepth(field.Type, depth)
+ return joinStrings(names) + " " + pkg.oneLineNodeDepth(field.Type, depth)
+}
+
+// joinStrings formats the input as a comma-separated list,
+// but truncates the list at some reasonable length if necessary.
+func joinStrings(ss []string) string {
+ var n int
+ for i, s := range ss {
+ n += len(s) + len(", ")
+ if n > punchedCardWidth {
+ ss = append(ss[:i:i], "...")
+ break
+ }
+ }
+ return strings.Join(ss, ", ")
}
// packageDoc prints the docs for the package (package doc plus one-liners of the rest).
}
name := iMethod.Names[0].Name
if match(method, name) {
- // pkg.oneLineField(iMethod, 0)
if iMethod.Doc != nil {
for _, comment := range iMethod.Doc.List {
doc.ToText(&pkg.buf, comment.Text, "", indent, indentedWidth)