Add go support#230
Draft
sinha108 wants to merge 6 commits into
Draft
Conversation
Wires CLDK(language="go") end to end: Models (cldk/models/go/): - 9 Pydantic models mirroring codeanalyzer-go schema: GoApplication, GoFile, GoType, GoCallable, GoCallsite, GoCallEdge, GoField, GoParameter, GoImport, GoComment, GoSymbol, GoVariableDeclaration, GoEntrypoint. - _NullSafeBase coerces JSON null to empty list/dict for nil-slice serialization from Go. - GoFile.types / .package_name aliases for spine compatibility. Analysis facade (cldk/analysis/go/): - GoCodeanalyzer subprocess wrapper: shells out to codeanalyzer-go binary discovered via shutil.which(); passes --analysis-level as integer (1/2), not enum string. - GoAnalysis facade: get_application_view, get_symbol_table, get_file, get_all_types, get_types_in_file, get_type, get_all_callables, get_callables_in_file, get_callable, get_call_graph (nx.DiGraph), get_callers, get_callees, get_call_graph_edges. Core dispatch (cldk/core.py): - elif language == "go" branch; rejects source_code mode. pyproject.toml: codeanalyzer-go = "0.1.0" pinned under [tool.backend-versions]. Tests: - 17 mocked SDK tests (backend patched, no binary required). - 25 E2E tests against a multi-package Go fixture; skipif when codeanalyzer-go is absent from PATH. - Fixture: calc (Calculator, Operator interface, embedded field, pointer/value receivers, multi-return, cross-file method) + pipeline (goroutine, variadic, cyclomatic complexity) + main.go. Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
- TOC: add Go under Analysis Backends - Mermaid diagram: add cldk.analysis.go → codeanalyzer-go branch and Go models node - Update "full support for Java, Python, C" → include Go - Update cldk.models example list to include cldk.models.go - Add Go backend section: tools, capabilities, prerequisites, usage snippet Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Merges origin/main (40 commits) and adapts the Go language support to the refactored per-language factory pattern introduced on main. Conflict resolutions: - pyproject.toml: bump codeanalyzer-java/python/typescript to main versions; retain codeanalyzer-go = 0.1.0 in [tool.backend-versions] - README.md: adopt main's cleaner structure; add Go row to supported-languages table, Go node to architecture Mermaid diagram, CLDK.go() in Quick Start - cldk/core.py: keep main's per-language factory layout; add CLDK.go() factory and wire Go into the deprecated analysis() shim via GoCodeAnalyzerConfig - uv.lock: regenerated from resolved pyproject.toml API conformance (Go): - backend_config.py: add GoCodeAnalyzerConfig dataclass, GoBackend union, and "go" key in _CACHE_KEYS so cache_subdir computes the right output path - GoAnalysis.__init__: replace (analysis_backend_path, analysis_json_path, cache_dir) with backend: GoBackend | None = None; derive output path via cache_subdir(backend.cache_dir, project_dir, "go") - GoCodeanalyzer.__init__: drop analysis_backend_path (always PATH) and cache_dir (folded into analysis_json_path); clean up unused imports - core.py: add CLDK.go() static factory; update analysis() Go branch to call CLDK.go() with GoCodeAnalyzerConfig - Tests: update GoAnalysis instantiations to use new backend= API Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
…sis=True Previously GoCodeanalyzer bypassed its own analysis.json cache when eager_analysis=True, but never forwarded --eager to the binary. The binary's own internal cache (~/.cldk/go-cache) was therefore still used, so repeated eager calls could return stale results. Pass --eager to the subprocess args unconditionally when eager_analysis is set; the binary will force a clean rebuild and ignore its cache. Tests: add test_eager_flag_passed_to_binary and test_eager_flag_absent_when_not_eager in test_go_analysis.py, patching subprocess.run at the GoCodeanalyzer layer to assert on the argv. Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
…→ binary CLDK.go() accepted target_files but neither passed it to GoAnalysis nor did GoAnalysis or GoCodeanalyzer forward it to the codeanalyzer-go binary. The --target-files flag therefore had no effect, silently ignoring incremental mode. Changes: - GoCodeanalyzer.__init__: add target_files: Optional[List[str]] = None; append one --target-files <path> per entry in _run_and_parse - GoAnalysis.__init__: add target_files param; forward to GoCodeanalyzer - CLDK.go(): add target_files param; forward to GoAnalysis - analysis() shim: forward target_files to CLDK.go() Tests: add test_target_files_passed_to_binary and test_target_files_absent_when_none in test_go_analysis.py. Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Java, Python, and TypeScript all define an abstract base class that every analysis backend implements, letting GoAnalysis hold its backend via the interface rather than the concrete type. This commit brings Go to parity: - Add cldk/analysis/go/backend.py with GoAnalysisBackend(ABC) exposing six abstract methods: get_application, get_symbol_table, get_all_files, get_file, get_all_types, get_all_callables. - Make GoCodeanalyzer subclass GoAnalysisBackend (satisfies ABC at class definition time; TypeError at startup if any abstract method is missing). - Type GoAnalysis._codeanalyzer as GoAnalysisBackend so static type checkers enforce the interface boundary. - Export GoAnalysisBackend from cldk/analysis/go/__init__.py. - Add two unit tests: GoCodeanalyzer is a subclass of GoAnalysisBackend (issubclass), and GoAnalysis._codeanalyzer is a GoAnalysisBackend instance at runtime (subprocess-stub pattern, no mock needed). - Fix test_e2e_application_round_trips_pydantic: cache_subdir writes analysis.json under <cache_dir>/go/, not directly under cache_dir. Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Go language support to the SDK via the
codeanalyzer-gosubprocess backend, bringing Go to full parity with the existing Java, Python, and TypeScript integrations.Motivation and Context
Go is a first-class language in the
codeanalyzer-gobackend but was absent from the Python SDK. Users analysing polyglot codebases that include Go had noCLDK-native path; they had to shell out to the binary themselves and deserialise the output manually. This PR closes that gap.How Has This Been Tested?
Mocked unit tests (23, no binary required)
get_symbol_table,get_file,get_types_in_file,get_typeget_callables_in_file,get_callableget_call_graph,get_callers,get_callees, unknown-node edge caseGoApplication.model_dump_json→model_validate_json)GoFile.types,GoFile.package_name)--eagerpresent/absent,--target-filesrepeated per entry / absent whenNoneissubclass(GoCodeanalyzer, GoAnalysisBackend),isinstance(analysis._codeanalyzer, GoAnalysisBackend)End-to-end tests against a real binary (25, auto-skipped when
codeanalyzer-gois absent)Fixture project under
tests/resources/go/application/exercises:calc/calc.go,calc/formatter.go)eager=Falsedoes not re-invoke the binaryBreaking Changes
None. All additions are new surface; existing Java / Python / TypeScript / C paths are untouched.
Types of changes
Checklist
Additional context
New public surface
Architecture
Follows the established pattern exactly:
CLDK.go()CLDK.java()GoAnalysisJavaAnalysisGoAnalysisBackendJavaAnalysisBackendGoCodeanalyzer(subprocess)JCodeanalyzer(subprocess JAR)GoCodeAnalyzerConfigJCodeAnalyzerConfigcldk/models/go/cldk/models/java/Binary requirement
codeanalyzer-gomust be onPATH(built from thecodeanalyzer-gorepo). The SDK raisesCodeanalyzerExecutionExceptionwith a clear message if it is absent. All unit tests mockshutil.whichandsubprocess.runso they pass in CI without the binary.Commits
5abe90a— initial Go support (models, codeanalyzer, facade, core factory, README, tests)aac1203— docs: add Go to README language support tablec146713— merge: bring branch up to date with main, conform Go to new backend-config APIf9b52ce— fix:--eagerflag never passed to binaryd196199— fix:target_filesnot wired end-to-end throughCLDK.go()→GoAnalysis→ binary31e497f— feat:GoAnalysisBackendABC; fix e2e test readinganalysis.jsonfrom wrong path