Skip to content

Commit c49a173

Browse files
committed
merge branch from main
2 parents 477b659 + 8be29e4 commit c49a173

14 files changed

Lines changed: 101 additions & 29 deletions

File tree

docs/uniast-en.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ A repository consists of entity Modules and relationship Graph
8181

8282
```json
8383
{
84-
"Identity": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
84+
"id": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
85+
"ASTVersion": "xx",
86+
"ToolVersion": "yy",
87+
"Path": "/a/b/localsession",
8588
"Modules": {
8689
"github.com/bytedance/gopkg@v0.0.0-20230728082804-614d0af6619b": {},
8790
"github.com/cloudwego/localsession": {}
@@ -90,7 +93,7 @@ A repository consists of entity Modules and relationship Graph
9093
}
9194
```
9295

93-
- Identity: The unique name of the repo. Since the abcoder parser does not currently retrieve repository git information, the absolute path where it is currently located is generally used as the Identity
96+
- id: The unique name of the repo. Since the abcoder parser does not currently retrieve repository git information, the absolute path where it is currently located is generally used as the Identity
9497

9598

9699
- Modules: Contains submodules, a dictionary of {ModPath}: {Module AST}. Both repository modules and external dependency modules can appear in Modules, but need to be distinguished by ModulePath.
@@ -104,7 +107,10 @@ A repository consists of entity Modules and relationship Graph
104107

105108
- Path: The file directory of the repository, usually should be an absolute path
106109

107-
- ASTVersion: The UniAST version used to parse
110+
- ASTVersion: The UniAST version spefication when the repository is parsed
111+
112+
- ToolVersion: The abcoder version used to parse
113+
108114

109115
### Module
110116

docs/uniast-zh.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
8181

8282
```json
8383
{
84-
"Identity": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
84+
"id": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
85+
"ASTVersion": "xx",
86+
"ToolVersion": "yy",
87+
"Path": "/a/b/localsession",
8588
"Modules": {
8689
"github.com/bytedance/gopkg@v0.0.0-20230728082804-614d0af6619b": {},
8790
"github.com/cloudwego/localsession": {}
@@ -90,7 +93,7 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
9093
}
9194
```
9295

93-
- Identity: repo 的唯一名称。由于 abcoder parser 目前不获取仓库 git 信息,因此一般使用当前所处的绝对路径作为 Identity
96+
- id: repo 的唯一名称。由于 abcoder parser 目前不获取仓库 git 信息,因此一般使用当前所处的绝对路径作为 Identity
9497

9598

9699
- Modules: 包含的子模块,{ModPath} : {Module AST} 的字典,本仓库模块和外部依赖模块都可以出现在 Modules 中,但是需要通过 ModulePath 来区分。
@@ -104,7 +107,9 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
104107

105108
- Path: 仓库的文件目录,通常应该为绝对路径
106109

107-
- ASTVersion: 解析时使用的 UniAST 版本
110+
- ASTVersion: 解析时对应的 UniAST 版本
111+
112+
- ToolVersion: 解析时使用的 abcoder 版本
108113

109114

110115
### Module

