docker / labs-ai-tools-for-devs

Project AI For Devs (chat-sdlc) - AI agents running containerized tools
43 stars 5 forks source link

5-1-insert-top-level-ranges prompt #27

Open slimslenderslacks opened 1 week ago

slimslenderslacks commented 1 week ago

Steps 3 and 4 could be simplified using tree-sitter queries. Instead of writing out the sexps of the parse trees and matching them with regexes, tree-sitter already supports capturing nodes that you describe in terms of the tree-sitter grammar.

For example, capture only top-level function_definitions and class_definitions.

(module [(function_definition)
         (class_definition)] @top-level)

We could iterate over all @top-level matches and extract either start/end points, or the start/end bytes if you just want to extract the content directly from tree-sitter. I think this is another example of where our description of what we want is actually a very small program but written using tree-sitter queries. For python, the LLMs already know this grammar so what I wrote above was generated by Claude.

The current regex is tied to the output format from the cli

slimslenderslacks commented 1 week ago

I think this turns out to be important because the AI can go straight to ranges here, and it can author these queries as well. These queries are also the queries that are continuously run in editors like neovim and zed to do syntax highlighting.

slimslenderslacks commented 1 week ago

@ColinMcNeil vonwig/tree-sitter:latest can run queries now. I added a README.md for that function.