Skip to content

Commit 5461a5d

Browse files
authored
fix(golang): correct receiver type resolution in selector parsing (cloudwego#162)
* fix(golang): correct receiver type resolution in selector parsing - Fix receiver type resolution by using m.Signature().Recv().Type() instead of sel.Recv() - Add test case for struct method resolution * fix unit test
1 parent b473883 commit 5461a5d

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

lang/golang/parser/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
371371
// callName := string(ctx.GetRawContent(expr))
372372
// get receiver type name
373373
// var rname string
374-
rev := ctx.getTypeinfo(sel.Recv())
374+
rev := ctx.getTypeinfo(m.Signature().Recv().Type())
375375
// if rev == nil {
376376
// rname = extractName(sel.Recv().String())
377377
// } else {

lang/lsp/clients_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestGolangLSP(t *testing.T) {
6565
// documentSymbol
6666
expectedSymNames := `(MyStruct).String
6767
(MyStructC).String
68+
(MyStructD).DFunction
6869
(MyStructD).String
6970
A
7071
G1

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ type InterfaceB interface {
3737
func (a MyStruct) String() string {
3838
_ = a.Embed.MyStruct
3939
_ = a.MyStructD
40-
return "base struct"
40+
return "base struct" + a.DFunction()
41+
}
42+
43+
func (c MyStructD) DFunction() string {
44+
return "I'm struct d function"
4145
}
4246

4347
func (c MyStructC) String() string {

0 commit comments

Comments
 (0)