Skip to content

Commit 0e5feb9

Browse files
authored
add to top instead of bottom (#3336)
2 parents b19355c + 1a53a66 commit 0e5feb9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sweepai/core/context_pruning.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ def add_snippets(self, snippets_to_add: list[Snippet]):
277277
for snippet in snippets_to_add:
278278
self.current_top_snippets.append(snippet)
279279

280+
# does the same thing as add_snippets but adds it to the beginning of the list
281+
def boost_snippets_to_top(self, snippets_to_boost: list[Snippet]):
282+
self.dir_obj.add_file_paths([snippet.file_path for snippet in snippets_to_boost])
283+
for snippet in snippets_to_boost:
284+
self.current_top_snippets.insert(0, snippet)
285+
280286
def add_import_trees(self, import_trees: str):
281287
self.import_trees += "\n" + import_trees
282288

@@ -411,7 +417,7 @@ def add_relevant_files_to_top_snippets(rcm: RepoContextManager) -> RepoContextMa
411417
code_snippets = [
412418
snippet for snippet in rcm.snippets if snippet.file_path == file
413419
]
414-
rcm.add_snippets(code_snippets)
420+
rcm.boost_snippets_to_top(code_snippets)
415421
except Exception as e:
416422
logger.error(
417423
f"Tried to add code file found in query but recieved error: {e}, skipping and continuing to next one."
@@ -484,11 +490,11 @@ def get_relevant_context(
484490
client = get_client()
485491
try:
486492
# attempt to get import tree for relevant snippets that show up in the query
487-
repo_context_manager, import_graph = parse_query_for_files(
493+
repo_context_manager, _ = parse_query_for_files(
488494
query, repo_context_manager
489495
)
490-
# for any code file mentioned in the query, build its import tree
491-
repo_context_manager = build_import_trees(repo_context_manager, import_graph, override_import_graph=override_import_graph)
496+
# for any code file mentioned in the query, build its import tree - This is currently not used
497+
# repo_context_manager = build_import_trees(repo_context_manager, import_graph, override_import_graph=override_import_graph)
492498
# for any code file mentioned in the query add it to the top relevant snippets
493499
repo_context_manager = add_relevant_files_to_top_snippets(repo_context_manager)
494500
# add relevant files to dir_obj inside repo_context_manager, this is in case dir_obj is too large when as a string

0 commit comments

Comments
 (0)