mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 20:54:59 +00:00
autocomplete file paths by (unique) basenames
This commit is contained in:
parent
5ba084edec
commit
db4fc2fe23
1 changed files with 16 additions and 1 deletions
17
aider/io.py
17
aider/io.py
|
@ -12,6 +12,8 @@ from rich.text import Text
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
class FileContentCompleter(Completer):
|
class FileContentCompleter(Completer):
|
||||||
def __init__(self, root, rel_fnames, addable_rel_fnames, commands):
|
def __init__(self, root, rel_fnames, addable_rel_fnames, commands):
|
||||||
|
@ -19,6 +21,13 @@ class FileContentCompleter(Completer):
|
||||||
self.addable_rel_fnames = addable_rel_fnames
|
self.addable_rel_fnames = addable_rel_fnames
|
||||||
self.rel_fnames = rel_fnames
|
self.rel_fnames = rel_fnames
|
||||||
|
|
||||||
|
fname_to_rel_fnames = defaultdict(list)
|
||||||
|
for rel_fname in addable_rel_fnames:
|
||||||
|
fname = os.path.basename(rel_fname)
|
||||||
|
if fname != rel_fname:
|
||||||
|
fname_to_rel_fnames[fname].append(rel_fname)
|
||||||
|
self.fname_to_rel_fnames = fname_to_rel_fnames
|
||||||
|
|
||||||
self.words = set()
|
self.words = set()
|
||||||
for rel_fname in addable_rel_fnames:
|
for rel_fname in addable_rel_fnames:
|
||||||
self.words.add(rel_fname)
|
self.words.add(rel_fname)
|
||||||
|
@ -51,11 +60,17 @@ class FileContentCompleter(Completer):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
candidates = self.words
|
candidates = self.words
|
||||||
|
candidates.update(set(self.fname_to_rel_fnames))
|
||||||
|
|
||||||
last_word = words[-1]
|
last_word = words[-1]
|
||||||
for word in candidates:
|
for word in candidates:
|
||||||
if word.lower().startswith(last_word.lower()):
|
if word.lower().startswith(last_word.lower()):
|
||||||
yield Completion(word, start_position=-len(last_word))
|
rel_fnames = self.fname_to_rel_fnames.get(word, [])
|
||||||
|
if rel_fnames:
|
||||||
|
for rel_fname in rel_fnames:
|
||||||
|
yield Completion(rel_fname, start_position=-len(last_word))
|
||||||
|
else:
|
||||||
|
yield Completion(word, start_position=-len(last_word))
|
||||||
|
|
||||||
|
|
||||||
class InputOutput:
|
class InputOutput:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue