Skip to content

Commit c60ccaa

Browse files
committed
change other instances of expand
1 parent 9b9508d commit c60ccaa

File tree

6 files changed

+37
-41
lines changed

6 files changed

+37
-41
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ registerAction2(class ExpandSelectedTreeCommandAction extends Action2 {
9999
});
100100
}
101101

102-
override run(accessor: any) {
103-
expandSelectSubtree(accessor);
102+
override async run(accessor: any) {
103+
return expandSelectSubtree(accessor);
104104
}
105105
});
106106

@@ -298,13 +298,13 @@ registerAction2(class FindInWorkspaceAction extends Action2 {
298298
});
299299

300300
//#region Helpers
301-
function expandSelectSubtree(accessor: ServicesAccessor) {
301+
async function expandSelectSubtree(accessor: ServicesAccessor) {
302302
const viewsService = accessor.get(IViewsService);
303303
const searchView = getSearchView(viewsService);
304304
if (searchView) {
305305
const viewer = searchView.getControl();
306306
const selected = viewer.getFocus()[0];
307-
viewer.expand(selected, true);
307+
await viewer.expand(selected, true);
308308
}
309309
}
310310

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,7 @@ async function focusNextSearchResult(accessor: ServicesAccessor): Promise<any> {
453453
return (editorService.activeEditorPane as SearchEditor).focusNextResult();
454454
}
455455

456-
return openSearchView(accessor.get(IViewsService)).then(searchView => {
457-
searchView?.selectNextMatch();
458-
});
456+
return openSearchView(accessor.get(IViewsService)).then(searchView => searchView?.selectNextMatch());
459457
}
460458

461459
async function focusPreviousSearchResult(accessor: ServicesAccessor): Promise<any> {
@@ -466,9 +464,7 @@ async function focusPreviousSearchResult(accessor: ServicesAccessor): Promise<an
466464
return (editorService.activeEditorPane as SearchEditor).focusPreviousResult();
467465
}
468466

469-
return openSearchView(accessor.get(IViewsService)).then(searchView => {
470-
searchView?.selectPreviousMatch();
471-
});
467+
return openSearchView(accessor.get(IViewsService)).then(searchView => searchView?.selectPreviousMatch());
472468
}
473469

