Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【工具自荐】ast-grep VSCode——更智能、更方便的代码搜索替换工具 #4100

Open
HerringtonDarkholme opened this issue Mar 6, 2024 · 9 comments
Labels

Comments

@HerringtonDarkholme
Copy link

HerringtonDarkholme commented Mar 6, 2024

正则表达式虽然强大,但在处理代码搜索和替换时,无法跨行匹配,处理嵌套结构效果不佳,且很难有效地忽略注释,使得其应用范围受限。

推荐一款新VS Code插件——ast-grep VSCode,运用结构化搜索与替换(Structural Search/Replace)的技术,有效解决了这些问题。
支持众多的编程语言,包括JavaScript、TypeScript、Python、Ruby、Java、C#、Go、Rust等等。它在编辑器内部直接进行SSR查询,无需切换搜索环境,让搜索替换过程更加流畅;而查询结果边执行边显示,能即时查看和编辑,大大提高了工作效率。

此外,ast-grep VSCode还支持linting和代码修复功能,可以方便自定义Linter规则。

特性 截图
搜索模式
替换预览
代码lint
@ruanyf ruanyf added the weekly label Mar 7, 2024
@baiwusanyu-c
Copy link

天呐,这简直太酷了

@wangrongding
Copy link

这下舒服了

@yaolifeng0629
Copy link

That's cool.

@no1xsyzy
Copy link

@ruanyf 周刊292中对于此工具的介绍错误,对 AST(抽象语法树)搜索/替换而不是正则表达式。二者各有优劣,不过一个比较明确的方面是 AST 替换可以简单且正确地处理括号之类的嵌套(正则正确处理必须使用递归正则,这个东西似乎到现在也就Perl有?)。

@HerringtonDarkholme
Copy link
Author

@no1xsyzy 感谢指正!能看那么仔细真是太感谢了!
ast-grep主要解决的是正则不能理解代码而且难写的问题,比较适合代码重构的场景。

@uctdsb
Copy link

uctdsb commented May 3, 2024

大神呀, 这支持C++吗?

@HerringtonDarkholme
Copy link
Author

@amitbha
Copy link

amitbha commented May 4, 2024

希望能支持markdown,比如搜出所有图片

@HerringtonDarkholme
Copy link
Author

@amitbha 可以使用自定义语言扩展 来支持markdown的搜索

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants