Skip to content

Commit 795b36b

Browse files
committed
feat: optimized progress output
1 parent eb5d94e commit 795b36b

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

lang/collect/collect.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type CollectOption struct {
4040
CacheResults bool
4141
}
4242

43+
const (
44+
SUPRESS_COLLECT_ERRORS = true
45+
)
46+
4347
type Collector struct {
4448
cli *LSPClient
4549
spec LanguageSpec
@@ -192,7 +196,7 @@ func (c *Collector) Collect(ctx context.Context) error {
192196
roots = append(roots, sym)
193197
}
194198
}
195-
log.Info("collected symbols.")
199+
log.Info("collected %d root symbols. going to collect more syms and dependencies...\n", len(roots))
196200

197201
// collect some extra metadata
198202
syms := make([]*DocumentSymbol, 0, len(roots))
@@ -203,6 +207,7 @@ func (c *Collector) Collect(ctx context.Context) error {
203207
}
204208
c.processSymbol(ctx, sym, 1)
205209
}
210+
log.Info("collected %d symbols. going to collect dependencies...\n", len(c.syms))
206211

207212
// collect internal references
208213
// for _, sym := range syms {
@@ -236,8 +241,11 @@ func (c *Collector) Collect(ctx context.Context) error {
236241
// }
237242
// }
238243

244+
num_edges := 0
239245
// collect dependencies
240-
for _, sym := range syms {
246+
for i, sym := range syms {
247+
log.Info("collecting dependencies %d/%d %s\n", i, len(syms), sym.Name)
248+
241249
next_token:
242250

243251
for i, token := range sym.Tokens {
@@ -283,7 +291,9 @@ func (c *Collector) Collect(ctx context.Context) error {
283291
// go to definition
284292
dep, err := c.getSymbolByToken(ctx, token)
285293
if err != nil || dep == nil {
286-
log.Error("dep token %v not found: %v\n", token, err)
294+
if !SUPRESS_COLLECT_ERRORS {
295+
log.Error("dep token %v not found: %v\n", token, err)
296+
}
287297
continue
288298
}
289299

@@ -305,6 +315,7 @@ func (c *Collector) Collect(ctx context.Context) error {
305315
}
306316

307317
log.Debug(" Collect: dep %s -> %s (file: %s -> %s)\n", sym.Name, dep.Name, sym.Location, token.Location)
318+
num_edges++
308319
c.deps[sym] = append(c.deps[sym], dependency{
309320
Location: token.Location,
310321
Symbol: dep,
@@ -313,6 +324,7 @@ func (c *Collector) Collect(ctx context.Context) error {
313324
}
314325
}
315326

327+
log.Info("collected %d symbols, %d edges.\n", len(c.syms), num_edges)
316328
return nil
317329
}
318330

@@ -334,7 +346,9 @@ func (c *Collector) getSymbolByTokenWithLimit(ctx context.Context, tok Token, de
334346
return nil, fmt.Errorf("definition of token %s not found", tok)
335347
}
336348
if len(defs) > 1 {
337-
log.Error("definition of token %s not unique", tok)
349+
if !SUPRESS_COLLECT_ERRORS {
350+
log.Error("definition of token %s not unique", tok)
351+
}
338352
}
339353
return c.getSymbolByLocation(ctx, defs[0], depth, tok)
340354
}
@@ -536,7 +550,9 @@ func (c *Collector) getDepsWithLimit(ctx context.Context, sym *DocumentSymbol, t
536550
for _, tp := range tps {
537551
dep, err := c.getSymbolByTokenWithLimit(ctx, sym.Tokens[tp], depth)
538552
if err != nil || sym == nil {
539-
log.Error_skip(1, "token %v not found its symbol: %v", tp, err)
553+
if !SUPRESS_COLLECT_ERRORS {
554+
log.Error_skip(1, "token %v not found its symbol: %v", tp, err)
555+
}
540556
} else {
541557
d := dependency{sym.Tokens[tp].Location, dep}
542558
tsyms[tp] = d
@@ -629,12 +645,16 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
629645
}
630646
}
631647
if i < 0 || i >= len(sym.Tokens) {
632-
log.Error("get type token of variable symbol %s failed\n", sym)
648+
if !SUPRESS_COLLECT_ERRORS {
649+
log.Error("get type token of variable symbol %s failed\n", sym)
650+
}
633651
return
634652
}
635653
tsym, err := c.getSymbolByTokenWithLimit(ctx, sym.Tokens[i], depth-1)
636654
if err != nil || tsym == nil {
637-
log.Error("get type symbol for token %s failed:%v\n", sym.Tokens[i], err)
655+
if !SUPRESS_COLLECT_ERRORS {
656+
log.Error("get type symbol for token %s failed:%v\n", sym.Tokens[i], err)
657+
}
638658
return
639659
}
640660
c.vars[sym] = dependency{

lang/collect/export.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import (
2727
"github.com/cloudwego/abcoder/lang/uniast"
2828
)
2929

30+
const (
31+
SUPRESS_EXPORT_OUTPUT = true
32+
)
33+
3034
type dependency struct {
3135
Location Location `json:"location"`
3236
Symbol *DocumentSymbol `json:"symbol"`
@@ -74,7 +78,10 @@ func (c *Collector) Export(ctx context.Context) (*uniast.Repository, error) {
7478
c.filterLocalSymbols()
7579

7680
// export symbols
81+
i := 0
7782
for _, symbol := range c.syms {
83+
log.Info("export symbol %d/%d: %s\n", i, len(c.syms), symbol.Name)
84+
i++
7885
visited := make(map[*lsp.DocumentSymbol]*uniast.Identity)
7986
_, err := c.exportSymbol(&repo, symbol, "", visited)
8087
if err != nil {
@@ -292,7 +299,9 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
292299
}
293300
obj.Types = uniast.InsertDependency(obj.Types, pdep)
294301
default:
295-
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
302+
if !SUPRESS_EXPORT_OUTPUT {
303+
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
304+
}
296305
}
297306
}
298307
}
@@ -320,7 +329,9 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
320329
case lsp.SKStruct, lsp.SKTypeParameter, lsp.SKInterface, lsp.SKEnum, lsp.SKClass:
321330
obj.SubStruct = append(obj.SubStruct, uniast.NewDependency(*depid, c.fileLine(dep.Location)))
322331
default:
323-
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
332+
if !SUPRESS_EXPORT_OUTPUT {
333+
log.Error("dep symbol %s not collected for %v\n", dep.Symbol, id)
334+
}
324335
}
325336
}
326337
}

lang/parse.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func Parse(ctx context.Context, uri string, args ParseOptions) ([]byte, error) {
9393
log.Error("Failed to marshal repository: %v\n", err)
9494
return nil, err
9595
}
96+
log.Info("all symbols written to stdout.\n")
9697
return out, nil
9798
}
9899

@@ -173,11 +174,14 @@ func collectSymbol(ctx context.Context, cli *lsp.LSPClient, repoPath string, opt
173174
if err != nil {
174175
return nil, err
175176
}
177+
log.Info("all symbols exported.\n")
176178
}
177179

180+
log.Info("start building graph...\n")
178181
if err := repo.BuildGraph(); err != nil {
179182
return nil, err
180183
}
184+
log.Info("graph built.\n")
181185
return repo, nil
182186
}
183187

0 commit comments

Comments
 (0)