mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
aider is AI pair programming in your terminal
https://aider.chat/
![]() # Context: USER: have prompt_toolkit autocomplete based on the contents of the files in self.fnames ASSISTANT: To add autocompletion based on the contents of the files in `self.fnames`, you can use the `Completer` class from `prompt_toolkit`. Here's how to implement it: 1. Import the necessary classes and functions from `prompt_toolkit`. 2. Create a custom completer class that inherits from `Completer`. 3. Override the `get_completions` method to provide completions based on the contents of the files. 4. Use the custom completer when calling the `prompt` function. Here are the changes to the code: ```python coder.py <<<<<<< ORIGINAL from prompt_toolkit import prompt ======= from prompt_toolkit import prompt from prompt_toolkit.completion import Completer, Completion >>>>>>> UPDATED ``` ```python coder.py <<<<<<< ORIGINAL class Coder: fnames = dict() last_modified = 0 repo = None ======= class FileContentCompleter(Completer): def __init__(self, fnames): self.fnames = fnames def get_completions(self, document, complete_event): text = document.text_before_cursor words = text.split() if not words: return last_word = words[-1] for fname in self.fnames: with open(fname, "r") as f: content = f.read() for word in content.split(): if word.startswith(last_word): yield Completion(word, start_position=-len(last_word)) class Coder: fnames = dict() last_modified = 0 repo = None >>>>>>> UPDATED ``` ```python coder.py <<<<<<< ORIGINAL line = prompt("> ") ======= completer = FileContentCompleter(self.fnames) line = prompt("> ", completer=completer) >>>>>>> UPDATED ``` These changes will add autocompletion based on the contents of the files in `self.fnames`. |
||
---|---|---|
.flake8 | ||
.pre-commit-config.yaml | ||
coder.py | ||
dump.py | ||
main.py | ||
prompts.py | ||
test_utils.py | ||
utils.py |