Skip to content

Commit 5c56636

Browse files
committed
fix(golang): continue parsing chained selector method calls
Allow selector traversal to keep visiting chained method calls instead of returning early, so downstream calls can still be collected during Go parsing.
1 parent 56e878a commit 5c56636

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

.github/workflows/regression.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ jobs:
8888
8989
- name: Run OLD abcoder
9090
run:
91-
OUTDIR=out_old ABCEXE=./abcoder_old ./main_repo/script/run_testdata.sh all
91+
# we run the old abcoder on the new data to compare the outputs
92+
OUTDIR=out_old ABCEXE=./abcoder_old ./pr_repo/script/run_testdata.sh all
9293

9394
- name: Reset dependencies
9495
run: |

lang/golang/parser/file.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,6 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
354354
} else if sel, ok := expr.X.(*ast.SelectorExpr); ok {
355355
// recurse call
356356
cont = p.parseSelector(ctx, sel, infos)
357-
} else {
358-
// try to get type info of field first
359-
if ti := ctx.GetTypeInfo(expr); ti.Ty != nil {
360-
if _, ok := ti.Ty.(*types.Signature); ok {
361-
// collect method call
362-
// method call
363-
rev := ctx.GetTypeInfo(expr.X)
364-
if !rev.IsStdOrBuiltin {
365-
id := NewIdentity(rev.Id.ModPath, rev.Id.PkgPath, rev.Id.Name+"."+expr.Sel.Name)
366-
dep := NewDependency(id, ctx.FileLine(expr.Sel))
367-
infos.methodCalls = InsertDependency(infos.methodCalls, dep)
368-
}
369-
}
370-
}
371-
return true
372357
}
373358

374359
// method calls
@@ -400,7 +385,9 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
400385
}
401386
infos.methodCalls = InsertDependency(infos.methodCalls, dep)
402387
}
403-
return false
388+
389+
// 此处应该是 true,用于处理 chained method call,让 visit 可以继续处理
390+
return true
404391
}
405392

406393
return cont

lang/lsp/clients_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ func TestGolangLSP(t *testing.T) {
6363

6464
uri := NewURI(goTestCase + "/pkg/entity/entity.go")
6565
// documentSymbol
66-
expectedSymNames := `(MyStruct).String
66+
expectedSymNames := `(MyStruct).Return0
67+
(MyStruct).Return4
68+
(MyStruct).String
6769
(MyStructC).String
6870
(MyStructD).DFunction
6971
(MyStructD).String

testdata/go/0_golang/pkg/entity/entity.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ const G1 = 1
6161
type Integer int
6262

6363
var V1 = Integer(1)
64+
65+
func (a *MyStruct) Return0() *MyStruct {
66+
return a
67+
}
68+
69+
func (a *MyStruct) Return4() string {
70+
return a.Return0().DFunction()
71+
}

0 commit comments

Comments
 (0)