![]() The TreeContext class is line-oriented, and is mainly interested in tracking language constructs whose scope spans multiple lines. This all exists because my other project aider uses TreeContext to display a repository map so that GPT-4 can understand how the most important classes, methods, functions, etc fit into the entire code base of a git repository.īut it was easy to make a CLI interface to grep lines of interest and display them with TreeContext, and it turned out to be quite useful. The command line tool is a thin wrapper around the `TreeContext` class, whose purpose is show you a set of "lines of interest" in the context of the entire AST. ![]() ▶ urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF) │ object to install in the current thread context. │ Parse a request and decide what translation │class LocaleMiddleware(MiddlewareMixin): │from django.http import HttpResponseRedirect │from 18n import is_language_prefix_patterns_used ![]() If you ran this in the terminal, it would also colorize the matches. Notice that it finds `ROOT_URLCONF` and then shows you the method and class that contain the matching line, including a helpful part of the docstring. Here's a snippet that shows grep-ast searching the django repo. It's useful when you're grepping to understand how functions, classes, variables etc are used within a non-trivial codebase. It shows relevant code from every layer of the AST, above and below the matches. It uses the abstract syntax tree (AST) of the source code to show how the matching lines fit into the code structure. It works with most popular languages, thanks to tree-sitter. My tool let's you grep a regex as usual, but shows you the matches in a helpful AST aware way. The OP's tool lets you specify your search as a chunk of code/AST (and then do AST transforms on matches). I'll share my similarly named tool `grep-ast`, which sort of does the opposite of the OP's `ast-grep`.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |