@@ -24,30 +24,30 @@ import (
24
24
"github.com/cloudwego/abcoder/src/lang/log"
25
25
"github.com/cloudwego/abcoder/src/lang/lsp"
26
26
. "github.com/cloudwego/abcoder/src/lang/lsp"
27
- parse "github.com/cloudwego/abcoder/src/uniast"
27
+ "github.com/cloudwego/abcoder/src/uniast"
28
28
)
29
29
30
30
type dependency struct {
31
31
Location Location `json:"location"`
32
32
Symbol * DocumentSymbol `json:"symbol"`
33
33
}
34
34
35
- func (d dependency ) FileLine () parse .FileLine {
36
- return parse .FileLine {
35
+ func (d dependency ) FileLine () uniast .FileLine {
36
+ return uniast .FileLine {
37
37
File : d .Location .URI .File (),
38
38
Line : d .Location .Range .Start .Line ,
39
39
}
40
40
}
41
41
42
- func newModule (name string , dir string ) * parse .Module {
43
- ret := parse .NewModule (name , dir )
44
- ret .Language = parse .Rust
42
+ func newModule (name string , dir string ) * uniast .Module {
43
+ ret := uniast .NewModule (name , dir )
44
+ ret .Language = uniast .Rust
45
45
return ret
46
46
}
47
47
48
- func (c * Collector ) Export (ctx context.Context ) (* parse .Repository , error ) {
48
+ func (c * Collector ) Export (ctx context.Context ) (* uniast .Repository , error ) {
49
49
// recursively read all go files in repo
50
- repo := parse .NewRepository (c .repo )
50
+ repo := uniast .NewRepository (c .repo )
51
51
modules , err := c .spec .WorkSpace (c .repo )
52
52
if err != nil {
53
53
return nil , err
@@ -64,7 +64,7 @@ func (c *Collector) Export(ctx context.Context) (*parse.Repository, error) {
64
64
65
65
// export symbols
66
66
for _ , symbol := range c .syms {
67
- visited := make (map [* lsp.DocumentSymbol ]* parse .Identity )
67
+ visited := make (map [* lsp.DocumentSymbol ]* uniast .Identity )
68
68
_ , err := c .exportSymbol (& repo , symbol , "" , visited )
69
69
if err != nil {
70
70
log .Info ("export symbol %s failed: %v\n " , symbol , err )
@@ -82,7 +82,7 @@ func (c *Collector) Export(ctx context.Context) (*parse.Repository, error) {
82
82
return & repo , nil
83
83
}
84
84
85
- func (c * Collector ) exportSymbol (repo * parse .Repository , symbol * DocumentSymbol , refName string , visited map [* DocumentSymbol ]* parse .Identity ) (* parse .Identity , error ) {
85
+ func (c * Collector ) exportSymbol (repo * uniast .Repository , symbol * DocumentSymbol , refName string , visited map [* DocumentSymbol ]* uniast .Identity ) (* uniast .Identity , error ) {
86
86
if symbol == nil {
87
87
return nil , errors .New ("symbol is nil" )
88
88
}
@@ -103,7 +103,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
103
103
if err != nil {
104
104
return nil , err
105
105
}
106
- id := parse .NewIdentity (mod , path , name )
106
+ id := uniast .NewIdentity (mod , path , name )
107
107
visited [symbol ] = & id
108
108
109
109
// Load eternal symbol on demands
@@ -116,7 +116,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
116
116
}
117
117
module := repo .Modules [mod ]
118
118
if repo .Modules [mod ].Packages [path ] == nil {
119
- repo .Modules [mod ].Packages [path ] = parse .NewPackage (path )
119
+ repo .Modules [mod ].Packages [path ] = uniast .NewPackage (path )
120
120
}
121
121
pkg := repo .Modules [mod ].Packages [path ]
122
122
if c .spec .IsMainFunction (* symbol ) {
@@ -129,13 +129,13 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
129
129
} else {
130
130
relfile = filepath .Base (file )
131
131
}
132
- fileLine := parse .FileLine {
132
+ fileLine := uniast .FileLine {
133
133
File : relfile ,
134
134
Line : symbol .Location .Range .Start .Line + 1 ,
135
135
}
136
136
// collect files
137
137
if module .Files [relfile ] == nil {
138
- module .Files [relfile ] = parse .NewFile (relfile )
138
+ module .Files [relfile ] = uniast .NewFile (relfile )
139
139
}
140
140
141
141
content := symbol .Text
@@ -156,7 +156,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
156
156
// NOTICE: no need collect interface method
157
157
break
158
158
}
159
- obj := & parse .Function {
159
+ obj := & uniast .Function {
160
160
FileLine : fileLine ,
161
161
Content : content ,
162
162
Exported : public ,
@@ -171,8 +171,8 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
171
171
log .Error ("export input symbol %s failed: %v\n " , input .Symbol , err )
172
172
continue
173
173
}
174
- dep := parse .NewDependency (* tyid , input .FileLine ())
175
- obj .Types = parse .Dedup (obj .Types , dep )
174
+ dep := uniast .NewDependency (* tyid , input .FileLine ())
175
+ obj .Types = uniast .Dedup (obj .Types , dep )
176
176
}
177
177
}
178
178
if info .Inputs != nil {
@@ -183,8 +183,8 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
183
183
log .Error ("export input symbol %s failed: %v\n " , input .Symbol , err )
184
184
continue
185
185
}
186
- dep := parse .NewDependency (* tyid , input .FileLine ())
187
- obj .Params = parse .Dedup (obj .Params , dep )
186
+ dep := uniast .NewDependency (* tyid , input .FileLine ())
187
+ obj .Params = uniast .Dedup (obj .Params , dep )
188
188
}
189
189
}
190
190
if info .Outputs != nil {
@@ -195,15 +195,15 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
195
195
log .Error ("export output symbol %s failed: %v\n " , output .Symbol , err )
196
196
continue
197
197
}
198
- dep := parse .NewDependency (* tyid , output .FileLine ())
199
- obj .Results = parse .Dedup (obj .Results , dep )
198
+ dep := uniast .NewDependency (* tyid , output .FileLine ())
199
+ obj .Results = uniast .Dedup (obj .Results , dep )
200
200
}
201
201
}
202
202
if info .Method != nil && info .Method .Receiver .Symbol != nil {
203
203
tok , _ := c .cli .Locate (info .Method .Receiver .Location )
204
204
rid , err := c .exportSymbol (repo , info .Method .Receiver .Symbol , tok , visited )
205
205
if err == nil {
206
- obj .Receiver = & parse .Receiver {
206
+ obj .Receiver = & uniast .Receiver {
207
207
Type : * rid ,
208
208
// Name: rid.Name,
209
209
}
@@ -244,26 +244,26 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
244
244
log .Error ("export dep symbol %s failed: %v\n " , dep .Symbol , err )
245
245
continue
246
246
}
247
- pdep := parse .NewDependency (* depid , dep .FileLine ())
247
+ pdep := uniast .NewDependency (* depid , dep .FileLine ())
248
248
switch dep .Symbol .Kind {
249
249
case lsp .SKFunction :
250
- obj .FunctionCalls = parse .Dedup (obj .FunctionCalls , pdep )
250
+ obj .FunctionCalls = uniast .Dedup (obj .FunctionCalls , pdep )
251
251
case lsp .SKMethod :
252
252
if obj .MethodCalls == nil {
253
- obj .MethodCalls = make ([]parse .Dependency , 0 , len (deps ))
253
+ obj .MethodCalls = make ([]uniast .Dependency , 0 , len (deps ))
254
254
}
255
255
// NOTICE: use loc token as key here, to make it more readable
256
- obj .MethodCalls = parse .Dedup (obj .MethodCalls , pdep )
256
+ obj .MethodCalls = uniast .Dedup (obj .MethodCalls , pdep )
257
257
case lsp .SKVariable , lsp .SKConstant :
258
258
if obj .GlobalVars == nil {
259
- obj .GlobalVars = make ([]parse .Dependency , 0 , len (deps ))
259
+ obj .GlobalVars = make ([]uniast .Dependency , 0 , len (deps ))
260
260
}
261
- obj .GlobalVars = parse .Dedup (obj .GlobalVars , pdep )
261
+ obj .GlobalVars = uniast .Dedup (obj .GlobalVars , pdep )
262
262
case lsp .SKStruct , lsp .SKTypeParameter , lsp .SKInterface , lsp .SKEnum :
263
263
if obj .Types == nil {
264
- obj .Types = make ([]parse .Dependency , 0 , len (deps ))
264
+ obj .Types = make ([]uniast .Dependency , 0 , len (deps ))
265
265
}
266
- obj .Types = parse .Dedup (obj .Types , pdep )
266
+ obj .Types = uniast .Dedup (obj .Types , pdep )
267
267
default :
268
268
log .Error ("dep symbol %s not collected for %v\n " , dep .Symbol , id )
269
269
}
@@ -274,7 +274,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
274
274
275
275
// Type
276
276
case lsp .SKStruct , lsp .SKTypeParameter , lsp .SKInterface , lsp .SKEnum :
277
- obj := & parse .Type {
277
+ obj := & uniast .Type {
278
278
FileLine : fileLine ,
279
279
Content : content ,
280
280
TypeKind : mapKind (k ),
@@ -291,15 +291,15 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
291
291
}
292
292
switch dep .Symbol .Kind {
293
293
case lsp .SKStruct , lsp .SKTypeParameter , lsp .SKInterface , lsp .SKEnum :
294
- obj .SubStruct = append (obj .SubStruct , parse .NewDependency (* depid , dep .FileLine ()))
294
+ obj .SubStruct = append (obj .SubStruct , uniast .NewDependency (* depid , dep .FileLine ()))
295
295
default :
296
296
log .Error ("dep symbol %s not collected for \n " , dep .Symbol , id )
297
297
}
298
298
}
299
299
}
300
300
// collect methods
301
301
if rec := receivers [symbol ]; rec != nil {
302
- obj .Methods = make (map [string ]parse .Identity , len (rec ))
302
+ obj .Methods = make (map [string ]uniast .Identity , len (rec ))
303
303
for _ , method := range rec {
304
304
tok , _ := c .cli .Locate (method .Location )
305
305
mid , err := c .exportSymbol (repo , method , tok , visited )
@@ -315,7 +315,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
315
315
pkg .Types [id .Name ] = obj
316
316
// Vars
317
317
case lsp .SKConstant , lsp .SKVariable :
318
- obj := & parse .Var {
318
+ obj := & uniast .Var {
319
319
FileLine : fileLine ,
320
320
Content : content ,
321
321
IsExported : public ,
@@ -339,16 +339,16 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
339
339
return & id , nil
340
340
}
341
341
342
- func mapKind (kind lsp.SymbolKind ) parse .TypeKind {
342
+ func mapKind (kind lsp.SymbolKind ) uniast .TypeKind {
343
343
switch kind {
344
344
case lsp .SKStruct :
345
- return parse .TypeKindStruct
345
+ return uniast .TypeKindStruct
346
346
case lsp .SKTypeParameter :
347
- return parse .TypeKindNamed
347
+ return uniast .TypeKindNamed
348
348
case lsp .SKInterface :
349
- return parse .TypeKindInterface
349
+ return uniast .TypeKindInterface
350
350
case lsp .SKEnum :
351
- return parse .TypeKindEnum
351
+ return uniast .TypeKindEnum
352
352
default :
353
353
panic (fmt .Sprintf ("unexpected kind %v" , kind ))
354
354
}
0 commit comments