mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Fix #55612 - fix findTextInFiles cancellation
This commit is contained in:
@@ -172,29 +172,29 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||
const queryBuilder = this._instantiationService.createInstance(QueryBuilder);
|
||||
const query = queryBuilder.text(pattern, folders, options);
|
||||
|
||||
return new TPromise((resolve, reject) => {
|
||||
const onProgress = (p: ISearchProgressItem) => {
|
||||
if (p.lineMatches) {
|
||||
this._proxy.$handleTextSearchResult(p, requestId);
|
||||
const onProgress = (p: ISearchProgressItem) => {
|
||||
if (p.lineMatches) {
|
||||
this._proxy.$handleTextSearchResult(p, requestId);
|
||||
}
|
||||
};
|
||||
|
||||
const search = this._searchService.search(query, onProgress).then(
|
||||
() => {
|
||||
delete this._activeSearches[requestId];
|
||||
return null;
|
||||
},
|
||||
err => {
|
||||
delete this._activeSearches[requestId];
|
||||
if (!isPromiseCanceledError(err)) {
|
||||
return TPromise.wrapError(err);
|
||||
}
|
||||
};
|
||||
|
||||
const search = this._searchService.search(query, onProgress).then(
|
||||
() => {
|
||||
delete this._activeSearches[requestId];
|
||||
resolve(null);
|
||||
},
|
||||
err => {
|
||||
delete this._activeSearches[requestId];
|
||||
if (!isPromiseCanceledError(err)) {
|
||||
reject(TPromise.wrapError(err));
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
return undefined;
|
||||
});
|
||||
this._activeSearches[requestId] = search;
|
||||
|
||||
this._activeSearches[requestId] = search;
|
||||
});
|
||||
return search;
|
||||
}
|
||||
|
||||
$cancelSearch(requestId: number): Thenable<boolean> {
|
||||
|
||||
@@ -395,7 +395,13 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
excludePattern: options.exclude && globPatternToString(options.exclude)
|
||||
};
|
||||
|
||||
let isCanceled = false;
|
||||
|
||||
this._activeSearchCallbacks[requestId] = p => {
|
||||
if (isCanceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.lineMatches.forEach(lineMatch => {
|
||||
lineMatch.offsetAndLengths.forEach(offsetAndLength => {
|
||||
const range = new Range(lineMatch.lineNumber, offsetAndLength[0], lineMatch.lineNumber, offsetAndLength[0] + offsetAndLength[1]);
|
||||
@@ -409,7 +415,10 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
};
|
||||
|
||||
if (token) {
|
||||
token.onCancellationRequested(() => this._proxy.$cancelSearch(requestId));
|
||||
token.onCancellationRequested(() => {
|
||||
isCanceled = true;
|
||||
this._proxy.$cancelSearch(requestId);
|
||||
});
|
||||
}
|
||||
|
||||
return this._proxy.$startTextSearch(query, queryOptions, requestId).then(
|
||||
|
||||
Reference in New Issue
Block a user