Static analyzer for Go projects, compatible with CodeLLM DevKit (CLDK). Produces Symbol Table and Call Graph in stable JSON format.
- Symbol Table Extraction: packages, imports, types (struct/interface/alias), functions, methods, variables, constants
- Call Graph Construction: using
golang.org/x/tools/go/ssawith CHA or RTA algorithms - CLDK Compatible: output follows CLDK schema conventions for seamless integration
- Flexible Filtering: exclude directories, filter by package path, include/exclude tests
- Position Tracking: detailed or minimal source position information
This analyzer is designed to work with CodeLLM DevKit (CLDK). If you plan to use it with CLDK:
-
First, fork/clone the CLDK repository:
git clone https://github.com/codellm-devkit/cldk.git
-
Then, fork/clone this analyzer (separate repository):
git clone https://github.com/battuto/codeanalyzer-go.git
cd codeanalyzer-go
go build -o bin/codeanalyzer-go ./cmd/codeanalyzer-goYou can also use this analyzer independently without CLDK:
go install github.com/battuto/codeanalyzer-go/cmd/codeanalyzer-go@latest# Analyze a project (full analysis to stdout)
codeanalyzer-go --input /path/to/project
# Symbol table only
codeanalyzer-go --input ./myproject --analysis-level symbol_table
# Call graph with RTA algorithm
codeanalyzer-go --input ./myproject --analysis-level call_graph --cg rta
# Save output to directory
codeanalyzer-go --input ./myproject --output ./outputcodeanalyzer-go [flags]
| Flag | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Path to Go project root | . |
--output |
-o |
Output directory (omit for stdout) | stdout |
--analysis-level |
-a |
Analysis level: symbol_table, call_graph, full |
full |
--cg |
Call graph algorithm: cha, rta |
rta |
|
--format |
-f |
Output format: json |
json |
| Flag | Description | Example |
|---|---|---|
--include-tests |
Include *_test.go files |
--include-tests |
--exclude-dirs |
Comma-separated directories to exclude | --exclude-dirs vendor,testdata |
--only-pkg |
Filter packages by path substring | --only-pkg myapp/internal |
| Flag | Description | Default |
|---|---|---|
--emit-positions |
Position detail: detailed, minimal |
detailed |
--include-body |
Include function body information | false |
--verbose, -v |
Enable verbose logging to stderr | false |
--quiet, -q |
Suppress non-error output | false |
--version |
Show version and exit |
The output follows CLDK conventions with this structure:
{
"metadata": {
"analyzer": "codeanalyzer-go",
"version": "2.0.0",
"language": "go",
"analysis_level": "full",
"timestamp": "2026-02-01T12:00:00Z",
"project_path": "/path/to/project",
"go_version": "go1.21",
"analysis_duration_ms": 1234
},
"symbol_table": {
"packages": {
"example.com/myapp": {
"path": "example.com/myapp",
"name": "myapp",
"files": ["main.go", "util.go"],
"imports": [{"path": "fmt"}],
"type_declarations": {"example.com/myapp.Config": {...}},
"callable_declarations": {"example.com/myapp.main": {...}},
"variables": {...},
"constants": {...}
}
}
},
"call_graph": {
"algorithm": "rta",
"nodes": [{"id": "example.com/myapp.main", "kind": "function", ...}],
"edges": [{"source": "example.com/myapp.main", "target": "fmt.Println", "kind": "call"}]
},
"pdg": null,
"sdg": null,
"issues": []
}- Maps, not arrays:
packages,type_declarations,callable_declarationsare maps keyed by qualified name - Qualified names: Format is
pkg.Funcorpkg.(*Type).Method - Positions: Include
file,start_line,start_column
| Algorithm | Description | Best For |
|---|---|---|
| CHA | Class Hierarchy Analysis - conservative, includes all possible call targets | Complete analysis, interface-heavy code |
| RTA | Rapid Type Analysis - more precise, starts from main() |
Focused analysis, smaller output |
# CHA (more conservative)
codeanalyzer-go --input ./myapp --analysis-level call_graph --cg cha
# RTA (more precise, requires main package)
codeanalyzer-go --input ./myapp --analysis-level call_graph --cg rtafrom cldk.analysis import GoAnalyzer
analyzer = GoAnalyzer()
result = analyzer.analyze("/path/to/project", level="call_graph")
# Access symbol table
for pkg_path, pkg in result.symbol_table.packages.items():
print(f"Package: {pkg.name}")
for fn_name, fn in pkg.callable_declarations.items():
print(f" Function: {fn.name} - {fn.signature}")
# Access call graph
for edge in result.call_graph.edges:
print(f"{edge.source} -> {edge.target}")# Build the analyzer
go build -o bin/codeanalyzer-go ./cmd/codeanalyzer-go
# Run Go unit tests
go test ./...
# Run Python integration tests
python tests/cldk_integration_test.py| Code | Meaning |
|---|---|
0 |
Success |
1 |
Analysis errors (partial results may be available) |
2 |
Configuration or validation errors |
The following flags are deprecated but still supported for backward compatibility:
| Deprecated | Use Instead |
|---|---|
--root |
--input |
--mode |
--analysis-level |
--out |
--output |
--include-test |
--include-tests |
RTA requires a main package as entry point. If your project is a library, use CHA instead:
codeanalyzer-go --input ./mylib --analysis-level call_graph --cg chaFor large codebases, use filters to reduce analysis scope:
codeanalyzer-go --input ./bigproject \
--exclude-dirs vendor,testdata,examples \
--only-pkg mycompany/bigproject/coreEnable verbose mode to see analysis progress:
codeanalyzer-go --input ./myproject --verbosecodeanalyzer-go/
βββ cmd/codeanalyzer-go/ # CLI entry point
βββ internal/
β βββ loader/ # Package loading with SSA support
β βββ symbols/ # Symbol table extraction
β βββ callgraph/ # Call graph construction
β βββ output/ # JSON output writer
βββ pkg/schema/ # CLDK schema definitions
βββ tests/ # Integration tests
βββ sampleapp/ # Sample Go project for testing
This project is licensed under the MIT License - see the LICENSE file for details.