CGO brings C-aware tooling to cgo preambles inside Go files.
It detects import "C" preambles, mirrors them into generated C translation units, and delegates language features such as hover and document symbols to your installed C tooling. The result is a more usable editing experience for projects that embed C, system headers, or platform interop code directly inside Go source.
Most editors treat cgo preambles as opaque comments. CGO turns them into something your C tooling can understand without forcing generated files into your repository.
- Semantic highlighting for cgo preambles embedded in Go files.
- Accurate preamble detection using a Go backend that understands real Go syntax.
- Generated mirror C files stored outside the workspace so repositories stay clean.
- Hover and document symbol delegation to installed C tooling such as
clangd. - Command to open the extracted C mirror for direct inspection.
- Windows-specific compile metadata generation so system headers resolve correctly in mirrored files.
- Bundled backend binaries for
windows-amd64,linux-amd64,linux-arm64, anddarwin-arm64.
- Install CGO.
- Make sure a C language provider such as
clangdis installed in VS Code. - Open a Go file that contains an
import "C"preamble. - Run
CGO: Open Extracted Cif you want to inspect the generated mirror file directly.
When CGO finds a cgo preamble, it extracts the C content into a generated mirror file and uses that file as the bridge to existing C language tooling. This allows VS Code to provide C-oriented insight for code that lives inside a Go comment block.
Backend resolution order:
cgo.backendPathif explicitly configured.- Bundled backend binary for the current OS and architecture.
go run ./cmd/cgo-backendwhen running from a source checkout.
- VS Code
1.98.0or newer. - A C language provider if you want delegated language features such as hover and symbols.
clangdis the expected choice. - Go is not required for normal VSIX installs, but it is useful for source checkout development.
- Better visibility into cgo preambles without moving code out of the Go file.
- Reuse of mature C tooling instead of a custom parser for every editor feature.
- A clean workspace because generated mirror files live outside the repository.
CGO: Open Extracted CCGO: Show Detected Blocks
cgo.backendPath: absolute path to a backend executable override.cgo.goExecutable: Go executable to use for source-checkout fallback execution.
- Inline diagnostics and completions are not yet delegated back into the Go cgo block itself.
- Raw
#cgodirectives are blanked in mirror files so the generated C remains valid for language tooling. - Delegated hover and symbols depend on a working C language provider installation.
pnpm install
pnpm buildUseful scripts:
pnpm build: builds the current-platform backend and the extension.pnpm run build:backend:matrix: builds the packaged backend matrix in parallel.pnpm run package:vsix: builds the matrix, compiles the extension, and creates a VSIX.
CGO is source-available.
- Personal use is allowed.
- Internal organizational use is allowed, including internal commercial use.
- Internal modification and internal copying for installation or backup are allowed.
- Redistribution, resale, sublicensing, bundling, hosted/OEM use, and publishing modified versions for third parties require prior written permission.
See LICENSE.txt for the full license terms.
- Pushes to
main, pull requests, and manual workflow runs build a VSIX in GitHub Actions. - Tagged releases matching
v*attach the generated VSIX to the GitHub release automatically. - Workflow artifacts can be downloaded from the Actions tab for test installs.