Skip to content

feat: initial implementation of codeanalyzer-go - #4

Merged
rahlk merged 7 commits into
mainfrom
feat/initial-implementation
Jul 10, 2026
Merged

feat: initial implementation of codeanalyzer-go#4
rahlk merged 7 commits into
mainfrom
feat/initial-implementation

Conversation

@sinha108

Copy link
Copy Markdown
Contributor

Summary

  • Static analyzer for Go projects producing analysis.json (symbol table + call graph) in the CLDK canonical schema
  • Consumable by the Python SDK via CLDK(language="go").analysis(project_path=...)
  • Level 1: symbol table via go/ast + golang.org/x/tools/go/packages
  • Level 2: resolver-based call graph via go/types

What's included

  • cmd/codeanalyzer — Cobra CLI (-i, -o, -a, -t, --skip-tests, --eager, --cache-dir, -v, --version)
  • internal/syntactic_analysisSymbolTableBuilder: structs, interfaces, methods, generics, closures, call sites, cyclomatic complexity, struct tags, cross-file method reconciliation
  • internal/semantic_analysisCallGraphBuilder: go/types resolver backfills callee_signature and emits project-internal call edges; CodeQL backend wired but stubbed
  • internal/analysis — pluggable pass registry with topological ordering (extension seam for framework passes)
  • internal/frameworksBaseEntrypointFinder seam for Gin/net-http entrypoint detection
  • internal/schema — canonical output types (GoApplication, GoFile, GoType, GoCallable, GoCallsite, GoCallEdge) with spine-compatible JSON keys

Test fixtures

FixturePurpose
testdata/greeter/Minimal two-package fixture (struct, interface, basic call sites)
testdata/multipackage/Embedded fields, variadic params, goroutines, cross-file methods, multiple return types
testdata/generics/Go 1.18+ generics (Set[T], union-constraint interfaces, multi-type-param functions)
testdata/chi/Vendored chi v5 (35 files) — real-world HTTP router patterns, closures, init()

105 tests across symbol table correctness, call graph edges, generics, JSON round-trip, caching, incremental analysis, and error paths.

Test plan

  • go test ./... passes (all 105 tests)
  • go build ./... succeeds
  • go vet ./... clean
  • Level 1 analysis on a real project produces valid analysis.json
  • Level 2 analysis produces non-empty call graph with no dangling edges

Adds the static code analysis engine for Go including syntactic analysis,
schema definitions, CLI entrypoint, and test fixtures. Semantic analysis
via CodeQL is scaffolded but not yet implemented.
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Incorporates the GitHub Go template (*.dll, *.so, go.work, .env, etc.)
alongside project-specific ignores for built binaries and .claude/.
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Bug fix: populate InnerCallables by walking ast.FuncLit nodes in
buildInnerCallables; add *ast.FuncLit: return false to buildCallSites so
closure call sites are not double-counted in the outer function.
New test files:
- cmd/codeanalyzer/main_test.go: CLI integration tests covering --version,
--format validation, --output, --analysis-level, --skip-tests, --target-files
- internal/analysis/registry_test.go: orderPasses topo-sort tests and
RunPipeline smoke test
- internal/semantic_analysis/call_graph_test.go: MergeEdges unit tests
- internal/utils/fs_test.go: table-driven tests for IsTestFile, IsVendored,
FileHash, EnsureDir, DiscoverGoFiles
- internal/core/skip_tests_test.go: SkipTests true/false behaviour
- internal/core/incremental_test.go: TargetFiles single/multi package and nil
Test additions to existing files:
- chi_test.go: InnerCallables populated, IsConstructorCall for methodTyp()
type conversion, init() presence and is_exported
- multipackage_test.go (renamed from realistic_test.go): LocalVariables
present with correct type and scope
Testdata restructure:
- testdata/fixture/ -> testdata/greeter/
- testdata/realistic/ -> testdata/multipackage/
- testdata/chi/: replace single-file wrapper with chi v5 library source (35 files)
- testdata/generics/: add generics fixture (fn + set packages)
- testdata/multipackage/server/server_test.go: minimal test file for
--skip-tests=false coverage
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
- Add .github/workflows/ci.yml: test (go build + go test) and lint
(golangci-lint) jobs triggered on push to main/feat/** and PRs to main
- Fix stale testdata path references in README (fixture/→greeter/,
realistic/→multipackage/) and update test count (57→105)
- Add /output/ to .gitignore to exclude generated analysis artifacts
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
@sinha108
sinha108 requested a review from rahlkJuly 3, 2026 17:42
golangci-lint-action@v6 resolved to v1.64.8 (built with Go 1.24) which
refuses to analyze go 1.25.0 modules. Installing via go install compiles
the tool from source using the project's own toolchain, so the version
check always passes.
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
- fs_test.go: use writeFile helper for TestFileHash_DifferentContent
and check os.MkdirAll error in TestDiscoverGoFiles_SkipsVendorDir
- signature.go: remove unused signatureOfNamed, signatureForCall,
normalizeReturnType functions and their unused strings import
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Mirror the codeanalyzer-typescript release pipeline: cross-compile the
self-contained binary for all platforms and publish to GitHub Releases,
PyPI (platform-tagged wheels), and Homebrew.
- CLI: make `cango` the canonical command with `codeanalyzer-go` as a
backwards-compatible alias; version is now a var injected at build time
via -ldflags so the tag, wheel, and `cango --version` stay in lockstep.
- packaging/python: hatchling wheel wrapper bundling the prebuilt binary
per platform; installs both `cango` and `codeanalyzer-go` launchers and
exposes codeanalyzer_go.bin_path() for the CLDK Python SDK.
- packaging/homebrew + packaging/install: formula generator and curl|sh
installer, both installing `cango` with a `codeanalyzer-go` alias.
- .github/workflows/release.yml + configuration.json: tag-triggered
release (test gate, wheels, raw binaries, PyPI via OIDC, Homebrew tap,
changelog, org/repo discussions).
- README: restructure to match siblings (header, badges, install
sections, cango examples).
Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
@sinha108
sinha108 marked this pull request as ready for review July 4, 2026 16:56
@rahlk
rahlk merged commit bb151ef into mainJul 10, 2026
4 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@sinha108@rahlk