Skip to content

Commit

Permalink
file-search: improve quick-file open
Browse files Browse the repository at this point in the history
- improves the quick-file open to show 'no matching results' when a search
yields no results
- improves handling of no workspaces
- enables the command always similarly to vscode

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed May 26, 2020
1 parent cf178eb commit 02f4400
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export class QuickFileOpenFrontendContribution implements CommandContribution, K
} else {
this.quickFileOpenService.open();
}
},
isEnabled: () => this.quickFileOpenService.isEnabled()
}
});
}

Expand Down
22 changes: 18 additions & 4 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
const token = this.cancelIndicator.token;

const roots = this.workspaceService.tryGetRoots();
if (roots.length === 0) {
return;
}

this.currentLookFor = lookFor;
const alreadyCollected = new Set<string>();
Expand All @@ -170,6 +167,12 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
return;
}
const fileSearchResultItems: QuickOpenItem[] = [];

if (results.length <= 0) {
acceptor([this.toNoResultsItem()]);
return;
}

for (const fileUri of results) {
if (!alreadyCollected.has(fileUri)) {
const item = this.toItem(fileUri);
Expand All @@ -192,6 +195,7 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
// Return the recently used items, followed by the search results.
acceptor([...recentlyUsedItems, ...sortedResults]);
};

this.fileSearchService.find(lookFor, {
rootUris: roots.map(r => r.uri),
fuzzyMatch: true,
Expand All @@ -200,7 +204,9 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
excludePatterns: ['*.git*']
}, token).then(handler);
} else {
acceptor(recentlyUsedItems);
if (roots.length !== 0) {
acceptor(recentlyUsedItems);
}
}
}

Expand Down Expand Up @@ -334,4 +340,12 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {
return new QuickOpenItem<QuickOpenItemOptions>(options);
}
}

private toNoResultsItem(): QuickOpenItem<QuickOpenItemOptions> {
const options: QuickOpenItemOptions = {
label: 'No matching results',
run: () => false
};
return new QuickOpenItem<QuickOpenItemOptions>(options);
}
}

0 comments on commit 02f4400

Please sign in to comment.