From 08164034ff94e78d74e2df141fe528f21dd8f7a3 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 08:34:20 -0700 Subject: [PATCH] aider: Updated check_for_file_mentions to only add a filename match if it is unambiguous and no other addable_rel_fnames have a basename that also matches. # Context: USER: on check_for_file_mentions, only add a fname match if it is unambiguous and no other addable_rel_fnames have a basename that also matches ASSISTANT: To update the `check_for_file_mentions` method to only add a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches, modify the method as follows: ```python aider/coder.py <<<<<<< ORIGINAL for rel_fname in addable_rel_fnames: fname = os.path.basename(rel_fname) if fname in words or rel_fname in words: mentioned_rel_fnames.add(rel_fname) ======= fname_to_rel_fnames = {} for rel_fname in addable_rel_fnames: fname = os.path.basename(rel_fname) if fname not in fname_to_rel_fnames: fname_to_rel_fnames[fname] = [] fname_to_rel_fnames[fname].append(rel_fname) for fname, rel_fnames in fname_to_rel_fnames.items(): if len(rel_fnames) == 1 and (fname in words or rel_fnames[0] in words): mentioned_rel_fnames.add(rel_fnames[0]) >>>>>>> UPDATED ``` This change will ensure that the method only adds a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches. --- aider/coder.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aider/coder.py b/aider/coder.py index 7dd8153e9..85e94f60a 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -344,10 +344,16 @@ class Coder: ) mentioned_rel_fnames = set() + fname_to_rel_fnames = {} for rel_fname in addable_rel_fnames: fname = os.path.basename(rel_fname) - if fname in words or rel_fname in words: - mentioned_rel_fnames.add(rel_fname) + if fname not in fname_to_rel_fnames: + fname_to_rel_fnames[fname] = [] + fname_to_rel_fnames[fname].append(rel_fname) + + for fname, rel_fnames in fname_to_rel_fnames.items(): + if len(rel_fnames) == 1 and (fname in words or rel_fnames[0] in words): + mentioned_rel_fnames.add(rel_fnames[0]) if not mentioned_rel_fnames: return