MCPcopy Create free account
hub / github.com/dolthub/doltgresql / helpWithFunction

Function helpWithFunction

postgres/parser/parser/help.go:107–153  ·  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

105// "in error", with the error set to a contextual help message about
106// the current built-in function.
107func helpWithFunction(sqllex sqlLexer, f tree.ResolvableFunctionReference) int {
108 d, err := f.Resolve(sessiondata.SearchPath{})
109 if err != nil {
110 return 1
111 }
112
113 helpCategory := "unknown function"
114 if d != nil {
115 helpCategory = d.Category
116 }
117 msg := HelpMessage{
118 Function: f.String(),
119 HelpMessageBody: HelpMessageBody{
120 Category: helpCategory,
121 },
122 }
123
124 var buf bytes.Buffer
125 w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0)
126
127 // Each function definition contains one or more overloads. We need
128 // to extract them all; moreover each overload may have a different
129 // documentation, so we need to also combine the descriptions
130 // together.
131 lastInfo := ""
132 if d != nil {
133 for i, overload := range d.Definition {
134 b := overload.(*tree.Overload)
135 if b.Info != "" && b.Info != lastInfo {
136 if i > 0 {
137 fmt.Fprintln(w, "---")
138 }
139 fmt.Fprintf(w, "\n%s\n\n", b.Info)
140 fmt.Fprintln(w, "Signature")
141 }
142 lastInfo = b.Info
143
144 simplifyRet := d.Class == tree.GeneratorClass
145 fmt.Fprintf(w, "%s%s\n", d.Name, b.Signature(simplifyRet))
146 }
147 }
148 _ = w.Flush()
149 msg.Text = buf.String()
150
151 sqllex.(*lexer).SetHelp(msg)
152 return 1
153}
154
155func helpWithFunctionByName(sqllex sqlLexer, s string) int {
156 un := &tree.UnresolvedName{NumParts: 1, Parts: tree.NameParts{s}}

Callers 1

helpWithFunctionByNameFunction · 0.85

Calls 5

SignatureMethod · 0.80
FlushMethod · 0.80
SetHelpMethod · 0.80
ResolveMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected