Skip to content

fix(go): continue parsing chained selector method calls#184

Merged
Hoblovski merged 1 commit intocloudwego:mainfrom
wzekin:fix/parse_error
Apr 22, 2026
Merged

fix(go): continue parsing chained selector method calls#184
Hoblovski merged 1 commit intocloudwego:mainfrom
wzekin:fix/parse_error

Conversation

@wzekin
Copy link
Copy Markdown
Collaborator

@wzekin wzekin commented Apr 21, 2026

Allow selector traversal to keep visiting chained method calls instead of returning early, so downstream calls can still be collected during Go parsing.

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

修复:golang 链式调用中,无法正确解析 Function Recv 的问题

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

在下面这样的代码中

type A struct {}
type E struct { A }

func (a *A) AFunction() {}

func (e *E) Return() *E {
    return e
}

func (e *E)  Raw() {
    e.Return().AFunction()
}

AFunction 的 NodeID Name 会被解析成 E.AFunction 而不是 A.AFunction

测试中, Return4MethodCallsDFunction 应该是:

                {
                  "ModPath": "a.b/c",
                  "PkgPath": "a.b/c/pkg/entity",
                  "Name": "MyStructD.DFunction",
                  "File": "pkg/entity/entity.go",
                  "Line": 78,
                  "StartOffset": 1458,
                  "EndOffset": 1465,
                  "Extra": {
                    "IsInvoked": true
                  }
                }

原来的代码中,会返回:

                {
                  "ModPath": "a.b/c",
                  "PkgPath": "a.b/c/pkg/entity",
                  "Name": "MyStruct.DFunction",
                  "File": "pkg/entity/entity.go",
                  "Line": 78,
                  "StartOffset": 1458,
                  "EndOffset": 1465,
                  "Extra": {
                    "IsInvoked": true
                  }
                }

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

Comment thread lang/golang/parser/file.go Outdated
fmt.Fprintf(os.Stderr, "failed to get refer code for %s: %v\n", id.Name, err)
}
if id.Name == "MyStructD.DFunction" {
fmt.Println(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是干啥

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just test.

@Hoblovski
Copy link
Copy Markdown
Collaborator

可以给 testdata/ 加一个测例吗?期望的行为就是回归测试挂掉,因为你改了 Go parser。

@wzekin wzekin force-pushed the fix/parse_error branch 2 times, most recently from 10c941e to 5c56636 Compare April 21, 2026 12:55
Allow selector traversal to keep visiting chained method calls instead of returning early, so downstream calls can still be collected during Go parsing.
@wzekin
Copy link
Copy Markdown
Collaborator Author

wzekin commented Apr 21, 2026

done

可以给 testdata/ 加一个测例吗?期望的行为就是回归测试挂掉,因为你改了 Go parser。

Comment thread lang/golang/parser/file.go Outdated
if err := p.referCodes(ctx, &id, p.opts.ReferCodeDepth); err != nil {
fmt.Fprintf(os.Stderr, "failed to get refer code for %s: %v\n", id.Name, err)
}
if id.Name == "MyStructD.DFunction" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个去掉吧

@Hoblovski Hoblovski merged commit 0029df9 into cloudwego:main Apr 22, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants