unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Search your codebase for text or numeric literals #5362

Closed pchiusano closed 1 month ago

pchiusano commented 2 months ago

This PR adds text.find (alternately grep) commands. They can be used to search for text or numeric literals appearing anywhere in your project. Just supply one or more tokens to search for and it will do substring matching. Unlike regular grep over the text of your code, this will ignore local variables and function names that happen to match your search tokens (use dependents or find for that purpose). It's only searching among the text literals and numeric literals that appear in your functions. Here's the help:

CleanShot 2024-09-21 at 19 23 18@2x

So you can search either the current project, or you can include all of lib as well.

CleanShot 2024-09-21 at 19 22 16@2x

Added transcript to test and illustrate.

I didn't try to do regex matching, leaving that for future work or someone else should feel to take over this PR. I also didn't try to include a preview of each search result but that would be cool as well.

Thanks to @etorreborre for inspiring this. :)

Implementation notes

The implementation isn't using any sort of index; it has to load each term in memory and scan the ABT. This is very fast for most projects. For including search of lib too, it's actually still fast enough but you do notice a pause of a few seconds. It is scanning the definitions by hash, so it's only actually searching the total number of unique hashes that appear in lib.

ChrisPenner commented 1 month ago

Left some comments on how to speed this up for non-lib searches.