From dfcf813ad63109fccc05456fd2bb2b33cd162410 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 14:45:57 -0700 Subject: [PATCH 1/3] include individual files in the ranked tags list, following specific ranked idents --- aider/repomap.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index 2189bdd8b..ea8c31e79 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -31,11 +31,15 @@ def to_tree(tags): for tag in tags: tag = list(tag) - for i in range(len(last)): + for i in range(len(last) + 1): + if i == len(last): + break if last[i] != tag[i]: break num_common = i + dump(repr(tag), num_common) + indent = tab * num_common rest = tag[num_common:] for item in rest: @@ -283,11 +287,6 @@ class RepoMap: except ZeroDivisionError: return [] - # top_rank = sorted([(rank, node) for (node, rank) in ranked.items()], reverse=True) - # Print the PageRank of each node - # for rank, node in top_rank: - # print(f"{rank:.03f} {node}") - # distribute the rank from each source node, across all of its out edges ranked_definitions = defaultdict(float) for src in G.nodes: @@ -307,6 +306,10 @@ class RepoMap: continue ranked_tags += list(definitions.get((fname, ident), [])) + top_rank = sorted([(rank, node) for (node, rank) in ranked.items()], reverse=True) + for rank, fname in top_rank: + ranked_tags.append((fname,)) + return ranked_tags def get_ranked_tags_map(self, chat_fnames, other_fnames=None): From 53e8c657451e4917b6f67d7a480cc2b95a2456d9 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 14:53:14 -0700 Subject: [PATCH 2/3] Return files without any tags at all at the tail of the ranked_tags list --- aider/repomap.py | 11 +++++++++++ tests/test_repomap.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/aider/repomap.py b/aider/repomap.py index ea8c31e79..ccd0f24d5 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -306,8 +306,19 @@ class RepoMap: continue ranked_tags += list(definitions.get((fname, ident), [])) + rel_other_fnames_without_tags = set( + os.path.relpath(fname, self.root) for fname in other_fnames + ) + + fnames_already_included = set(rt[0] for rt in ranked_tags) + top_rank = sorted([(rank, node) for (node, rank) in ranked.items()], reverse=True) for rank, fname in top_rank: + rel_other_fnames_without_tags.remove(fname) + if fname not in fnames_already_included: + ranked_tags.append((fname,)) + + for fname in rel_other_fnames_without_tags: ranked_tags.append((fname,)) return ranked_tags diff --git a/tests/test_repomap.py b/tests/test_repomap.py index f1902acef..18c9d3c3d 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -53,6 +53,9 @@ print(obj.my_method(1, 2)) print(my_function(3, 4)) """ + test_file3 = "test_file_pass.py" + file_content3 = "pass" + with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, test_file1), "w") as f: f.write(file_content1) @@ -60,8 +63,15 @@ print(my_function(3, 4)) with open(os.path.join(temp_dir, test_file2), "w") as f: f.write(file_content2) + with open(os.path.join(temp_dir, test_file3), "w") as f: + f.write(file_content3) + repo_map = RepoMap(root=temp_dir) - other_files = [os.path.join(temp_dir, test_file1), os.path.join(temp_dir, test_file2)] + other_files = [ + os.path.join(temp_dir, test_file1), + os.path.join(temp_dir, test_file2), + os.path.join(temp_dir, test_file3), + ] result = repo_map.get_repo_map([], other_files) # Check if the result contains the expected tags map with identifiers @@ -69,6 +79,7 @@ print(my_function(3, 4)) self.assertIn("MyClass", result) self.assertIn("my_method", result) self.assertIn("my_function", result) + self.assertIn("test_file_pass.py", result) def test_check_for_ctags_failure(self): with patch("subprocess.run") as mock_run: From c0bf25d05bd7a27d139e596c7f517cb49b0b41e0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 4 Jun 2023 15:03:13 -0700 Subject: [PATCH 3/3] undo trailing newline "fix" --- aider/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 61af34379..942d72757 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -99,10 +99,7 @@ def replace_most_similar_chunk(whole, part, replace): if max_similarity < similarity_thresh: return - if replace: - replace_lines = replace.splitlines() + [""] - else: - replace_lines = [] + replace_lines = replace.splitlines() modified_whole = ( whole_lines[:most_similar_chunk_start]