lang/golang/parser/ctx.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ func (ctx *fileContext) GetMod(impt string) (string, error) {
142142
if isSysPkg(impt) {
143143
return "", errSysImport
144144
}
145+
146+
// fileContext 中的 import 信息只有**当前文件的引用路径**,但是存在一种场景就是实际调用的节点在另外的一个Package,导致漏解析
147+
// 常见于"链式调用"、"另一个 pkg 的全局变量的类型在另外一个 pkg 下"
148+
if ctx.module != nil && ctx.module.Packages != nil {
149+
if _, exist := ctx.module.Packages[impt]; exist {
150+
return ctx.module.Name, nil
151+
}
152+
}
145153
for _, ims := range ctx.imports.ProjectImports {
146154
if ims == impt {
147155
return ctx.module.Name, nil
@@ -483,7 +491,11 @@ func (ctx *fileContext) getTypeinfo(typ types.Type) (ti typeInfo) {
483491
ti.IsStdOrBuiltin = true
484492
}
485493
// collect sub Named type here
486-
for i := 1; i < len(tobjs); i++ {
494+
i := 0
495+
if isNamed {
496+
i = 1
497+
}
498+
for ; i < len(tobjs); i++ {
487499
tobj := tobjs[i]
488500
if isGoBuiltins(tobj.Name()) {
489501
continue

lang/golang/parser/file.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ func (p *GoParser) parseInterface(ctx *fileContext, name *ast.Ident, decl *ast.I
609609
fn.IsMethod = true
610610
fn.IsInterfaceMethod = true
611611
fn.Signature = string(ctx.GetRawContent(fieldDecl))
612+
// collect func signature deps
613+
ty := ctx.GetTypeInfo(fieldDecl.Type)
614+
for _, dep := range ty.Deps {
615+
fn.Types = InsertDependency(fn.Types, NewDependency(dep, ctx.FileLine(fieldDecl)))
616+
}
612617
}
613618
p.collectTypes(ctx, fieldDecl.Type, st, inlined)
614619
}

lang/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/cloudwego/abcoder/lang/register"
3636
"github.com/cloudwego/abcoder/lang/rust"
3737
"github.com/cloudwego/abcoder/lang/uniast"
38+
"github.com/cloudwego/abcoder/version"
3839
)
3940

4041
// ParseOptions is the options for parsing the repo.
@@ -105,6 +106,7 @@ func Parse(ctx context.Context, uri string, args ParseOptions) ([]byte, error) {
105106
}
106107

107108
repo.ASTVersion = uniast.Version
109+
repo.ToolVersion = version.Version
108110

109111
out, err := json.Marshal(repo)
110112
if err != nil {

lang/uniast/ast.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ type NodeGraph map[string]*Node
8383

8484
// Repository
8585
type Repository struct {
86-
ASTVersion string
87-
Name string `json:"id"` // module name
88-
Path string // repo path
89-
Modules map[string]*Module // module name => module
90-
Graph NodeGraph // node id => node
86+
Name string `json:"id"` // module name
87+
ASTVersion string // uniast version
88+
ToolVersion string // abcoder version
89+
Path string // repo absolute path
90+
Modules map[string]*Module // module name => module
91+
Graph NodeGraph // node id => node
9192
}
9293

9394
func (r Repository) ID() string {

lang/uniast/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
package uniast
1818

19-
const Version = "v0.1.3"
19+
const Version = "v0.1.4"

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/cloudwego/abcoder/llm/agent"
4848
"github.com/cloudwego/abcoder/llm/mcp"
4949
"github.com/cloudwego/abcoder/llm/tool"
50+
"github.com/cloudwego/abcoder/version"
5051
)
5152

5253
const Usage = `abcoder <Action> [Language] <Path> [Flags]
@@ -106,7 +107,7 @@ func main() {
106107

107108
switch action {
108109
case "version":
109-
fmt.Fprintf(os.Stdout, "%s\n", Version)
110+
fmt.Fprintf(os.Stdout, "%s\n", version.Version)
110111

111112
case "parse":
112113
language, uri := parseArgsAndFlags(flags, true, flagHelp, flagVerbose)
@@ -183,7 +184,7 @@ func main() {
183184

184185
svr := mcp.NewServer(mcp.ServerOptions{
185186
ServerName: "abcoder",
186-
ServerVersion: Version,
187+
ServerVersion: version.Version,
187188
Verbose: *flagVerbose,
188189
ASTReadToolsOptions: tool.ASTReadToolsOptions{
189190
RepoASTsDir: uri,
@@ -308,6 +309,8 @@ func parseTSProject(ctx context.Context, repoPath string, opts lang.ParseOptions
308309

309310
cmd := exec.CommandContext(ctx, parserPath, args...)
310311
cmd.Env = append(os.Environ(), "NODE_OPTIONS=--max-old-space-size=65536")
312+
cmd.Env = append(cmd.Env, "ABCODER_TOOL_VERSION="+version.Version)
313+
cmd.Env = append(cmd.Env, "ABCODER_AST_VERSION="+uniast.Version)
311314
cmd.Stdout = os.Stdout
312315
cmd.Stderr = os.Stderr
313316

testdata/go/0_golang/pkg/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ var CaseVarFunc CaseStruct = func() CaseStruct {
161161
FieldExternalType: entity.MyStruct{},
162162
}
163163
}()
164+
165+
type CaseInterface interface {
166+
CaseMethodDeps(a int, b entity.MyStruct) Integer
167+
}

ts-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
"ts-node": "^10.9.0",
4444
"typescript": "^5.0.0"
4545
}
46-
}
46+
}

0 commit comments

Comments
 (0)