Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
slimslenderslacks opened this issue Oct 8, 2024 · 2 comments
Open

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

slimslenderslacks opened this issue Oct 8, 2024 · 2 comments
Assignees

Comments

@slimslenderslacks
Copy link
Contributor

slimslenderslacks commented Oct 8, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants