()
| 578 | } |
| 579 | |
| 580 | func (c *Completer) complete() ([]base.Candidate, error) { |
| 581 | checkTokenQuoted := func(idx int) quotedType { |
| 582 | if idx < 0 || idx >= len(c.tokens) { |
| 583 | return quotedTypeNone |
| 584 | } |
| 585 | tok := c.tokens[idx] |
| 586 | if !mssqlparser.IsIdentTokenType(tok.Type) || tok.Loc >= len(c.sql) { |
| 587 | return quotedTypeNone |
| 588 | } |
| 589 | switch c.sql[tok.Loc] { |
| 590 | case '"': |
| 591 | return quotedTypeDoubleQuote |
| 592 | case '[': |
| 593 | return quotedTypeSquareBracket |
| 594 | default: |
| 595 | return quotedTypeNone |
| 596 | } |
| 597 | } |
| 598 | if typ := checkTokenQuoted(c.caretTokenIndex); typ != quotedTypeNone { |
| 599 | c.caretTokenIsQuoted = typ |
| 600 | } else if c.caretTokenIndex > 0 { |
| 601 | prev := c.tokens[c.caretTokenIndex-1] |
| 602 | if prev.End >= c.cursorByteOffset { |
| 603 | c.caretTokenIsQuoted = checkTokenQuoted(c.caretTokenIndex - 1) |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | completionContext := omnimssql.CollectCompletion(c.sql, c.cursorByteOffset) |
| 608 | if completionContext != nil { |
| 609 | c.completionPrefix = completionContext.Prefix |
| 610 | c.completionIntent = completionContext.Intent |
| 611 | c.collectCompletionCTEs(completionContext) |
| 612 | c.collectCompletionScopeReferences(completionContext) |
| 613 | } |
| 614 | candidates := (*mssqlparser.CandidateSet)(nil) |
| 615 | if completionContext != nil { |
| 616 | candidates = completionContext.Candidates |
| 617 | } |
| 618 | if candidates == nil { |
| 619 | candidates = mssqlparser.Collect(c.sql, c.cursorByteOffset) |
| 620 | } |
| 621 | |
| 622 | return c.convertCandidates(candidates) |
| 623 | } |
| 624 | |
| 625 | func (c *Completer) determineObjectNameContext() []*objectRefContext { |
| 626 | if c.completionIntent == nil { |
no test coverage detected