rewrite-clj

wilkerlucio 2022-06-27T14:14:38.015819Z

hello, I'm trying to use rewrite-clj to analyse some code, I start from clj-kondo analysis info which contains row and col of what I need, how can I navigate to something on rewrite-clj based on row/col?

jacob.maine 2022-07-15T22:43:37.693719Z

@wilkerlucio rewrite-clj provides find-last-by-pos which lets you seek to a node if you know its position. There are some caveats to using that function. It only works if you have a :track-position? zipper. And it can be slow, especially if you’re working in large files. See this https://github.com/clj-commons/rewrite-clj/issues/171 for some alternative code that works around both of those problems. Feel free to 👍 that issue if you’d like to see it worked on ;).

borkdude 2022-06-27T14:17:33.540169Z

@wilkerlucio using zippers. see e.g. carve which does something like that: https://github.com/borkdude/carve/blob/df552797a198b6701fb2d92390fce7c59205ea77/src/carve/impl.clj#L111

wilkerlucio 2022-06-27T14:21:37.886329Z

thanks! checking it out