Skip to content

Commit e01828a

Browse files
committed
chore: move import alias parse
1 parent de8c618 commit e01828a

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

src/lang/collect/collect_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/cloudwego/abcoder/src/lang/log"
2626
"github.com/cloudwego/abcoder/src/lang/lsp"
27-
parse "github.com/cloudwego/abcoder/src/uniast"
27+
"github.com/cloudwego/abcoder/src/uniast"
2828
)
2929

3030
var testroot = "../../../testdata"
@@ -44,12 +44,12 @@ func TestCollector_Collect(t *testing.T) {
4444

4545
tests := []struct {
4646
name string
47-
want *parse.Repository
47+
want *uniast.Repository
4848
wantErr bool
4949
}{
5050
{
5151
name: "rust",
52-
want: &parse.Repository{},
52+
want: &uniast.Repository{},
5353
wantErr: false,
5454
},
5555
}

src/lang/collect/export.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ import (
2424
"github.com/cloudwego/abcoder/src/lang/log"
2525
"github.com/cloudwego/abcoder/src/lang/lsp"
2626
. "github.com/cloudwego/abcoder/src/lang/lsp"
27-
parse "github.com/cloudwego/abcoder/src/uniast"
27+
"github.com/cloudwego/abcoder/src/uniast"
2828
)
2929

3030
type dependency struct {
3131
Location Location `json:"location"`
3232
Symbol *DocumentSymbol `json:"symbol"`
3333
}
3434

35-
func (d dependency) FileLine() parse.FileLine {
36-
return parse.FileLine{
35+
func (d dependency) FileLine() uniast.FileLine {
36+
return uniast.FileLine{
3737
File: d.Location.URI.File(),
3838
Line: d.Location.Range.Start.Line,
3939
}
4040
}
4141

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
4545
return ret
4646
}
4747

48-
func (c *Collector) Export(ctx context.Context) (*parse.Repository, error) {
48+
func (c *Collector) Export(ctx context.Context) (*uniast.Repository, error) {
4949
// recursively read all go files in repo
50-
repo := parse.NewRepository(c.repo)
50+
repo := uniast.NewRepository(c.repo)
5151
modules, err := c.spec.WorkSpace(c.repo)
5252
if err != nil {
5353
return nil, err
@@ -64,7 +64,7 @@ func (c *Collector) Export(ctx context.Context) (*parse.Repository, error) {
6464

6565
// export symbols
6666
for _, symbol := range c.syms {
67-
visited := make(map[*lsp.DocumentSymbol]*parse.Identity)
67+
visited := make(map[*lsp.DocumentSymbol]*uniast.Identity)
6868
_, err := c.exportSymbol(&repo, symbol, "", visited)
6969
if err != nil {
7070
log.Info("export symbol %s failed: %v\n", symbol, err)
@@ -82,7 +82,7 @@ func (c *Collector) Export(ctx context.Context) (*parse.Repository, error) {
8282
return &repo, nil
8383
}
8484

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) {
8686
if symbol == nil {
8787
return nil, errors.New("symbol is nil")
8888
}
@@ -103,7 +103,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
103103
if err != nil {
104104
return nil, err
105105
}
106-
id := parse.NewIdentity(mod, path, name)
106+
id := uniast.NewIdentity(mod, path, name)
107107
visited[symbol] = &id
108108

109109
// Load eternal symbol on demands
@@ -116,7 +116,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
116116
}
117117
module := repo.Modules[mod]
118118
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)
120120
}
121121
pkg := repo.Modules[mod].Packages[path]
122122
if c.spec.IsMainFunction(*symbol) {
@@ -129,13 +129,13 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
129129
} else {
130130
relfile = filepath.Base(file)
131131
}
132-
fileLine := parse.FileLine{
132+
fileLine := uniast.FileLine{
133133
File: relfile,
134134
Line: symbol.Location.Range.Start.Line + 1,
135135
}
136136
// collect files
137137
if module.Files[relfile] == nil {
138-
module.Files[relfile] = parse.NewFile(relfile)
138+
module.Files[relfile] = uniast.NewFile(relfile)
139139
}
140140

141141
content := symbol.Text
@@ -156,7 +156,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
156156
// NOTICE: no need collect interface method
157157
break
158158
}
159-
obj := &parse.Function{
159+
obj := &uniast.Function{
160160
FileLine: fileLine,
161161
Content: content,
162162
Exported: public,
@@ -171,8 +171,8 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
171171
log.Error("export input symbol %s failed: %v\n", input.Symbol, err)
172172
continue
173173
}
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)
176176
}
177177
}
178178
if info.Inputs != nil {
@@ -183,8 +183,8 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
183183
log.Error("export input symbol %s failed: %v\n", input.Symbol, err)
184184
continue
185185
}
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)
188188
}
189189
}
190190
if info.Outputs != nil {
@@ -195,15 +195,15 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
195195
log.Error("export output symbol %s failed: %v\n", output.Symbol, err)
196196
continue
197197
}
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)
200200
}
201201
}
202202
if info.Method != nil && info.Method.Receiver.Symbol != nil {
203203
tok, _ := c.cli.Locate(info.Method.Receiver.Location)
204204
rid, err := c.exportSymbol(repo, info.Method.Receiver.Symbol, tok, visited)
205205
if err == nil {
206-
obj.Receiver = &parse.Receiver{
206+
obj.Receiver = &uniast.Receiver{
207207
Type: *rid,
208208
// Name: rid.Name,
209209
}
@@ -244,26 +244,26 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
244244
log.Error("export dep symbol %s failed: %v\n", dep.Symbol, err)
245245
continue
246246
}
247-
pdep := parse.NewDependency(*depid, dep.FileLine())
247+
pdep := uniast.NewDependency(*depid, dep.FileLine())
248248
switch dep.Symbol.Kind {
249249
case lsp.SKFunction:
250-
obj.FunctionCalls = parse.Dedup(obj.FunctionCalls, pdep)
250+
obj.FunctionCalls = uniast.Dedup(obj.FunctionCalls, pdep)
251251
case lsp.SKMethod:
252252
if obj.MethodCalls == nil {
253-
obj.MethodCalls = make([]parse.Dependency, 0, len(deps))
253+
obj.MethodCalls = make([]uniast.Dependency, 0, len(deps))
254254
}
255255
// 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)
257257
case lsp.SKVariable, lsp.SKConstant:
258258
if obj.GlobalVars == nil {
259-
obj.GlobalVars = make([]parse.Dependency, 0, len(deps))
259+
obj.GlobalVars = make([]uniast.Dependency, 0, len(deps))
260260
}
261-
obj.GlobalVars = parse.Dedup(obj.GlobalVars, pdep)
261+
obj.GlobalVars = uniast.Dedup(obj.GlobalVars, pdep)
262262
case lsp.SKStruct, lsp.SKTypeParameter, lsp.SKInterface, lsp.SKEnum:
263263
if obj.Types == nil {
264-
obj.Types = make([]parse.Dependency, 0, len(deps))
264+
obj.Types = make([]uniast.Dependency, 0, len(deps))
265265
}
266-
obj.Types = parse.Dedup(obj.Types, pdep)
266+
obj.Types = uniast.Dedup(obj.Types, pdep)
267267
default:
268268
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
269269
}
@@ -274,7 +274,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
274274

275275
// Type
276276
case lsp.SKStruct, lsp.SKTypeParameter, lsp.SKInterface, lsp.SKEnum:
277-
obj := &parse.Type{
277+
obj := &uniast.Type{
278278
FileLine: fileLine,
279279
Content: content,
280280
TypeKind: mapKind(k),
@@ -291,15 +291,15 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
291291
}
292292
switch dep.Symbol.Kind {
293293
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()))
295295
default:
296296
log.Error("dep symbol %s not collected for \n", dep.Symbol, id)
297297
}
298298
}
299299
}
300300
// collect methods
301301
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))
303303
for _, method := range rec {
304304
tok, _ := c.cli.Locate(method.Location)
305305
mid, err := c.exportSymbol(repo, method, tok, visited)
@@ -315,7 +315,7 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
315315
pkg.Types[id.Name] = obj
316316
// Vars
317317
case lsp.SKConstant, lsp.SKVariable:
318-
obj := &parse.Var{
318+
obj := &uniast.Var{
319319
FileLine: fileLine,
320320
Content: content,
321321
IsExported: public,
@@ -339,16 +339,16 @@ func (c *Collector) exportSymbol(repo *parse.Repository, symbol *DocumentSymbol,
339339
return &id, nil
340340
}
341341

342-
func mapKind(kind lsp.SymbolKind) parse.TypeKind {
342+
func mapKind(kind lsp.SymbolKind) uniast.TypeKind {
343343
switch kind {
344344
case lsp.SKStruct:
345-
return parse.TypeKindStruct
345+
return uniast.TypeKindStruct
346346
case lsp.SKTypeParameter:
347-
return parse.TypeKindNamed
347+
return uniast.TypeKindNamed
348348
case lsp.SKInterface:
349-
return parse.TypeKindInterface
349+
return uniast.TypeKindInterface
350350
case lsp.SKEnum:
351-
return parse.TypeKindEnum
351+
return uniast.TypeKindEnum
352352
default:
353353
panic(fmt.Sprintf("unexpected kind %v", kind))
354354
}

src/lang/lsp/spec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package lsp
1616

17-
import parse "github.com/cloudwego/abcoder/src/uniast"
17+
import "github.com/cloudwego/abcoder/src/uniast"
1818

1919
type Language string
2020

@@ -80,5 +80,5 @@ type LanguageSpec interface {
8080

8181
// Patcher is used to patch the AST of a module
8282
type ModulePatcher interface {
83-
Patch(ast *parse.Module)
83+
Patch(ast *uniast.Module)
8484
}

src/lang/rust/patch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ import (
3535
"path/filepath"
3636

3737
"github.com/cloudwego/abcoder/src/lang/log"
38-
parse "github.com/cloudwego/abcoder/src/uniast"
38+
"github.com/cloudwego/abcoder/src/uniast"
3939
)
4040

4141
type RustModulePatcher struct {
4242
Root string
4343
}
4444

45-
func (p *RustModulePatcher) Patch(ast *parse.Module) {
45+
func (p *RustModulePatcher) Patch(ast *uniast.Module) {
4646
filepath.Walk(p.Root, func(path string, info os.FileInfo, err error) error {
4747
if err != nil {
4848
return err

0 commit comments

Comments
 (0)