mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
Merge branch 'call-graph' into gpt-35
This commit is contained in:
commit
b339df3f70
3 changed files with 41 additions and 28 deletions
|
@ -113,11 +113,12 @@ class RepoMap:
|
||||||
|
|
||||||
if self.has_ctags:
|
if self.has_ctags:
|
||||||
files_listing = self.get_ranked_tags_map(chat_files, other_files)
|
files_listing = self.get_ranked_tags_map(chat_files, other_files)
|
||||||
num_tokens = self.token_count(files_listing)
|
if files_listing:
|
||||||
if self.io:
|
num_tokens = self.token_count(files_listing)
|
||||||
self.io.tool_output(f"ctags map: {num_tokens/1024:.1f} k-tokens")
|
if self.io:
|
||||||
ctags_msg = " with selected ctags info"
|
self.io.tool_output(f"ctags map: {num_tokens/1024:.1f} k-tokens")
|
||||||
return files_listing, ctags_msg
|
ctags_msg = " with selected ctags info"
|
||||||
|
return files_listing, ctags_msg
|
||||||
|
|
||||||
files_listing = self.get_simple_files_map(other_files)
|
files_listing = self.get_simple_files_map(other_files)
|
||||||
ctags_msg = ""
|
ctags_msg = ""
|
||||||
|
|
|
@ -99,7 +99,7 @@ def replace_most_similar_chunk(whole, part, replace):
|
||||||
if max_similarity < similarity_thresh:
|
if max_similarity < similarity_thresh:
|
||||||
return
|
return
|
||||||
|
|
||||||
replace_lines = replace.splitlines()
|
replace_lines = replace.splitlines() + [""]
|
||||||
modified_whole = (
|
modified_whole = (
|
||||||
whole_lines[:most_similar_chunk_start]
|
whole_lines[:most_similar_chunk_start]
|
||||||
+ replace_lines
|
+ replace_lines
|
||||||
|
|
|
@ -8,7 +8,7 @@ from aider.repomap import RepoMap
|
||||||
|
|
||||||
|
|
||||||
class TestRepoMap(unittest.TestCase):
|
class TestRepoMap(unittest.TestCase):
|
||||||
def test_get_tags_map(self):
|
def test_get_repo_map(self):
|
||||||
# Create a temporary directory with sample files for testing
|
# Create a temporary directory with sample files for testing
|
||||||
test_files = [
|
test_files = [
|
||||||
"test_file1.py",
|
"test_file1.py",
|
||||||
|
@ -24,18 +24,18 @@ class TestRepoMap(unittest.TestCase):
|
||||||
|
|
||||||
repo_map = RepoMap(root=temp_dir)
|
repo_map = RepoMap(root=temp_dir)
|
||||||
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
||||||
result = repo_map.get_tags_map(other_files)
|
result = repo_map.get_repo_map([], other_files)
|
||||||
|
|
||||||
# Check if the result contains the expected tags map
|
# Check if the result contains the expected tags map
|
||||||
self.assertIn("test_file1.py:", result)
|
self.assertIn("test_file1.py", result)
|
||||||
self.assertIn("test_file2.py:", result)
|
self.assertIn("test_file2.py", result)
|
||||||
self.assertIn("test_file3.md:", result)
|
self.assertIn("test_file3.md", result)
|
||||||
self.assertIn("test_file4.json:", result)
|
self.assertIn("test_file4.json", result)
|
||||||
|
|
||||||
def test_get_tags_map_with_identifiers(self):
|
def test_get_repo_map_with_identifiers(self):
|
||||||
# Create a temporary directory with a sample Python file containing identifiers
|
# Create a temporary directory with a sample Python file containing identifiers
|
||||||
test_file = "test_file_with_identifiers.py"
|
test_file1 = "test_file_with_identifiers.py"
|
||||||
file_content = """\
|
file_content1 = """\
|
||||||
class MyClass:
|
class MyClass:
|
||||||
def my_method(self, arg1, arg2):
|
def my_method(self, arg1, arg2):
|
||||||
return arg1 + arg2
|
return arg1 + arg2
|
||||||
|
@ -44,16 +44,28 @@ def my_function(arg1, arg2):
|
||||||
return arg1 * arg2
|
return arg1 * arg2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
test_file2 = "test_file_import.py"
|
||||||
|
file_content2 = """\
|
||||||
|
from test_file_with_identifiers import MyClass
|
||||||
|
|
||||||
|
obj = MyClass()
|
||||||
|
print(obj.my_method(1, 2))
|
||||||
|
print(my_function(3, 4))
|
||||||
|
"""
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
with open(os.path.join(temp_dir, test_file), "w") as f:
|
with open(os.path.join(temp_dir, test_file1), "w") as f:
|
||||||
f.write(file_content)
|
f.write(file_content1)
|
||||||
|
|
||||||
|
with open(os.path.join(temp_dir, test_file2), "w") as f:
|
||||||
|
f.write(file_content2)
|
||||||
|
|
||||||
repo_map = RepoMap(root=temp_dir)
|
repo_map = RepoMap(root=temp_dir)
|
||||||
other_files = [os.path.join(temp_dir, test_file)]
|
other_files = [os.path.join(temp_dir, test_file1), os.path.join(temp_dir, test_file2)]
|
||||||
result = repo_map.get_tags_map(other_files)
|
result = repo_map.get_repo_map([], other_files)
|
||||||
|
|
||||||
# Check if the result contains the expected tags map with identifiers
|
# Check if the result contains the expected tags map with identifiers
|
||||||
self.assertIn("test_file_with_identifiers.py:", result)
|
self.assertIn("test_file_with_identifiers.py", result)
|
||||||
self.assertIn("MyClass", result)
|
self.assertIn("MyClass", result)
|
||||||
self.assertIn("my_method", result)
|
self.assertIn("my_method", result)
|
||||||
self.assertIn("my_function", result)
|
self.assertIn("my_function", result)
|
||||||
|
@ -61,7 +73,7 @@ def my_function(arg1, arg2):
|
||||||
def test_check_for_ctags_failure(self):
|
def test_check_for_ctags_failure(self):
|
||||||
with patch("subprocess.run") as mock_run:
|
with patch("subprocess.run") as mock_run:
|
||||||
mock_run.side_effect = Exception("ctags not found")
|
mock_run.side_effect = Exception("ctags not found")
|
||||||
repo_map = RepoMap(use_ctags=True)
|
repo_map = RepoMap()
|
||||||
result = repo_map.check_for_ctags()
|
result = repo_map.check_for_ctags()
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
|
|
||||||
|
@ -75,11 +87,11 @@ def my_function(arg1, arg2):
|
||||||
b' status = main()$/", "kind": "variable"}'
|
b' status = main()$/", "kind": "variable"}'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
repo_map = RepoMap(use_ctags=True)
|
repo_map = RepoMap()
|
||||||
result = repo_map.check_for_ctags()
|
result = repo_map.check_for_ctags()
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_get_tags_map_without_ctags(self):
|
def test_get_repo_map_without_ctags(self):
|
||||||
# Create a temporary directory with a sample Python file containing identifiers
|
# Create a temporary directory with a sample Python file containing identifiers
|
||||||
test_files = [
|
test_files = [
|
||||||
"test_file_without_ctags.py",
|
"test_file_without_ctags.py",
|
||||||
|
@ -96,15 +108,15 @@ def my_function(arg1, arg2):
|
||||||
with open(os.path.join(temp_dir, file), "w") as f:
|
with open(os.path.join(temp_dir, file), "w") as f:
|
||||||
f.write("")
|
f.write("")
|
||||||
|
|
||||||
repo_map = RepoMap(use_ctags=False, root=temp_dir)
|
repo_map = RepoMap(root=temp_dir)
|
||||||
|
repo_map.has_ctags = False # force it off
|
||||||
|
|
||||||
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
other_files = [os.path.join(temp_dir, file) for file in test_files]
|
||||||
result = repo_map.get_tags_map(other_files)
|
result = repo_map.get_repo_map([], other_files)
|
||||||
|
|
||||||
# Check if the result contains each specific file in the expected tags map without ctags
|
# Check if the result contains each specific file in the expected tags map without ctags
|
||||||
for file in test_files:
|
for file in test_files:
|
||||||
self.assertIn(
|
self.assertIn(file, result)
|
||||||
f"{os.path.splitext(file)[0]}.{os.path.splitext(file)[1][1:]}:", result
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue