Add ability to do global search based on tree-sitter grammar #3476
Replies: 2 comments 3 replies
-
I don't think it would be too much work to implement this on the tree-sitter side given what we have for highlights and some of the refactoring in #2857. The UI for writing queries could use some discussion though. Using the prompt for this (like when searching by regex) seems clunky since meaningful queries are usually long. Maybe we could pipe a selection? So you would have a selection over a query and then you would use a keybind or typable command to use the query under that selection as input. |
Beta Was this translation helpful? Give feedback.
-
My ideal workflow would be like this:
More details on Below are examples where
This mechanism will allow you to write queries without knowing the AST structure of your programming language but just using a multi-selection feature of Helix. So after that, you just need to write predicates and you have a working query. P.S. I'm wondering why my "feature request" was closed and converted to the discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I do a lot of refactoring, and I try to do one particular refactoring per commit but across all the repo.
So I frequently write small regexp to find a particular pattern in the source code.
Today I wanted to find all JS exports/imports for local files that don't have '.js'.
I managed to come up with a working regexp only after 5min of trial and error.
At the same time, Helix already has a bunch of Treesitter grammars so why do I need to mess with RegExp anyway?

I never used Treesitter in my life and after reading official docs on query syntax, I managed to write the correct query on the first try:
So my idea is to have a window where you can enter a tree-sitter query and get all the matches across the repo, similar to the window with
<space>/
results.I did a quick google and learned that it not a new idea:
https://github.com/BrianHicks/tree-grepper
But I still think it should be a part of the editor:
Basically, if we already support search using RegExp I suggest offering the same tree-sitter queries.
Beta Was this translation helpful? Give feedback.
All reactions