MCPcopy Index your code
hub / github.com/bytebase/bytebase / formatCollectionCandidate

Function formatCollectionCandidate

backend/plugin/parser/mongodb/completion.go:135–147  ·  view source on GitHub ↗

formatCollectionCandidate formats a collection name for completion context. In bracket context (db[|): returns "name"] to complete the bracket expression. In dot context (db.|): returns bracket notation ["name"] for special chars, bare name otherwise.

(name string, inBracket bool)

Source from the content-addressed store, hash-verified

133// In bracket context (db[|): returns "name"] to complete the bracket expression.
134// In dot context (db.|): returns bracket notation ["name"] for special chars, bare name otherwise.
135func formatCollectionCandidate(name string, inBracket bool) string {
136 if inBracket {
137 escaped := strings.ReplaceAll(name, `\`, `\\`)
138 escaped = strings.ReplaceAll(escaped, `"`, `\"`)
139 return `"` + escaped + `"]`
140 }
141 if !validIdentifierRegexp.MatchString(name) {
142 escaped := strings.ReplaceAll(name, `\`, `\\`)
143 escaped = strings.ReplaceAll(escaped, `"`, `\"`)
144 return `["` + escaped + `"]`
145 }
146 return name
147}
148
149// omniCandidateTypeToBase maps omni completion candidate types to Bytebase base types.
150func omniCandidateTypeToBase(t omnicompletion.CandidateType) base.CandidateType {

Callers 1

CompletionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected