Provides completions for slash commands based on registered commands.
| 30 | |
| 31 | |
| 32 | class SlashCompleter(Completer): |
| 33 | """Provides completions for slash commands based on registered commands.""" |
| 34 | |
| 35 | def __init__(self, command_names: list[str]): |
| 36 | self.command_names = command_names |
| 37 | |
| 38 | def get_completions(self, document, complete_event): |
| 39 | text = document.text_before_cursor.lstrip() |
| 40 | if not text.startswith("/"): |
| 41 | return |
| 42 | token = text[1:] |
| 43 | for name in self.command_names: |
| 44 | if name.startswith(token): |
| 45 | yield Completion(f"/{name}", start_position=-len(text)) |
| 46 | |
| 47 | |
| 48 | async def interactive_mode( |
no outgoing calls