MCPcopy
hub / github.com/HKUDS/DeepCode / analyze_file_content

Method analyze_file_content

tools/code_indexer.py:753–863  ·  view source on GitHub ↗

Analyze a single file and create summary with caching support

(self, file_path: Path)

Source from the content-addressed store, hash-verified

751 )
752
753 async def analyze_file_content(self, file_path: Path) -> FileSummary:
754 """Analyze a single file and create summary with caching support"""
755 try:
756 # Check file size before reading
757 file_size = file_path.stat().st_size
758 if file_size > self.max_file_size:
759 self.logger.warning(
760 f"Skipping file {file_path} - size {file_size} bytes exceeds limit {self.max_file_size}"
761 )
762 return FileSummary(
763 file_path=str(file_path.relative_to(self.code_base_path)),
764 file_type="skipped - too large",
765 main_functions=[],
766 key_concepts=[],
767 dependencies=[],
768 summary=f"File skipped - size {file_size} bytes exceeds {self.max_file_size} byte limit",
769 lines_of_code=0,
770 last_modified=datetime.fromtimestamp(
771 file_path.stat().st_mtime
772 ).isoformat(),
773 )
774
775 # Check cache if enabled
776 cache_key = None
777 if self.enable_content_caching:
778 cache_key = self._get_cache_key(file_path)
779 if cache_key in self.content_cache:
780 if self.verbose_output:
781 self.logger.info(f"Using cached analysis for {file_path.name}")
782 return self.content_cache[cache_key]
783
784 with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
785 content = f.read()
786
787 # Get file stats
788 stats = file_path.stat()
789 lines_of_code = len([line for line in content.split("\n") if line.strip()])
790
791 # Truncate content based on config
792 content_for_analysis = content[: self.max_content_length]
793 content_suffix = "..." if len(content) > self.max_content_length else ""
794
795 # Create analysis prompt
796 analysis_prompt = f"""
797 Analyze this code file and provide a structured summary:
798
799 File: {file_path.name}
800 Content:
801 ```
802 {content_for_analysis}{content_suffix}
803 ```
804
805 Please provide analysis in this JSON format:
806 {{
807 "file_type": "description of what type of file this is",
808 "main_functions": ["list", "of", "main", "functions", "or", "classes"],
809 "key_concepts": ["important", "concepts", "algorithms", "patterns"],
810 "dependencies": ["external", "libraries", "or", "imports"],

Calls 5

_get_cache_keyMethod · 0.95
_call_llmMethod · 0.95
_manage_cache_sizeMethod · 0.95
FileSummaryClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected