@@ -22,7 +22,6 @@ import (
22
22
"strings"
23
23
24
24
"github.com/cloudwego/abcoder/lang/log"
25
- "github.com/cloudwego/abcoder/lang/lsp"
26
25
. "github.com/cloudwego/abcoder/lang/lsp"
27
26
"github.com/cloudwego/abcoder/lang/uniast"
28
27
)
@@ -44,8 +43,8 @@ func (c *Collector) fileLine(loc Location) uniast.FileLine {
44
43
return uniast.FileLine {
45
44
File : rel ,
46
45
Line : loc .Range .Start .Line + 1 ,
47
- StartOffset : lsp . PositionOffset (file_uri , text , loc .Range .Start ),
48
- EndOffset : lsp . PositionOffset (file_uri , text , loc .Range .End ),
46
+ StartOffset : PositionOffset (file_uri , text , loc .Range .Start ),
47
+ EndOffset : PositionOffset (file_uri , text , loc .Range .End ),
49
48
}
50
49
}
51
50
@@ -75,7 +74,7 @@ func (c *Collector) Export(ctx context.Context) (*uniast.Repository, error) {
75
74
c .filterLocalSymbols ()
76
75
77
76
// export symbols
78
- visited := make (map [* lsp. DocumentSymbol ]* uniast.Identity )
77
+ visited := make (map [* DocumentSymbol ]* uniast.Identity )
79
78
for _ , symbol := range c .syms {
80
79
_ , _ = c .exportSymbol (& repo , symbol , "" , visited )
81
80
}
@@ -191,15 +190,15 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
191
190
// map receiver to methods
192
191
receivers := make (map [* DocumentSymbol ][]* DocumentSymbol , len (c .funcs )/ 4 )
193
192
for method , rec := range c .funcs {
194
- if method .Kind == lsp . SKMethod && rec .Method != nil && rec .Method .Receiver .Symbol != nil {
193
+ if method .Kind == SKMethod && rec .Method != nil && rec .Method .Receiver .Symbol != nil {
195
194
receivers [rec .Method .Receiver .Symbol ] = append (receivers [rec .Method .Receiver .Symbol ], method )
196
195
}
197
196
}
198
197
199
198
switch k := symbol .Kind ; k {
200
199
// Function
201
- case lsp . SKFunction , lsp . SKMethod :
202
- if p := c .cli .GetParent (symbol ); p != nil && p .Kind == lsp . SKInterface {
200
+ case SKFunction , SKMethod :
201
+ if p := c .cli .GetParent (symbol ); p != nil && p .Kind == SKInterface {
203
202
// NOTICE: no need collect interface method
204
203
break
205
204
}
@@ -209,6 +208,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
209
208
Exported : public ,
210
209
}
211
210
info := c .funcs [symbol ]
211
+ obj .Signature = info .Signature
212
212
// NOTICE: type parames collect into types
213
213
if info .TypeParams != nil {
214
214
for _ , input := range info .TypeParamsSorted {
@@ -262,7 +262,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
262
262
id .Name = iid .Name + "<" + id .Name + ">"
263
263
}
264
264
}
265
- if k == lsp . SKFunction {
265
+ if k == SKFunction {
266
266
// NOTICE: class static method name is: type::method
267
267
id .Name += "::" + name
268
268
} else {
@@ -285,20 +285,20 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
285
285
}
286
286
pdep := uniast .NewDependency (* depid , c .fileLine (dep .Location ))
287
287
switch dep .Symbol .Kind {
288
- case lsp . SKFunction :
288
+ case SKFunction :
289
289
obj .FunctionCalls = uniast .InsertDependency (obj .FunctionCalls , pdep )
290
- case lsp . SKMethod :
290
+ case SKMethod :
291
291
if obj .MethodCalls == nil {
292
292
obj .MethodCalls = make ([]uniast.Dependency , 0 , len (deps ))
293
293
}
294
294
// NOTICE: use loc token as key here, to make it more readable
295
295
obj .MethodCalls = uniast .InsertDependency (obj .MethodCalls , pdep )
296
- case lsp . SKVariable , lsp . SKConstant :
296
+ case SKVariable , SKConstant :
297
297
if obj .GlobalVars == nil {
298
298
obj .GlobalVars = make ([]uniast.Dependency , 0 , len (deps ))
299
299
}
300
300
obj .GlobalVars = uniast .InsertDependency (obj .GlobalVars , pdep )
301
- case lsp . SKStruct , lsp . SKTypeParameter , lsp . SKInterface , lsp . SKEnum , lsp . SKClass :
301
+ case SKStruct , SKTypeParameter , SKInterface , SKEnum , SKClass :
302
302
if obj .Types == nil {
303
303
obj .Types = make ([]uniast.Dependency , 0 , len (deps ))
304
304
}
@@ -312,7 +312,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
312
312
pkg .Functions [id .Name ] = obj
313
313
314
314
// Type
315
- case lsp . SKStruct , lsp . SKTypeParameter , lsp . SKInterface , lsp . SKEnum , lsp . SKClass :
315
+ case SKStruct , SKTypeParameter , SKInterface , SKEnum , SKClass :
316
316
obj := & uniast.Type {
317
317
FileLine : fileLine ,
318
318
Content : content ,
@@ -328,7 +328,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
328
328
continue
329
329
}
330
330
switch dep .Symbol .Kind {
331
- case lsp . SKStruct , lsp . SKTypeParameter , lsp . SKInterface , lsp . SKEnum , lsp . SKClass :
331
+ case SKStruct , SKTypeParameter , SKInterface , SKEnum , SKClass :
332
332
obj .SubStruct = uniast .InsertDependency (obj .SubStruct , uniast .NewDependency (* depid , c .fileLine (dep .Location )))
333
333
default :
334
334
log .Error ("dep symbol %s not collected for \n " , dep .Symbol , id )
@@ -351,12 +351,12 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
351
351
obj .Identity = * id
352
352
pkg .Types [id .Name ] = obj
353
353
// Vars
354
- case lsp . SKConstant , lsp . SKVariable :
354
+ case SKConstant , SKVariable :
355
355
obj := & uniast.Var {
356
356
FileLine : fileLine ,
357
357
Content : content ,
358
358
IsExported : public ,
359
- IsConst : k == lsp . SKConstant ,
359
+ IsConst : k == SKConstant ,
360
360
}
361
361
if ty , ok := c .vars [symbol ]; ok {
362
362
tok , _ := c .cli .Locate (ty .Location )
@@ -374,18 +374,18 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
374
374
return
375
375
}
376
376
377
- func mapKind (kind lsp. SymbolKind ) uniast.TypeKind {
377
+ func mapKind (kind SymbolKind ) uniast.TypeKind {
378
378
switch kind {
379
- case lsp . SKStruct :
379
+ case SKStruct :
380
380
return "struct"
381
381
// XXX: C++ should use class instead of struct
382
- case lsp . SKClass :
382
+ case SKClass :
383
383
return "struct"
384
- case lsp . SKTypeParameter :
384
+ case SKTypeParameter :
385
385
return "type-parameter"
386
- case lsp . SKInterface :
386
+ case SKInterface :
387
387
return "interface"
388
- case lsp . SKEnum :
388
+ case SKEnum :
389
389
return "enum"
390
390
default :
391
391
panic (fmt .Sprintf ("unexpected kind %v" , kind ))
0 commit comments