helpWithFunction is to be used in parser actions to mark the parser "in error", with the error set to a contextual help message about the current built-in function.
(sqllex sqlLexer, f tree.ResolvableFunctionReference)
| 92 | // "in error", with the error set to a contextual help message about |
| 93 | // the current built-in function. |
| 94 | func helpWithFunction(sqllex sqlLexer, f tree.ResolvableFunctionReference) int { |
| 95 | // A resolver is not needed because we do not provide contextual help |
| 96 | // messages for user-defined functions. |
| 97 | d, err := f.Resolve(context.Background(), tree.EmptySearchPath, nil /* resolver */) |
| 98 | if err != nil { |
| 99 | return 1 |
| 100 | } |
| 101 | |
| 102 | props, _ := builtinsregistry.GetBuiltinProperties(d.Name) |
| 103 | msg := HelpMessage{ |
| 104 | Function: f.String(), |
| 105 | HelpMessageBody: HelpMessageBody{ |
| 106 | Category: props.Category, |
| 107 | SeeAlso: docs.URL("functions-and-operators.html"), |
| 108 | }, |
| 109 | } |
| 110 | |
| 111 | var buf bytes.Buffer |
| 112 | w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0) |
| 113 | |
| 114 | // Each function definition contains one or more overloads. We need |
| 115 | // to extract them all; moreover each overload may have a different |
| 116 | // documentation, so we need to also combine the descriptions |
| 117 | // together. |
| 118 | lastInfo := "" |
| 119 | for i, b := range d.Overloads { |
| 120 | if b.Info != "" && b.Info != lastInfo { |
| 121 | if i > 0 { |
| 122 | fmt.Fprintln(w, "---") |
| 123 | } |
| 124 | fmt.Fprintf(w, "\n%s\n\n", b.Info) |
| 125 | fmt.Fprintln(w, "Signature") |
| 126 | } |
| 127 | lastInfo = b.Info |
| 128 | |
| 129 | simplifyRet := b.Class == tree.GeneratorClass |
| 130 | fmt.Fprintf(w, "%s%s\n", d.Name, b.Signature(simplifyRet)) |
| 131 | } |
| 132 | _ = w.Flush() |
| 133 | msg.Text = buf.String() |
| 134 | |
| 135 | sqllex.(*lexer).SetHelp(msg) |
| 136 | return 1 |
| 137 | } |
| 138 | |
| 139 | func helpWithFunctionByName(sqllex sqlLexer, s string) int { |
| 140 | un := &tree.UnresolvedName{NumParts: 1, Parts: tree.NameParts{s}} |
no test coverage detected
searching dependent graphs…