MCPcopy Index your code
hub / github.com/HKUDS/DeepCode / find_direct_relationships_in_cache

Function find_direct_relationships_in_cache

tools/code_reference_indexer.py:198–236  ·  view source on GitHub ↗

Find direct relationships with target file from provided cache

(
    target_file: str, index_cache: Dict[str, Dict]
)

Source from the content-addressed store, hash-verified

196
197
198def find_direct_relationships_in_cache(
199 target_file: str, index_cache: Dict[str, Dict]
200) -> List[RelationshipInfo]:
201 """Find direct relationships with target file from provided cache"""
202 relationships = []
203
204 # Normalize target file path (remove common prefixes if exists)
205 common_prefixes = ["src/", "core/", "lib/", "main/", "./"]
206 normalized_target = target_file.strip("/")
207 for prefix in common_prefixes:
208 if normalized_target.startswith(prefix):
209 normalized_target = normalized_target[len(prefix) :]
210 break
211
212 # Collect relationship information from all index files
213 for repo_name, index_data in index_cache.items():
214 repo_relationships = extract_relationships(index_data)
215 for rel in repo_relationships:
216 # Normalize target file path in relationship
217 normalized_rel_target = rel.target_file_path.strip("/")
218 for prefix in common_prefixes:
219 if normalized_rel_target.startswith(prefix):
220 normalized_rel_target = normalized_rel_target[len(prefix) :]
221 break
222
223 # Check target file path matching (support multiple matching methods)
224 if (
225 normalized_target == normalized_rel_target
226 or normalized_target in normalized_rel_target
227 or normalized_rel_target in normalized_target
228 or target_file in rel.target_file_path
229 or rel.target_file_path in target_file
230 ):
231 relationships.append(rel)
232
233 # Sort by confidence score
234 relationships.sort(key=lambda x: x.confidence_score, reverse=True)
235
236 return relationships
237
238
239def format_reference_output(

Callers 1

search_code_referencesFunction · 0.85

Calls 1

extract_relationshipsFunction · 0.85

Tested by

no test coverage detected