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)
| 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. |
| 135 | func 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. |
| 150 | func omniCandidateTypeToBase(t omnicompletion.CandidateType) base.CandidateType { |