Skip to content

Commit 8a19a91

Browse files
authored
Merge pull request #127 from FSoft-AI4Code/feat/rust-support
analyzers: add tree-sitter based Rust analyzer
2 parents 208473a + d3e0565 commit 8a19a91

17 files changed

Lines changed: 1185 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to CodeWiki. The format follows
44
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project
55
uses [Semantic Versioning](https://semver.org/).
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- **Rust analyzer.** Structs, unions, enums, traits, free functions, and
12+
impl/trait methods become components, with trait-impl, field-type,
13+
struct-literal, and call edges. `#[cfg(test)]` modules are skipped, and
14+
`build.rs` is classified as a build artifact.
15+
716
## [2.0.0] - 2026-09-18
817

918
The first release since 1.0.1. Everything that landed on `main` in between is

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Full list in the [CHANGELOG](./CHANGELOG.md).
119119
## Features
120120

121121
**Languages.** Python, Java, JavaScript, TypeScript, C, C++, C#, Kotlin,
122-
PHP, Ruby, Scala.
122+
PHP, Ruby, Scala, Rust.
123123

124124
**Hierarchical decomposition.** The dependency graph is clustered into a
125125
module tree, recursively, so a 1.4M-line repository gets the same treatment

‎codewiki/cli/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def cli(ctx):
2020
2121
AI agents write the documentation from your dependency graph. Supports
2222
Python, Java, JavaScript, TypeScript, C, C++, C#, Kotlin, PHP, Ruby,
23-
and Scala.
23+
Scala, and Rust.
2424
"""
2525
# Ensure context object exists
2626
ctx.ensure_object(dict)

‎codewiki/cli/utils/repo_validator.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
".rb", # Ruby
3434
".scala", # Scala
3535
".sc", # Scala Scripts
36+
".rs", # Rust
3637
}
3738

3839

@@ -64,7 +65,7 @@ def validate_repository(repo_path: Path) -> tuple[Path, list[tuple[str, int]]]:
6465
raise RepositoryError(
6566
f"No supported code files found in {repo_path}\n\n"
6667
"CodeWiki supports: Python, Java, JavaScript, TypeScript, C, C++, C#, Kotlin, PHP, "
67-
"Ruby, Scala\n\n"
68+
"Ruby, Scala, Rust\n\n"
6869
"Please navigate to a code repository or specify a custom directory:\n"
6970
" cd /path/to/your/project\n"
7071
" codewiki generate"

‎codewiki/cli/utils/validation.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def detect_supported_languages(directory: Path) -> list[tuple[str, int]]:
167167
"Kotlin": [".kt", ".kts"],
168168
"Ruby": [".rb"],
169169
"Scala": [".scala", ".sc"],
170+
"Rust": [".rs"],
170171
}
171172

172173
# Directories to exclude from counting

‎codewiki/mcp/tools/analysis.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def _detect_via_mtime(
228228
".rb",
229229
".scala",
230230
".sc",
231+
".rs",
231232
}
232233

233234
changed: list[str] = []

‎codewiki/src/be/dependency_analyzer/analysis/analysis_service.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ def _filter_supported_languages(self, code_files: list[dict]) -> list[dict]:
339339
"""
340340
Filter code files to only include supported languages.
341341
342-
Supports Python, JavaScript, TypeScript, Java, C#, C, C++, PHP, Ruby, Go, and Rust.
342+
Supports Python, JavaScript, TypeScript, Java, C#, C, C++, PHP, Ruby, Kotlin,
343+
Scala, and Rust.
343344
"""
344345
supported_languages = {
345346
"python",
@@ -377,6 +378,7 @@ def _get_supported_languages(self) -> list[str]:
377378
"ruby",
378379
"kotlin",
379380
"scala",
381+
"rust",
380382
]
381383

382384
def _cleanup_repository(self, temp_dir: str):

‎codewiki/src/be/dependency_analyzer/analysis/call_graph_analyzer.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def _analyze_code_file(self, repo_dir: str, file_info: dict):
259259
self._analyze_ruby_file(file_path, content, repo_dir)
260260
elif language == "scala":
261261
self._analyze_scala_file(file_path, content, repo_dir)
262+
elif language == "rust":
263+
self._analyze_rust_file(file_path, content, repo_dir)
262264
# else:
263265
# logger.warning(
264266
# f"Unsupported language for call graph analysis: {language} for file {file_path}"
@@ -536,6 +538,28 @@ def _analyze_scala_file(self, file_path: str, content: str, repo_dir: str):
536538
except Exception:
537539
logger.exception(f"Failed to analyze Scala file {file_path}")
538540

541+
def _analyze_rust_file(self, file_path: str, content: str, repo_dir: str):
542+
"""
543+
Analyze Rust file using tree-sitter based analyzer.
544+
545+
Args:
546+
file_path: Relative path to the Rust file
547+
content: File content string
548+
repo_dir: Repository base directory
549+
"""
550+
from codewiki.src.be.dependency_analyzer.analyzers.rust import analyze_rust_file
551+
552+
try:
553+
functions, relationships = analyze_rust_file(file_path, content, repo_path=repo_dir)
554+
555+
for func in functions:
556+
func_id = func.id if func.id else f"{file_path}:{func.name}"
557+
self.functions[func_id] = func
558+
559+
self.call_relationships.extend(relationships)
560+
except Exception:
561+
logger.exception(f"Failed to analyze Rust file {file_path}")
562+
539563
def _resolve_call_relationships(self):
540564
"""
541565
Resolve function call relationships across all languages.
@@ -834,6 +858,8 @@ def _generate_visualization_data(self) -> dict:
834858
node_classes.append("lang-ruby")
835859
elif file_ext in [".scala", ".sc"]:
836860
node_classes.append("lang-scala")
861+
elif file_ext == ".rs":
862+
node_classes.append("lang-rust")
837863

838864
cytoscape_elements.append(
839865
{

‎codewiki/src/be/dependency_analyzer/analyzers/artifact.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def is_artifact_file_node(node: Any) -> bool:
278278
_BUILD_NAMES = {
279279
"Makefile",
280280
"GNUmakefile",
281+
"build.rs",
281282
"makefile",
282283
"CMakeLists.txt",
283284
"Rakefile",

0 commit comments

Comments
 (0)