Skip to content

Go ​

Plugin: @ctxo/lang-go (npm) Parser: ctxo-go-analyzer (Go binary, full tier) with tree-sitter-go fallback Tier: full (advertised), downgrades to syntax when Go toolchain is missing Extensions: .go

What this plugin does ​

The Go plugin ships a small Go program (tools/ctxo-go-analyzer) that uses go/packages + go/types to produce fully resolved symbols and edges across a module. At index time the plugin compiles the analyzer to a binary, runs one batch analysis pass over the module, and caches the per-file results. Individual extractSymbols / extractEdges calls read from that cache, keeping the ILanguageAdapter per-file contract intact while only invoking the Go toolchain once per index.

If Go 1.22+ is not on PATH, or no go.mod / go.work is discoverable, the plugin transparently downgrades to a tree-sitter-go syntax adapter. Complexity is always computed by tree-sitter, because the analyzer binary intentionally emits empty complexity.

Install ​

bash
pnpm add -D @ctxo/lang-go
bash
npm install --save-dev @ctxo/lang-go
bash
yarn add -D @ctxo/lang-go

Or:

bash
npx ctxo install go --yes

For full tier, also install a Go 1.22+ toolchain. The first ctxo index run builds the analyzer binary into the plugin's node_modules directory (typically under 5 seconds, cached after).

What it extracts ​

Symbols ​

KindSources
functionTop-level func declarations
methodMethods with receivers (func (r *T) M())
typetype declarations (structs, aliases, named primitives)
interfacetype X interface { ... } declarations
variablePackage-level var and const declarations

Edges ​

KindNotes
importsimport statements. Standard-library and module imports both tracked.
callsFunction and method calls resolved by go/types
implementsStruct-implements-interface relationships (structural, not declared)
usesType references in field lists, function signatures, composite literals

Note that Go has no extends. Embedding is modeled as a mix of uses and implements relationships because the analyzer reports implementation satisfaction explicitly via go/types.

Go modules and workspaces ​

The analyzer discovers the module root by walking up from the project root looking for go.mod and then go.work. A Go workspace (go.work) is supported: all modules listed in the use block are analyzed in a single pass. For repositories that nest a Go module inside a larger polyglot workspace, the analyzer rebases symbol IDs relative to the ctxo project root, not the module root.

Graceful degradation ​

ConditionResult
Go toolchain missing or < 1.22Falls back to tree-sitter syntax tier
No go.mod / go.work foundFalls back to tree-sitter syntax tier
Analyzer build failsFalls back to tree-sitter syntax tier, warn
Analyzer batch times outMarks batch timedOut, uses partial results

The active tier is reported by ctxo doctor (look for the Go language coverage check).

Known issues ​

  • tree-sitter peer version: tree-sitter@0.22.x and the native tree-sitter-go@0.23.x binding currently advertise mismatched peer ranges in the pnpm dependency graph. Installs succeed but may emit a peer warning. This is a known upstream issue and does not affect runtime behaviour.
  • Generics: type parameter lists are parsed but the uses edges for generic constraints are best-effort under the syntax fallback.
  • CGo files (import "C") are indexed as regular Go files; the C side is not analyzed.

Released under the MIT License.