474470
async function findOrReplaceInFiles(accessor: ServicesAccessor, expandSearchReplaceWidget: boolean): Promise<any> {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ registerAction2(class RemoveAction extends Action2 {
113113
let nextFocusElement;
114114
const shouldRefocusMatch = shouldRefocus(elementsToRemove, focusElement);
115115
if (focusElement && shouldRefocusMatch) {
116-
nextFocusElement = getElementToFocusAfterRemoved(viewer, focusElement, elementsToRemove);
116+
nextFocusElement = await getElementToFocusAfterRemoved(viewer, focusElement, elementsToRemove);
117117
}
118118

119119
const searchResult = searchView.searchResult;
@@ -281,7 +281,7 @@ async function performReplace(accessor: ServicesAccessor,
281281
}
282282
let nextFocusElement;
283283
if (focusElement) {
284-
nextFocusElement = getElementToFocusAfterRemoved(viewer, focusElement, elementsToReplace);
284+
nextFocusElement = await getElementToFocusAfterRemoved(viewer, focusElement, elementsToReplace);
285285
}
286286

287287
const searchResult = viewlet?.searchResult;
@@ -370,17 +370,17 @@ function compareLevels(elem1: RenderableMatch, elem2: RenderableMatch) {
370370
/**
371371
* Returns element to focus after removing the given element
372372
*/
373-
export function getElementToFocusAfterRemoved(viewer: WorkbenchCompressibleAsyncDataTree<SearchResult, RenderableMatch>, element: RenderableMatch, elementsToRemove: RenderableMatch[]): RenderableMatch | undefined {
373+
export async function getElementToFocusAfterRemoved(viewer: WorkbenchCompressibleAsyncDataTree<SearchResult, RenderableMatch>, element: RenderableMatch, elementsToRemove: RenderableMatch[]): Promise<RenderableMatch | undefined> {
374374
const navigator: ITreeNavigator<any> = viewer.navigate(element);
375375
if (element instanceof FolderMatch) {
376376
while (!!navigator.next() && (!(navigator.current() instanceof FolderMatch) || arrayContainsElementOrParent(navigator.current(), elementsToRemove))) { }
377377
} else if (element instanceof FileMatch) {
378378
while (!!navigator.next() && (!(navigator.current() instanceof FileMatch) || arrayContainsElementOrParent(navigator.current(), elementsToRemove))) {
379-
viewer.expand(navigator.current());
379+
await viewer.expand(navigator.current());
380380
}
381381
} else {
382382
while (navigator.next() && (!(navigator.current() instanceof Match) || arrayContainsElementOrParent(navigator.current(), elementsToRemove))) {
383-
viewer.expand(navigator.current());
383+
await viewer.expand(navigator.current());
384384
}
385385
}
386386
return navigator.current();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ registerAction2(class ExpandAllAction extends Action2 {
127127
}]
128128
});
129129
}
130-
run(accessor: ServicesAccessor, ...args: any[]) {
130+
async run(accessor: ServicesAccessor, ...args: any[]) {
131131
return expandAll(accessor);
132132
}
133133
});
@@ -214,7 +214,7 @@ const clearHistoryCommand: ICommandHandler = accessor => {
214214
searchHistoryService.clearHistory();
215215
};
216216

217-
function expandAll(accessor: ServicesAccessor) {
217+
async function expandAll(accessor: ServicesAccessor) {
218218
const viewsService = accessor.get(IViewsService);
219219
const searchView = getSearchView(viewsService);
220220
if (searchView) {
@@ -224,7 +224,7 @@ function expandAll(accessor: ServicesAccessor) {
224224
if (searchView.model.hasAIResults) {
225225
viewer.expandAll();
226226
} else {
227-
viewer.expand(searchView.model.searchResult.plainTextSearchResult, true);
227+
await viewer.expand(searchView.model.searchResult.plainTextSearchResult, true);
228228
}
229229
} else {
230230
viewer.expandAll();

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,17 @@ export class SearchView extends ViewPane {
394394

395395
asyncResults.then((complete) => {
396396
clearTimeout(slowTimer);
397-
this.onSearchComplete(progressComplete, undefined, undefined, complete);
397+
return this.onSearchComplete(progressComplete, undefined, undefined, complete);
398398
}, (e) => {
399399
clearTimeout(slowTimer);
400-
this.onSearchError(e, progressComplete, undefined, undefined);
400+
return this.onSearchError(e, progressComplete, undefined, undefined);
401401
});
402402

403403
const collapseResults = this.searchConfig.collapseResults;
404404
if (collapseResults !== 'alwaysCollapse' && this.viewModel.searchResult.matches().length === 1) {
405405
const onlyMatch = this.viewModel.searchResult.matches()[0];
406406
if (onlyMatch.count() < 50) {
407-
this.tree.expand(onlyMatch);
407+
await this.tree.expand(onlyMatch);
408408
}
409409
}
410410
}
@@ -1017,7 +1017,7 @@ export class SearchView extends ViewPane {
10171017
return false;
10181018
}
10191019

1020-
selectNextMatch(): void {
1020+
async selectNextMatch(): Promise<void> {
10211021
if (!this.hasSearchResults()) {
10221022
return;
10231023
}
@@ -1027,7 +1027,7 @@ export class SearchView extends ViewPane {
10271027
// Expand the initial selected node, if needed
10281028
if (selected && !(selected instanceof Match)) {
10291029
if (this.tree.isCollapsed(selected)) {
1030-
this.tree.expand(selected);
1030+
await this.tree.expand(selected);
10311031
}
10321032
}
10331033

@@ -1041,7 +1041,7 @@ export class SearchView extends ViewPane {
10411041
// Expand until first child is a Match
10421042
while (next && !(next instanceof Match)) {
10431043
if (this.tree.isCollapsed(next)) {
1044-
this.tree.expand(next);
1044+
await this.tree.expand(next);
10451045
}
10461046

10471047
// Select the first child
@@ -1062,7 +1062,7 @@ export class SearchView extends ViewPane {
10621062
}
10631063
}
10641064

1065-
selectPreviousMatch(): void {
1065+
async selectPreviousMatch(): Promise<void> {
10661066
if (!this.hasSearchResults()) {
10671067
return;
10681068
}
@@ -1089,7 +1089,7 @@ export class SearchView extends ViewPane {
10891089
if (!nextItem) {
10901090
break;
10911091
}
1092-
this.tree.expand(prev);
1092+
await this.tree.expand(prev);
10931093
navigator = this.tree.navigate(nextItem); // recreate navigator because modifying the tree can invalidate it
10941094
prev = nextItem ? navigator.previous() : navigator.last(); // select last child
10951095
}
@@ -1642,7 +1642,7 @@ export class SearchView extends ViewPane {
16421642
}
16431643
}
16441644

1645-
private onSearchComplete(progressComplete: () => void, excludePatternText?: string, includePatternText?: string, completed?: ISearchComplete) {
1645+
private async onSearchComplete(progressComplete: () => void, excludePatternText?: string, includePatternText?: string, completed?: ISearchComplete) {
16461646

16471647
this.state = SearchUIState.Idle;
16481648

@@ -1656,7 +1656,7 @@ export class SearchView extends ViewPane {
16561656
if (collapseResults !== 'alwaysCollapse' && this.viewModel.searchResult.matches().length === 1) {
16571657
const onlyMatch = this.viewModel.searchResult.matches()[0];
16581658
if (onlyMatch.count() < 50) {
1659-
this.tree.expand(onlyMatch);
1659+
await this.tree.expand(onlyMatch);
16601660
}
16611661
}
16621662

@@ -1745,7 +1745,7 @@ export class SearchView extends ViewPane {
17451745
this.reLayout();
17461746
}
17471747

1748-
private onSearchError(e: any, progressComplete: () => void, excludePatternText?: string, includePatternText?: string, completed?: ISearchComplete) {
1748+
private async onSearchError(e: any, progressComplete: () => void, excludePatternText?: string, includePatternText?: string, completed?: ISearchComplete) {
17491749
this.state = SearchUIState.Idle;
17501750
if (errors.isCancellationError(e)) {
17511751
return this.onSearchComplete(progressComplete, excludePatternText, includePatternText, completed);
@@ -1787,10 +1787,10 @@ export class SearchView extends ViewPane {
17871787
const result = this.viewModel.addAIResults();
17881788
return result.then((complete) => {
17891789
clearTimeout(slowTimer);
1790-
this.onSearchComplete(progressComplete, excludePatternText, includePatternText, complete);
1790+
return this.onSearchComplete(progressComplete, excludePatternText, includePatternText, complete);
17911791
}, (e) => {
17921792
clearTimeout(slowTimer);
1793-
this.onSearchError(e, progressComplete, excludePatternText, includePatternText);
1793+
return this.onSearchError(e, progressComplete, excludePatternText, includePatternText);
17941794
});
17951795

17961796
}
@@ -1822,10 +1822,10 @@ export class SearchView extends ViewPane {
18221822
const result = this.viewModel.search(query);
18231823
return result.asyncResults.then((complete) => {
18241824
clearTimeout(slowTimer);
1825-
this.onSearchComplete(progressComplete, excludePatternText, includePatternText, complete);
1825+
return this.onSearchComplete(progressComplete, excludePatternText, includePatternText, complete);
18261826
}, (e) => {
18271827
clearTimeout(slowTimer);
1828-
this.onSearchError(e, progressComplete, excludePatternText, includePatternText);
1828+
return this.onSearchError(e, progressComplete, excludePatternText, includePatternText);
18291829
});
18301830
}
18311831

src/vs/workbench/contrib/search/test/browser/searchActions.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,36 @@ suite('Search Actions', () => {
4242
instantiationService.dispose();
4343
});
4444

45-
test('get next element to focus after removing a match when it has next sibling file', function () {
45+
test('get next element to focus after removing a match when it has next sibling file', async function () {
4646
const fileMatch1 = aFileMatch();
4747
const fileMatch2 = aFileMatch();
4848
const data = [fileMatch1, aMatch(fileMatch1), aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), aMatch(fileMatch2)];
4949
const tree = aTree(data);
5050
const target = data[2];
5151

52-
const actual = getElementToFocusAfterRemoved(tree, target, [target]);
52+
const actual = await getElementToFocusAfterRemoved(tree, target, [target]);
5353
assert.strictEqual(data[4], actual);
5454
});
5555

56-
test('get next element to focus after removing a match when it is the only match', function () {
56+
test('get next element to focus after removing a match when it is the only match', async function () {
5757
const fileMatch1 = aFileMatch();
5858
const data = [fileMatch1, aMatch(fileMatch1)];
5959
const tree = aTree(data);
6060
const target = data[1];
6161

62-
const actual = getElementToFocusAfterRemoved(tree, target, [target]);
62+
const actual = await getElementToFocusAfterRemoved(tree, target, [target]);
6363
assert.strictEqual(undefined, actual);
6464
});
6565

66-
test('get next element to focus after removing a file match when it has next sibling', function () {
66+
test('get next element to focus after removing a file match when it has next sibling', async function () {
6767
const fileMatch1 = aFileMatch();
6868
const fileMatch2 = aFileMatch();
6969
const fileMatch3 = aFileMatch();
7070
const data = [fileMatch1, aMatch(fileMatch1), fileMatch2, aMatch(fileMatch2), fileMatch3, aMatch(fileMatch3)];
7171
const tree = aTree(data);
7272
const target = data[2];
7373

74-
const actual = getElementToFocusAfterRemoved(tree, target, []);
74+
const actual = await getElementToFocusAfterRemoved(tree, target, []);
7575
assert.strictEqual(data[4], actual);
7676
});
7777

@@ -97,14 +97,14 @@ suite('Search Actions', () => {
9797
assert.strictEqual(data[5], actual);
9898
});
9999

100-
test('get next element to focus after removing a file match when it is only match', function () {
100+
test('get next element to focus after removing a file match when it is only match', async function () {
101101
const fileMatch1 = aFileMatch();
102102
const data = [fileMatch1, aMatch(fileMatch1)];
103103
const tree = aTree(data);
104104
const target = data[0];
105105
// const testObject: ReplaceAction = instantiationService.createInstance(ReplaceAction, tree, target, null);
106106

107-
const actual = getElementToFocusAfterRemoved(tree, target, []);
107+
const actual = await getElementToFocusAfterRemoved(tree, target, []);
108108
assert.strictEqual(undefined, actual);
109109
});
110110

0 commit comments

Comments
 (0)