| 764 | |
| 765 | |
| 766 | def suggest_special(text: str) -> list[dict[str, Any]]: |
| 767 | text = text.lstrip() |
| 768 | cmd, _separator, _arg = parse_special_command(text) |
| 769 | |
| 770 | if cmd == text: |
| 771 | # Trying to complete the special command itself |
| 772 | return [{"type": "special"}] |
| 773 | |
| 774 | if cmd in ("\\u", "/u", "\\r", "/r"): |
| 775 | return [{"type": "database"}] |
| 776 | |
| 777 | if cmd.lower() in ('use', '/use', 'connect', '/connect'): |
| 778 | return [{'type': 'database'}] |
| 779 | |
| 780 | if cmd in (r'\T', '/T', r'\Tr', '/Tr'): |
| 781 | return [{"type": "table_format"}] |
| 782 | |
| 783 | if cmd.lower() in ('tableformat', '/tableformat', 'redirectformat', '/redirectformat'): |
| 784 | return [{"type": "table_format"}] |
| 785 | |
| 786 | if cmd in ["\\f", "/f", "\\fs", "/fs", "\\fd", "/fd"]: |
| 787 | return [{"type": "favoritequery"}] |
| 788 | |
| 789 | if cmd in ["\\dt", "/dt", "\\dt+", "/dt+"]: |
| 790 | return [ |
| 791 | {"type": "table", "schema": []}, |
| 792 | {"type": "view", "schema": []}, |
| 793 | {"type": "schema"}, |
| 794 | ] |
| 795 | elif cmd.lower() in [ |
| 796 | r'\.', |
| 797 | r'/.', |
| 798 | 'source', |
| 799 | '/source', |
| 800 | r'\o', |
| 801 | '/o', |
| 802 | r'\once', |
| 803 | '/once', |
| 804 | 'tee', |
| 805 | '/tee', |
| 806 | ]: |
| 807 | return [{"type": "file_name"}] |
| 808 | # todo: why is \edit case-sensitive? |
| 809 | elif cmd in [ |
| 810 | r'\e', |
| 811 | '/e', |
| 812 | r'\edit', |
| 813 | '/edit', |
| 814 | ]: |
| 815 | return [{"type": "file_name"}] |
| 816 | if cmd in ["\\llm", "/llm", "\\ai", "/ai"]: |
| 817 | return [{"type": "llm"}] |
| 818 | |
| 819 | return [{"type": "keyword"}, {"type": "special"}] |
| 820 | |
| 821 | |
| 822 | def suggest_based_on_last_token( |