codeintel

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package codeintel resolves symbol references by type-checking a workspace.

The types in this file define the model-facing result of a reference query. Host-language details (Go types, packages) are confined to analyzer.go and roles.go; this file is the shared vocabulary between the analyzer and the tool layer.

Index

Constants

View Source
const DefaultSymbolLimit = 50

DefaultSymbolLimit is the result cap applied when a caller asks for none.

View Source
const MaxDefinitionLines = 40

MaxDefinitionLines bounds the source text go_to_definition returns. A declaration longer than this is reported with its full span and a truncated body; read_file with an offset covers the rest.

Variables

View Source
var ErrUnavailable = errors.New("analysis unavailable: workspace does not have a supported language toolchain")

ErrUnavailable reports that analysis could not run at all.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer resolves symbol references by type-checking a workspace.

One Analyzer owns one cached snapshot (see cache.go) shared by every query. mu guards the WHOLE query, not merely the snapshot pointer: go/types performs lazy resolution on the objects a query reaches, so two queries walking the same shared *packages.Package concurrently would race. Queries are therefore serialized - which costs nothing next to what the cache saves, since before this each query paid a full ~2.4s packages.Load of its own.

func NewAnalyzer

func NewAnalyzer(dir string) *Analyzer

NewAnalyzer returns an Analyzer rooted at dir.

The root is resolved to an absolute path. Snapshot invalidation decides whether a file belongs to the workspace by comparing it against this root, and packages.Load reports absolute paths - so a relative root would match nothing, stamp nothing, and silently turn the cache into a permanent stale answer rather than a fast one.

func (*Analyzer) Definition

func (a *Analyzer) Definition(ctx context.Context, symbol string) (Definition, error)

Definition resolves symbol to its declaration site and returns the span plus the declaration source, read from disk at the reported position and bounded to MaxDefinitionLines.

Resolution is symbol-based only (plan tools/03 D4): "Name", "pkg.Name", "full/import/path.Name", and - unlike References - "Type.Method", "pkg.Type.Method" and "Type.Field", including fields promoted from embedded types. It returns ErrUnavailable when the workspace cannot be analyzed.

func (*Analyzer) References

func (a *Analyzer) References(ctx context.Context, symbol string, roles []Role, limit int) (Result, error)

References returns classified references to symbol, capped at limit. It returns ErrUnavailable when the workspace cannot be analyzed.

func (*Analyzer) Symbols

func (a *Analyzer) Symbols(ctx context.Context, prefix string, limit int) (SymbolResult, error)

Symbols searches the workspace for declarations whose name starts with prefix (case-insensitive; an empty prefix matches everything). It reports package-scope declarations and their methods - the surface an agent navigates by. Struct fields are deliberately not part of workspace search: they are an outline concern, and including them turns a prefix query on a large module into thousands of hits that crowd out the declarations asked for.

It returns ErrUnavailable when the workspace cannot be analyzed.

type Definition

type Definition struct {
	Symbol    string     `json:"symbol"`
	Kind      SymbolKind `json:"kind"`
	Package   string     `json:"package,omitempty"`
	Receiver  string     `json:"receiver,omitempty"`
	Path      string     `json:"path"`
	Line      int        `json:"line"`
	EndLine   int        `json:"end_line"`
	Signature string     `json:"signature"`
	// Source is the declaration text, bounded to MaxDefinitionLines.
	Source string `json:"source,omitempty"`
	// SourceTruncated reports that the declaration is longer than the bound.
	SourceTruncated bool `json:"source_truncated,omitempty"`
}

Definition is the declaration site of a resolved symbol, with the source text read from disk at the reported span.

type Location

type Location struct {
	Path   string `json:"path"`
	Line   int    `json:"line"`
	Symbol string `json:"symbol"`
	Role   Role   `json:"role"`
}

Location is one classified reference to a symbol.

type Result

type Result struct {
	Symbol    string     `json:"symbol"`
	Locations []Location `json:"locations"`
	Complete  bool       `json:"complete"`
	Errors    int        `json:"errors,omitempty"`
	Truncated bool       `json:"truncated,omitempty"`
}

Result is the outcome of a reference query.

type Role

type Role string

Role classifies how a source location uses a symbol.

const (
	RoleDefinition     Role = "definition"
	RoleImplementation Role = "implementation"
	RoleCaller         Role = "caller"
	RoleReturn         Role = "return"
	RoleComparison     Role = "comparison"
)

func (Role) String

func (r Role) String() string

String returns the role name.

type Symbol

type Symbol struct {
	Name string     `json:"name"`
	Kind SymbolKind `json:"kind"`
	// Receiver is the method receiver type, or the owning type for a field.
	Receiver string `json:"receiver,omitempty"`
	// Package is the declaring package's import path. Empty in file mode,
	// which does not type-check and therefore knows no import paths.
	Package string `json:"package,omitempty"`
	// Path is omitted when the enclosing result already names the file, which
	// a single-file outline does - repeating it on every symbol is pure cost
	// in the one mode where it carries no information.
	Path     string `json:"path,omitempty"`
	Line     int    `json:"line"`
	EndLine  int    `json:"end_line"`
	Exported bool   `json:"exported"`
	// Signature is a single-line rendering of the declaration.
	Signature string `json:"signature"`
}

Symbol is one declaration, either from a single-file outline or from a workspace-wide symbol search. Paths are absolute, matching Location.

type SymbolKind

type SymbolKind string

SymbolKind classifies a declaration reported by an outline or symbol search.

const (
	KindFunc   SymbolKind = "func"
	KindMethod SymbolKind = "method"
	KindType   SymbolKind = "type"
	KindConst  SymbolKind = "const"
	KindVar    SymbolKind = "var"
	KindField  SymbolKind = "field"
)

type SymbolResult

type SymbolResult struct {
	Symbols   []Symbol `json:"symbols"`
	Complete  bool     `json:"complete"`
	Errors    int      `json:"errors,omitempty"`
	Truncated bool     `json:"truncated,omitempty"`
}

SymbolResult is the outcome of an outline or symbol search.

func FileOutline

func FileOutline(path string) (SymbolResult, error)

FileOutline lists the declarations in a single file, in source order.

This path parses ONE file with the standard parser (plan tools/03 D2): no type checking, no workspace load, no cache. It answers "what is in this file" for the price of reading it, and keeps working when the workspace snapshot is cold or the module does not build at all. The trade is that it reports no import paths and no resolved types - only what the syntax says.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL