From a716fda897be96df81e6a805533c4139e5793875 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 26 Aug 2024 13:49:11 -0700 Subject: [PATCH] fix: Handle partial filename matches correctly in find_filename --- aider/coders/editblock_coder.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index ea29b1f30..0683daeaf 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -540,15 +540,15 @@ def find_filename(lines, fence, valid_fnames): # pick the *best* filename found - # pick a valid fname + # Check for exact match first for fname in filenames: if fname in valid_fnames: return fname - # match just on basename, return full valid fname + # Check for partial match (basename match) for fname in filenames: for vfn in valid_fnames: - if fname == vfn.name: + if fname == Path(vfn).name: return vfn # Perform fuzzy matching with valid_fnames @@ -562,7 +562,7 @@ def find_filename(lines, fence, valid_fnames): if "." in fname: return fname - return filenames[0] + return filenames[0] if filenames else None def find_similar_lines(search_lines, content_lines, threshold=0.6):