-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Add a directory searcher that uses ripgrep
as the backend
#19348
Conversation
293eda6
to
c46522e
Compare
ripgrep
as the backendripgrep
as the backend
1c47e4f
to
d35aef3
Compare
Since a new RipgrepDirectorySearcher is constructed during the snapshot creation, we cannot require vscode-ripgrep from there (since it's not in the snapshot).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever approach keeping the set of trailing context lines and continuing populating them in subsequent matches. Did you profile this at all to get a sense of how much overhead this state tracking introduces? I don't imagine it would be too bad though... just a bit of extra work per match, and the alternative is breaking the API which I agree is probably not worth it.
src/ripgrep-directory-searcher.js
Outdated
|
||
if (options.trailingContextLineCount) { | ||
for (const trailingContextLines of pendingTrailingContexts) { | ||
trailingContextLines.push(message.data.lines.text.trim()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if message.data.lines.text
contains newlines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this, but I'm going to add a test for that.
I remember that when we were testing the current implementation we saw some issues with multi-line results right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, although I honestly can't remember what we saw.
Good point! On my local tests I couldn't see any issue even when returning a lot of results but I'm going to do some profiling |
884d1b2
to
4f9bd50
Compare
I've done some profiling and the overhead added is non-significative. The whole processing of a single line from For comparison, |
I've added a new commit which enables multiline support in the I've also added a bunch of tests to verify that the behaviour is correct ✨ |
eb7060a
to
6748b84
Compare
Oh god I've had to handle yet more edge cases (created tests for each of them):
There may be other edge cases that I'm missing, so my current recommendation is to add this as a setting on the |
Hey |
Summary
This PR adds a new
RipgrepDirectorySearcher
(the backend thatatom.workspace.scan()
uses that implements the search usingripgrep
.For simplicity (and backwards compatibility), the
RipgrepDirectorySearcher
implements the exact same interface that theDefaultDirectorySearcher
(in order to verify that, we're running the exact same tests against both of them).🍐'd with @nathansobo
Benefits
This should speed up considerably searches along big projects (I'll provide some benchmarks later), since
ripgrep
has proven to be dramatically faster than using Node's filesystem apis to crawl a big project.Alternate designs
Instead of mimicking the data structure of
scandal
, we could have chosen to just return the data in a similar structure than the output ofripgrep
(which aligns better with what's used on the find and replace UI). This would mean less processing of data and would allow simplifying the find and replace logic.At the same time, this alternative had some big drawbacks:
ripgrep
is a suitable alternative for find and replace, we prefer to avoid having to do this amount of work just to test the hypothesis.ripgrep
and the standard scanner at the same time to compare them. This means that we would need to keep both types of handling logic in the find and replace, with the risk of diverging or introducing bugs in one logic only without realizing.scan()
, other packages using that method (or other parts of Atom) won't be able to easily benefit fromripgrep
improvements without being refactored.Verification process
ripgrep
andscandal
, a few new tests have been added to test the context lines logic.