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

Function Completion

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

Completion is the entry point for MongoDB code completion.

(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int)

Source from the content-addressed store, hash-verified

22
23// Completion is the entry point for MongoDB code completion.
24func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error) {
25 // Build omni catalog from Bytebase metadata.
26 cat := buildCatalog(ctx, cCtx)
27
28 // Convert caret line:column to byte offset.
29 byteOffset := caretToByteOffset(statement, caretLine, caretOffset)
30
31 // Get omni completion candidates.
32 candidates := omnicompletion.Complete(statement, byteOffset, cat)
33
34 // Detect whether cursor is inside bracket notation (db[|).
35 inBracket := isAfterOpenBracket(statement, byteOffset)
36
37 // Convert to base.Candidate, formatting collection names for context.
38 var result []base.Candidate
39 for _, c := range candidates {
40 text := c.Text
41 if c.Type == omnicompletion.CandidateCollection {
42 text = formatCollectionCandidate(c.Text, inBracket)
43 }
44 result = append(result, base.Candidate{
45 Type: omniCandidateTypeToBase(c.Type),
46 Text: text,
47 })
48 }
49
50 // Sort and deduplicate.
51 slices.SortFunc(result, func(a, b base.Candidate) int {
52 if a.Type != b.Type {
53 if a.Type < b.Type {
54 return -1
55 }
56 return 1
57 }
58 if a.Text < b.Text {
59 return -1
60 }
61 if a.Text > b.Text {
62 return 1
63 }
64 return 0
65 })
66
67 return slices.CompactFunc(result, func(a, b base.Candidate) bool {
68 return a.Type == b.Type && a.Text == b.Text
69 }), nil
70}
71
72// buildCatalog creates an omni catalog from Bytebase completion context.
73func buildCatalog(ctx context.Context, cCtx base.CompletionContext) *catalog.Catalog {

Callers

nothing calls this directly

Calls 5

isAfterOpenBracketFunction · 0.85
buildCatalogFunction · 0.70
caretToByteOffsetFunction · 0.70
omniCandidateTypeToBaseFunction · 0.70

Tested by

no test coverage detected