-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Move search function to use Promise interface #32609
Conversation
@kgrz, thanks for your PR! By analyzing the history of the files in this pull request, we identified @roblourens and @bpasero to be potential reviewers. |
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.
Thanks for tackling this! It looks like a great start to me.
The complete action's object shape is very different from that of progress. So much so that the usage doesn't feel natural to me.
Is that a problem? I would expect them to be different and carry different information
}); | ||
search(): PPromise<ISerializedSearchComplete, ISearchProgress<IRawFileMatch>> { | ||
return new PPromise<ISerializedSearchComplete, ISearchProgress<IRawFileMatch>>((complete, error, progress) => { | ||
this.walker.walk(this.folderQueries, this.extraFiles, |
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 think it would make sense for walk
to return a PPromise as well.
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.
Oh! yeah, I forgot to mention this in the PR description. This usage was very odd. Will try migrating this too.
Looks like there is a search-related test failing. |
Weird. I didn't see this test run output when I ran on my local machine (OSX). Will recheck. |
limitHit: isLimitHit, | ||
stats: this.walker.getStats() | ||
}); | ||
search(): PPromise<ISerializedSearchComplete, ISearchProgress<IRawFileMatch>> { |
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.
You forgot access modificator
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.
Oh! thanks for pointing this out. Corrected.
search(): PPromise<ISerializedSearchComplete, ISearchProgress<IRawFileMatch>> { | ||
return new PPromise<ISerializedSearchComplete, ISearchProgress<IRawFileMatch>>((complete, error, progress) => { | ||
this.walker.walk(this.folderQueries, this.extraFiles, | ||
(result: IRawFileMatch) => { |
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.
Why you use function body
? You can write is like: (result: IRawFileMatch) => progress({ results: result });
In one line.
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.
There's a subtle difference between calling a function and returning the result, especially in the case of promises. I wanted to keep the old structure.
engine.search((matches) => { | ||
const totalMatches = matches.reduce((acc, m) => acc + m.numMatches, 0); | ||
collector.addItems(matches, totalMatches); | ||
engine.search().then((success) => { |
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.
Can you specify type for success
if you don't specify type you aren't needed parentheses
} else { | ||
c(stats); | ||
} | ||
const results = progress.results; |
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.
Which type of const results
. Can you specify this type?
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.
Same question as below. I'm leaning towards not specifying these implicit types everywhere.
c(stats); | ||
} | ||
const results = progress.results; | ||
const totalMatches = results.reduce((acc, m) => acc + m.numMatches, 0); |
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.
Which type of const totalMatches
. Can you specify this?
I think within parentheses you can specify type.
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.
Do we need to specify types for automatically inferred primitives? Because we aren't implementing reduce
, and the return type of that will never change (by our actions).
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.
No, I don't specify the type when it isn't necessary. This is fine.
a11d4cb
to
207f678
Compare
Thanks, but do you know why the tests are failing? |
TODO: There's a bit of duplication inside the `complete` and `error` callbacks.
@roblourens I'm sort of reworking this today. Will update once done. |
Tests are failing because I made a mess 😐 I didn't change some of the |
This will combine the result and the progress metrics
* Update integration tests accordingly.
9a885d4
to
ed5a579
Compare
@roblourens I've reworked this changeset, this time preserving the old To be more precise, the |
Thanks, I promise I'll look at this when I have a minute. |
Sorry for the delay. The tests are failing because of a tricky point with PPromise - if the progress callback is called synchronously inside the Promise constructor, then the progress call will be lost, because the caller's progress callback will not be attached. To work around this, you can wait a tick to give the caller a chance to attach the progress callback. We do this in several places. Here's one example: https://github.com/Microsoft/vscode/blob/4173c6478d4ac630fa4064485ecec610a02b8b5c/src/vs/workbench/services/search/node/searchService.ts#L88 That should be it. Besides that, there are just a couple things to do before I merge this -
|
I'm largely rewriting this code as part of #47058 |
Draft to fix #20650
Initial draft of changes for moving the
search
function inside FileSearch andTextSearch modules to ause a promise interface instead of callbacks.
I have a couple of problems with the changes I made:
The
complete
action's object shape is very different from that ofprogress
. So much so that the usage doesn't feel natural to me.As @roblourens pointed out, may be it's time to have different interfaces
for text and file search.
This doesn't clean up code related to ripgrepsearch yet.