4 ms·
This looks exciting. One thing I've always wanted to do is search Rust code but excluding code in tests (marked by a #[cfg(test)] annotation). Can it do that?
by da39a3ee 3y ago
This looks exciting. One thing I've always wanted to do is search Rust code but excluding code in tests (marked by a #[cfg(test)] annotation). Can it do that?
I certainly hope some excellent AST-based CLI code search tools come to exist; hopefully this is one of them.
- herrington_d 3y agoOf course, it gets you covered. https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InJ1c3QiLCJxdWVyeSI6IicxMzMnIiwicmV3cml0ZSI6IiRBLmNoYXJzKCkuZW51bWVyYXRlKCkiLCJjb25maWciOiJydWxlOlxuICBwYXR0ZXJuOiBIYXNoTWFwXG4gIG5vdDpcbiAgICBpbnNpZGU6XG4gICAgICBwYXR0ZXJuOiBtb2QgdGVzdCB7ICQkJCB9XG4gICAgICBzdG9wQnk6IGVuZCIsInNvdXJjZSI6ImZuIHRlc3QoKSB7XG4gICBIYXNoTWFwOjpuZXcoKTsgXG59XG5cbm1vZCB0ZXN0IHtcbiAgICBmbiB0ZXN0MigpIHtcbiAgICAgICAgSGFzaE1hcDo6bmV3KCk7XG4gICAgfVxufSJ9 https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZ... I have the same problem also, haha, https://x.com/hd_nvim/status/1667059966111547392 https://x.com/hd_nvim/status/1667059966111547392
- da39a3ee 3y agoThanks! How would you do that for a #[cfg(test)] attribute in Rust? (I believe that the true identifier of test code; `mod test {}` is just a convention). I assume Rust attributes "wrap" the AST node rooted at the node that follows them?
- herrington_d 3y agoYes you can! https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InJ1c3QiLCJxdWVyeSI6IicxMzMnIiwicmV3cml0ZSI6IiRBLmNoYXJzKCkuZW51bWVyYXRlKCkiLCJjb25maWciOiJydWxlOlxuICBwYXR0ZXJuOiBIYXNoTWFwXG4gIG5vdDpcbiAgICBpbnNpZGU6XG4gICAgICBwYXR0ZXJuOiBtb2QgJE0geyAkJCQgfVxuICAgICAgZm9sbG93czpcbiAgICAgICAgcGF0dGVybjogJyNbY2ZnKHRlc3QpXSdcbiAgICAgIHN0b3BCeTogZW5kIiwic291cmNlIjoiZm4gdGVzdCgpIHtcbiAgIEhhc2hNYXA6Om5ldygpOyBcbn1cblxuI1tjZmcodGVzdCldXG5tb2Qgbm90X3Rlc3Qge1xuICAgIGZuIHRlc3QyKCkge1xuICAgICAgICBIYXNoTWFwOjpuZXcoKTtcbiAgICB9XG59XG5cbm1vZCB0ZXN0IHtcbiAgICBmbiB0ZXN0MigpIHtcbiAgICAgICAgSGFzaE1hcDo6bmV3KCk7XG4gICAgfVxufSJ9 https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZ...