MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / handleCompletion

Method handleCompletion

pkg/lsp/handler.go:661–701  ·  view source on GitHub ↗

handleCompletion provides completion suggestions for SQL keywords and snippets. This handler implements intelligent auto-completion that helps users write SQL faster with less typing. It provides context-aware suggestions based on the current cursor position and partial input. Features: - 100+ SQL

(params json.RawMessage)

Source from the content-addressed store, hash-verified

659// - Empty list if no matches or document not found
660// - IsIncomplete=true if results were truncated
661func (h *Handler) handleCompletion(params json.RawMessage) (*CompletionList, error) {
662 var p CompletionParams
663 if err := json.Unmarshal(params, &p); err != nil {
664 return nil, err
665 }
666
667 doc, ok := h.server.Documents().Get(p.TextDocument.URI)
668 if !ok {
669 return &CompletionList{Items: []CompletionItem{}}, nil
670 }
671
672 // Get partial word at position for filtering
673 word := doc.GetWordAtPosition(p.Position)
674 prefix := strings.ToUpper(word)
675 lowerPrefix := strings.ToLower(word)
676
677 // Build completion items - keywords first
678 items := []CompletionItem{}
679 for _, kw := range sqlKeywords {
680 if prefix == "" || strings.HasPrefix(strings.ToUpper(kw.Label), prefix) {
681 items = append(items, kw)
682 }
683 }
684
685 // Add snippets (match on lowercase prefix for snippet shortcuts)
686 for _, snippet := range sqlSnippets {
687 if lowerPrefix == "" || strings.HasPrefix(strings.ToLower(snippet.Label), lowerPrefix) {
688 items = append(items, snippet)
689 }
690 }
691
692 // Limit results
693 if len(items) > 100 {
694 items = items[:100]
695 }
696
697 return &CompletionList{
698 IsIncomplete: len(items) >= 100,
699 Items: items,
700 }, nil
701}
702
703// handleFormatting formats the SQL document with intelligent indentation.
704//

Callers 1

HandleRequestMethod · 0.95

Calls 3

DocumentsMethod · 0.80
GetWordAtPositionMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected