Help us shape the future of Go! Take the 2026 Go Developer Survey

codeintel

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

callers.go —— Go 调用方精化:token 级调用位(calls 表,IDENT 紧跟 '(') 作候选,AST 二次核实并补封闭函数名与限定名。零磁盘 IO——候选文件源码在 建索引期已驻留(fileEntry.src),精化只做内存重解析。

边界如实声明(与 GoCallers 词法级同纪律):不做类型解析——同名异接收者的 方法调用全部命中(pkg.F 与 var.F 形态在 AST 上不可分);接口分派/动态派发 不可见;包级 var/const 初始化器与匿名函数体内的调用封闭函数记 "(package init)"。误报面显著小于纯词法(字符串/注释在候选层已排除,本层 再排除非调用位),但**不是** SSA 精确调用图。

Package codeintel 轻量代码符号索引(收编自 argus internal/codegraph,v0.10.34): 工作副本上以 go/parser / go/scanner 建立符号定义表与标识符出现索引,为审查/ 问答类 agent 提供 get_symbol(定义定位)、get_references(跨文件影响面)、 get_callers(词法调用边)的数据面。v1.5 起含 JS/TS/Python 词法符号表。

边界如实声明:全部是词法级索引(Go 侧"定义/出现"两级,多语言侧正则锚定 声明/调用形态),不做类型解析级的精确调用图(那是 Greptile 全库图/LSIF 的 领域)。浅克隆工作副本 + CGO_ENABLED=0 构建约束下,纯 Go stdlib 方案是成本 与收益的平衡点。误报形态(字符串/注释内命中、动态调用)由工具描述向 agent 声明"须回文件读取核实"。全部为确定性代码,不经 LLM。

polyglot.go —— 多语言词法符号表(JS/TS/Python)。

边界如实声明:JS/TS/Python 与 Go 的 get_callers 全部是**词法级**索引 (正则锚定声明/调用形态),不做类型解析——与 Go 侧 go/scanner 同级质量, 零新增依赖、零 cgo(CGO_ENABLED=0 兼容)。误报形态(字符串/注释内命中、 动态调用)与 Go 词法索引一致,由工具描述向 agent 声明"须回 get_file 核实"。

Index

Constants

View Source
const CallerInit = "(package init)"

CallerInit 包级初始化/匿名函数体的封闭函数占位。

导出成常量供下游判别(下游按 `Caller == codeintel.CallerInit` 判断 「这条调用位在包级初始化里」),而不是让下游去比一个字面量。

Variables

This section is empty.

Functions

This section is empty.

Types

type CallerRef added in v0.7.0

type CallerRef struct {
	File   string // 相对索引根路径
	Line   int
	Caller string // 封闭函数(Recv.Name / Name;包级初始化记 "(package init)")
	Callee string // 调用目标限定名(pkg.F / T.M / F;链式调用取末端 Sel)
}

CallerRef 精化后的调用位。

type Index

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

Index 代码图索引(只读;多 goroutine 并发查询安全——refs 与 files 均在 NewIndex 建完后冻结,查询侧零共享可变状态)。

func NewIndex

func NewIndex(dir string, maxFiles int) (*Index, error)

NewIndex 建立目录索引(dir 为工作副本根;maxFiles 封顶防超大仓,0 = 1000)。 单文件解析失败跳过计数,不致命。

func (*Index) Definitions

func (x *Index) Definitions(name string) []Symbol

Definitions 按名查定义(大小写不敏感,词法索引惯例)。

func (*Index) GoCallers

func (x *Index) GoCallers(name string, limit int) []Ref

GoCallers 按名查调用形态出现位置(pkg.F( 与 F( 两种形态,定义行不计; 与 References 的差异:只收调用形态行,并注明词法级)。v0.12.0 起查建索引 期与 refs 同遍采集的 calls 表(token 对 IDENT+'(')——正则扫描、正则缓存、 子串预筛、逐行匹配四层全部删除:token 扫描无视空白(Serve (w) 命中)、 字符串/注释不产 token(假命中根除)、查询 O(1)。

func (*Index) IndexedFiles

func (x *Index) IndexedFiles() int

IndexedFiles 成功索引文件数。

func (*Index) PolyDefinitions

func (x *Index) PolyDefinitions(name string) []PolySymbol

PolyDefinitions 按名查非 Go 符号(大小写不敏感;Go 侧命中优先——同名冲突 时 Go 索引是权威)。

func (*Index) PreciseCallers added in v0.7.0

func (x *Index) PreciseCallers(name string, limit int) []CallerRef

PreciseCallers 按名查精化调用位:与 GoCallers 同一候选源(calls 表,定义行 不计),候选文件逐一内存重解析为 AST,只保留「确为调用位」的行并补 Caller/ Callee。结果按 (File,Line) 稳定有序,limit 封顶(<=0 = 50)。文件解析失败 丢弃该文件候选(宁缺毋假——不回填 token 级结果)。查询侧并发安全(与 Index 只读纪律一致:不写任何 Index 字段)。

func (*Index) References

func (x *Index) References(name string, limit int) []Ref

References 查标识符出现位置(精确大小写——Go 标识符大小写敏感)。 定义行自身不计入;按行去重;limit 封顶(<=0 = 50)。 走 buildRefs 预建的反向索引:查询 O(1) 查表,不再全量重扫。

func (*Index) SkippedFiles

func (x *Index) SkippedFiles() int

SkippedFiles 解析失败文件数(覆盖可见性)。

func (*Index) TouchedByLines

func (x *Index) TouchedByLines(file string, from, to int) []Symbol

TouchedByLines 返回与给定行区间重叠的符号(变更触达提示的依据)。 区间语义为 overlap(改动行落在符号 [Line,EndLine] 内即触达)。

type PolySymbol

type PolySymbol struct {
	Name string
	Lang string // py | js
	File string // 相对索引根
	Line int
	Args string // 参数表原文(≤120 runes)
	Doc  string // 前置 docstring/注释首行(≤120 runes,可空)
}

PolySymbol 非 Go 语言的词法符号。

type Ref

type Ref struct {
	File string
	Line int
}

Ref 一个标识符出现位置(文件:行,按行去重)。

type Symbol

type Symbol struct {
	Name      string // 原名(查询大小写不敏感)
	Kind      string // func | type | var | const
	Recv      string // 方法 receiver 类型文本(普通函数为空)
	File      string // 相对索引根的路径
	Line      int
	EndLine   int
	Signature string // 声明源码片段(≤200 runes)
}

Symbol 一个顶层符号定义。

Jump to

Keyboard shortcuts

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