mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
feat: implement ThreadedCompleter for improved autocomplete performance
This commit is contained in:
parent
31f7856f41
commit
530dae2a98
1 changed files with 21 additions and 9 deletions
30
aider/io.py
30
aider/io.py
|
@ -6,7 +6,7 @@ from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from prompt_toolkit import prompt
|
from prompt_toolkit import prompt
|
||||||
from prompt_toolkit.completion import Completer, Completion
|
from prompt_toolkit.completion import Completer, Completion, ThreadedCompleter
|
||||||
from prompt_toolkit.enums import EditingMode
|
from prompt_toolkit.enums import EditingMode
|
||||||
from prompt_toolkit.history import FileHistory
|
from prompt_toolkit.history import FileHistory
|
||||||
from prompt_toolkit.key_binding import KeyBindings
|
from prompt_toolkit.key_binding import KeyBindings
|
||||||
|
@ -67,7 +67,15 @@ class AutoCompleter(Completer):
|
||||||
if abs_read_only_fnames:
|
if abs_read_only_fnames:
|
||||||
all_fnames.extend(abs_read_only_fnames)
|
all_fnames.extend(abs_read_only_fnames)
|
||||||
|
|
||||||
for fname in all_fnames:
|
self.all_fnames = all_fnames
|
||||||
|
self.tokenized = False
|
||||||
|
|
||||||
|
def tokenize(self):
|
||||||
|
if self.tokenized:
|
||||||
|
return
|
||||||
|
self.tokenized = True
|
||||||
|
|
||||||
|
for fname in self.all_fnames:
|
||||||
try:
|
try:
|
||||||
with open(fname, "r", encoding=self.encoding) as f:
|
with open(fname, "r", encoding=self.encoding) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
@ -113,6 +121,8 @@ class AutoCompleter(Completer):
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
def get_completions(self, document, complete_event):
|
def get_completions(self, document, complete_event):
|
||||||
|
self.tokenize()
|
||||||
|
|
||||||
text = document.text_before_cursor
|
text = document.text_before_cursor
|
||||||
words = text.split()
|
words = text.split()
|
||||||
if not words:
|
if not words:
|
||||||
|
@ -275,13 +285,15 @@ class InputOutput:
|
||||||
else:
|
else:
|
||||||
style = None
|
style = None
|
||||||
|
|
||||||
completer_instance = AutoCompleter(
|
completer_instance = ThreadedCompleter(
|
||||||
root,
|
AutoCompleter(
|
||||||
rel_fnames,
|
root,
|
||||||
addable_rel_fnames,
|
rel_fnames,
|
||||||
commands,
|
addable_rel_fnames,
|
||||||
self.encoding,
|
commands,
|
||||||
abs_read_only_fnames=abs_read_only_fnames,
|
self.encoding,
|
||||||
|
abs_read_only_fnames=abs_read_only_fnames,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue