Is there a way to search (aka "grep") some Go code, and show all functions/methods which return a struct called "FooBar"?
A command-line tool would be fine, or a way to do this in vscode.
In vscode, if I use "Go to References" I see the methods of this struct, too (which I don’t want to see)
Update: I know how to use grep
via the vscode terminal. But using grep
or rg
for this task is error-prone. I am looking for an AST-based solution.
2
Answers
You can try to use callgraph and
grep
combination to parsego
code and find required returning value in functions signature.Install::
Example:
✳️ project structure
✳️
service.go
✳️
type.go
✳️
main.go
to configure format look at the source. For example
.Callee
is ssa.Function type -> you can usetext/template
syntax to reach it value ({{.Callee.Signature.Results}}}
)Summary:
Package > File > FuncDecl
*FooBar, []FooBar, map[FooBar]any
…