debt - smarter initial commands picker

This commit is contained in:
Benjamin Pasero 2019-02-05 12:52:01 +01:00
parent beabfb15c8
commit 30afe8898a

View file

@ -31,6 +31,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { CancellationToken } from 'vs/base/common/cancellation';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { Disposable } from 'vs/base/common/lifecycle';
import { timeout } from 'vs/base/common/async';
export const ALL_COMMANDS_PREFIX = '>';
@ -376,6 +377,7 @@ export class CommandsHandler extends QuickOpenHandler {
private commandHistoryEnabled: boolean;
private commandsHistory: CommandsHistory;
private extensionsRegistered: boolean;
constructor(
@IEditorService private readonly editorService: IEditorService,
@ -389,6 +391,8 @@ export class CommandsHandler extends QuickOpenHandler {
this.commandsHistory = this.instantiationService.createInstance(CommandsHistory);
this.extensionService.whenInstalledExtensionsRegistered().then(() => this.extensionsRegistered = true);
this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration());
this.updateConfiguration();
}
@ -398,12 +402,20 @@ export class CommandsHandler extends QuickOpenHandler {
}
getResults(searchValue: string, token: CancellationToken): Promise<QuickOpenModel> {
if (this.extensionsRegistered) {
return this.doGetResults(searchValue, token);
}
// wait for extensions being registered to cover all commands
// also from extensions
return this.extensionService.whenInstalledExtensionsRegistered().then(() => {
// If extensions are not yet registered, we wait for a little moment to give them
// a chance to register so that the complete set of commands shows up as result
// We do not want to delay functionality beyond that time though to keep the commands
// functional.
return Promise.race([timeout(800), this.extensionService.whenInstalledExtensionsRegistered().then(() => undefined)]).then(() => this.doGetResults(searchValue, token));
}
private doGetResults(searchValue: string, token: CancellationToken): Promise<QuickOpenModel> {
if (token.isCancellationRequested) {
return new QuickOpenModel([]);
return Promise.resolve(new QuickOpenModel([]));
}
searchValue = searchValue.trim();
@ -479,8 +491,7 @@ export class CommandsHandler extends QuickOpenHandler {
}
}
return new QuickOpenModel(entries);
});
return Promise.resolve(new QuickOpenModel(entries));
}
private editorActionsToEntries(actions: IEditorAction[], searchValue: string): EditorActionCommandEntry[] {