refactor(cmd/gf): improve command gf gen ctrl
using ast
#3470
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dear review:
使用AST替换正则,使用buf来优化性能,经过对1000个文件扫描重新生成后,两者速度几乎一致。
以下是我的测试结果:
单位都为秒,测试环境:go1.22.1 windows11/AMD Ryzen 5500U/16G memory
测试仓库,可以直接拉下来测试:
AST 测试仓库:click me
正则测试仓库(master):click me
执行
TestPerformance
方法,即可看见测试结果。如果此 PR 被社区接受,后续会进行正则全部替换成AST的工作。此外,单测为什么需要修改?
因为 AST 遍历出来的结构体名称是乱序的,所以不能单纯的只使用文件内容比较。
fixed #3067