Hey folks! I’ve been working on some tools to build other tools lately. One of the things that came out of that was an AST search tool I’m calling tree-grepper. It sits on top of tree-sitter grammars and exposes the tree-sitter s-expression query API. I’m using it at NoRedInk on our giant production codebase and it’s quite fast, so I imagine it will be similarly fast on other codebases too!
Here’s a blog post I’ve written about it with some code samples:
And the repo:
Side note: I just know there’s an AST-based code transformation/refactoring tool out there that has Elm support. I wanted to include it in this post, but I just couldn’t find it again! Does anyone know what I’m talking about? If so, could you share the link here?
BTW: shouts out to @razze for elm-tree-sitter, which is the string I started pulling on to end up writing this tool. What a nice reusable thing you’ve made for the community!
Yes, I end up storing something like RDF triples in a SQLite database. It’s a real duct tape and bubble gum kinda solution. Basically:
when we see an Elm module match, add ( module, "located-at", filename )
when we see an Elm import, add ( module, "imports", import )
when we see a JS import, add ( filename, "imports", require ), where require is the fully-qualified path if it’s a JS file, and a lookup in a table to find the module name if it’s an Elm file.