MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / helpWithFunction

Function helpWithFunction

pkg/sql/parser/help.go:94–137  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

92// "in error", with the error set to a contextual help message about
93// the current built-in function.
94func 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
139func helpWithFunctionByName(sqllex sqlLexer, s string) int {
140 un := &tree.UnresolvedName{NumParts: 1, Parts: tree.NameParts{s}}

Callers 1

helpWithFunctionByNameFunction · 0.85

Calls 6

GetBuiltinPropertiesFunction · 0.92
URLFunction · 0.92
SignatureMethod · 0.80
SetHelpMethod · 0.80
StringMethod · 0.65
ResolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…