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

codeintel

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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