Skip to content

Commit 9b8401d

Browse files
author
Benjamin Pasero
committed
1 parent 553e8d6 commit 9b8401d

8 files changed

Lines changed: 38 additions & 28 deletions

File tree

src/vs/editor/browser/services/bulkEditService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
77
import { WorkspaceEdit } from 'vs/editor/common/modes';
88
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
9-
import { IProgressRunner } from 'vs/platform/progress/common/progress';
9+
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
1010

1111
export const IBulkEditService = createDecorator<IBulkEditService>('IWorkspaceEditService');
1212

1313

1414
export interface IBulkEditOptions {
1515
editor?: ICodeEditor;
16-
progress?: IProgressRunner;
16+
progress?: IProgress<IProgressStep>;
1717
}
1818

1919
export interface IBulkEditResult {

src/vs/platform/progress/common/progress.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface IProgressCompositeOptions extends IProgressOptions {
7474
export interface IProgressStep {
7575
message?: string;
7676
increment?: number;
77+
total?: number;
7778
}
7879

7980
export interface IProgressRunner {
@@ -82,6 +83,8 @@ export interface IProgressRunner {
8283
done(): void;
8384
}
8485

86+
export const emptyProgress: IProgress<IProgressStep> = { report: () => { } };
87+
8588
export const emptyProgressRunner: IProgressRunner = Object.freeze({
8689
total() { },
8790
worked() { },

src/vs/workbench/contrib/search/browser/replaceService.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1313
import { IModelService } from 'vs/editor/common/services/modelService';
1414
import { IModeService } from 'vs/editor/common/services/modeService';
1515
import { Match, FileMatch, FileMatchOrMatch, ISearchWorkbenchService } from 'vs/workbench/contrib/search/common/searchModel';
16-
import { IProgressRunner } from 'vs/platform/progress/common/progress';
16+
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
1717
import { ITextModelService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
1818
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
1919
import { ScrollType } from 'vs/editor/common/editorCommon';
@@ -101,13 +101,11 @@ export class ReplaceService implements IReplaceService {
101101
) { }
102102

103103
replace(match: Match): Promise<any>;
104-
replace(files: FileMatch[], progress?: IProgressRunner): Promise<any>;
105-
replace(match: FileMatchOrMatch, progress?: IProgressRunner, resource?: URI): Promise<any>;
106-
replace(arg: any, progress: IProgressRunner | undefined = undefined, resource: URI | null = null): Promise<any> {
107-
104+
replace(files: FileMatch[], progress?: IProgress<IProgressStep>): Promise<any>;
105+
replace(match: FileMatchOrMatch, progress?: IProgress<IProgressStep>, resource?: URI): Promise<any>;
106+
replace(arg: any, progress: IProgress<IProgressStep> | undefined = undefined, resource: URI | null = null): Promise<any> {
108107
const edits: ResourceTextEdit[] = this.createEdits(arg, resource);
109108
return this.bulkEditorService.apply({ edits }, { progress }).then(() => this.textFileService.saveAll(edits.map(e => e.resource)));
110-
111109
}
112110

113111
openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<any> {

src/vs/workbench/contrib/search/browser/searchView.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { FileChangesEvent, FileChangeType, IFileService } from 'vs/platform/file
3333
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3434
import { TreeResourceNavigator2, WorkbenchObjectTree, getSelectionKeyboardEvent } from 'vs/platform/list/browser/listService';
3535
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
36-
import { ILocalProgressService, IProgressService } from 'vs/platform/progress/common/progress';
36+
import { IProgressService, IProgressStep, IProgress } from 'vs/platform/progress/common/progress';
3737
import { IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ITextQuery, SearchErrorCode, VIEW_ID, VIEWLET_ID } from 'vs/workbench/services/search/common/search';
3838
import { ISearchHistoryService, ISearchHistoryValues } from 'vs/workbench/contrib/search/common/searchHistoryService';
3939
import { diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, editorFindMatchHighlight, editorFindMatchHighlightBorder, listActiveSelectionForeground } from 'vs/platform/theme/common/colorRegistry';
@@ -129,7 +129,6 @@ export class SearchView extends ViewletPanel {
129129
options: IViewletPanelOptions,
130130
@IFileService private readonly fileService: IFileService,
131131
@IEditorService private readonly editorService: IEditorService,
132-
@ILocalProgressService private readonly localProgressService: ILocalProgressService,
133132
@IProgressService private readonly progressService: IProgressService,
134133
@INotificationService private readonly notificationService: INotificationService,
135134
@IDialogService private readonly dialogService: IDialogService,
@@ -518,13 +517,19 @@ export class SearchView extends ViewletPanel {
518517
return;
519518
}
520519

521-
const progressRunner = this.localProgressService.show(100);
522-
523520
const occurrences = this.viewModel.searchResult.count();
524521
const fileCount = this.viewModel.searchResult.fileCount();
525522
const replaceValue = this.searchWidget.getReplaceValue() || '';
526523
const afterReplaceAllMessage = this.buildAfterReplaceAllMessage(occurrences, fileCount, replaceValue);
527524

525+
let progressComplete: () => void;
526+
let progressReporter: IProgress<IProgressStep>;
527+
this.progressService.withProgress({ location: VIEWLET_ID, delay: 100, total: occurrences }, p => {
528+
progressReporter = p;
529+
530+
return new Promise(resolve => progressComplete = resolve);
531+
});
532+
528533
const confirmation: IConfirmation = {
529534
title: nls.localize('replaceAll.confirmation.title', "Replace All"),
530535
message: this.buildReplaceAllConfirmationMessage(occurrences, fileCount, replaceValue),
@@ -535,12 +540,12 @@ export class SearchView extends ViewletPanel {
535540
this.dialogService.confirm(confirmation).then(res => {
536541
if (res.confirmed) {
537542
this.searchWidget.setReplaceAllActionState(false);
538-
this.viewModel.searchResult.replaceAll(progressRunner).then(() => {
539-
progressRunner.done();
543+
this.viewModel.searchResult.replaceAll(progressReporter).then(() => {
544+
progressComplete();
540545
const messageEl = this.clearMessage();
541546
dom.append(messageEl, $('p', undefined, afterReplaceAllMessage));
542547
}, (error) => {
543-
progressRunner.done();
548+
progressComplete();
544549
errors.isPromiseCanceledError(error);
545550
this.notificationService.error(error);
546551
});

src/vs/workbench/contrib/search/common/replace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Match, FileMatch, FileMatchOrMatch } from 'vs/workbench/contrib/search/common/searchModel';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
8-
import { IProgressRunner } from 'vs/platform/progress/common/progress';
8+
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
99

1010
export const IReplaceService = createDecorator<IReplaceService>('replaceService');
1111

@@ -22,7 +22,7 @@ export interface IReplaceService {
2222
* Replace all the matches from the given file matches in the files
2323
* You can also pass the progress runner to update the progress of replacing.
2424
*/
25-
replace(files: FileMatch[], progress?: IProgressRunner): Promise<any>;
25+
replace(files: FileMatch[], progress?: IProgress<IProgressStep>): Promise<any>;
2626

2727
/**
2828
* Opens the replace preview for given file match or match

src/vs/workbench/contrib/search/common/searchModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { FindMatch, IModelDeltaDecoration, ITextModel, OverviewRulerLane, Tracke
1818
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
1919
import { IModelService } from 'vs/editor/common/services/modelService';
2020
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
21-
import { IProgressRunner } from 'vs/platform/progress/common/progress';
21+
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
2222
import { ReplacePattern } from 'vs/workbench/services/search/common/replace';
2323
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchMatch, ITextSearchStats, resultIsMatch, ISearchRange, OneLineRange } from 'vs/workbench/services/search/common/search';
2424
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -736,10 +736,10 @@ export class SearchResult extends Disposable {
736736
return this.getFolderMatch(match.resource()).replace(match);
737737
}
738738

739-
replaceAll(progressRunner: IProgressRunner): Promise<any> {
739+
replaceAll(progress: IProgress<IProgressStep>): Promise<any> {
740740
this.replacingAll = true;
741741

742-
const promise = this.replaceService.replace(this.matches(), progressRunner);
742+
const promise = this.replaceService.replace(this.matches(), progress);
743743
const onDone = Event.stopwatch(Event.fromPromise(promise));
744744
/* __GDPR__
745745
"replaceAll.started" : {

src/vs/workbench/services/bulkEdit/browser/bulkEditService.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { localize } from 'vs/nls';
1818
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
1919
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
2020
import { ILogService } from 'vs/platform/log/common/log';
21-
import { emptyProgressRunner, IProgress, IProgressRunner } from 'vs/platform/progress/common/progress';
21+
import { IProgress, IProgressStep, emptyProgress } from 'vs/platform/progress/common/progress';
2222
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2323
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
2424
import { ILabelService } from 'vs/platform/label/common/label';
@@ -231,11 +231,11 @@ export class BulkEdit {
231231

232232
private _edits: Edit[] = [];
233233
private _editor: ICodeEditor | undefined;
234-
private _progress?: IProgressRunner;
234+
private _progress: IProgress<IProgressStep>;
235235

236236
constructor(
237237
editor: ICodeEditor | undefined,
238-
progress: IProgressRunner | undefined,
238+
progress: IProgress<IProgressStep> | undefined,
239239
@ILogService private readonly _logService: ILogService,
240240
@ITextModelService private readonly _textModelService: ITextModelService,
241241
@IFileService private readonly _fileService: IFileService,
@@ -244,7 +244,7 @@ export class BulkEdit {
244244
@IConfigurationService private readonly _configurationService: IConfigurationService
245245
) {
246246
this._editor = editor;
247-
this._progress = progress || emptyProgressRunner;
247+
this._progress = progress || emptyProgress;
248248
}
249249

250250
add(edits: Edit[] | Edit): void {
@@ -294,10 +294,9 @@ export class BulkEdit {
294294

295295
// define total work and progress callback
296296
// for child operations
297-
if (this._progress) {
298-
this._progress.total(total);
299-
}
300-
let progress: IProgress<void> = { report: _ => this._progress && this._progress.worked(1) };
297+
this._progress.report({ total });
298+
299+
let progress: IProgress<void> = { report: _ => this._progress.report({ increment: 1 }) };
301300

302301
// do it.
303302
for (const group of groups) {

src/vs/workbench/services/progress/browser/progressService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,17 @@ export class ProgressService extends Disposable implements IProgressService {
298298
if (typeof progress.increment === 'number') {
299299
progressRunner.worked(progress.increment);
300300
}
301+
302+
if (typeof progress.total === 'number') {
303+
progressRunner.total(progress.total);
304+
}
301305
}
302306
});
303307

304308
if (compositeProgressService) {
305309
if (typeof options.total === 'number') {
306310
progressRunner = compositeProgressService.show(options.total, options.delay);
311+
promise.catch(() => undefined /* ignore */).finally(() => progressRunner ? progressRunner.done() : undefined);
307312
} else {
308313
compositeProgressService.showWhile(promise, options.delay);
309314
}

0 commit comments

Comments
 (0)