Closed acheronfail closed 4 years ago
I tried to test this out, and found that the structs that the grep
crate gives us still don't contain the byte location information (see fix/proper-encoding-support
branch).
Asked in ripgrep:
So, if we want to do this via the grep
crate we will have to wait for the above to be fixed.
We may be able to do some manual matches via the regex::bytes
export from the regex crate itself...
After a little research and tests, I found this approach to be both the simplest to implement, and reliable enough for our needs:
String
(UTF8)This is the way ripgrep searches for matches most of the time. It's also the way VSCode opens and edits files too. I think performing all our replacements on a format that's native to Rust is the most maintainable way forward.
As discussed https://github.com/BurntSushi/ripgrep/issues/1627#issuecomment-649858419.
Rather than trusting the
absolute_offset
andstart
+end
items in thematch
JSON object provided by ripgrep, we should instead use the same regex engine that ripgrep uses, use theline_number
provided and try to perform our own search of the line to discover the exact location.Potentially useful links: