Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)

This commit is contained in:
Anthony Dresser
2019-05-24 12:20:30 -07:00
committed by GitHub
parent 361ada4963
commit bcc449b524
126 changed files with 3096 additions and 2255 deletions

View File

@@ -302,6 +302,24 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.collapseAll',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.CtrlCmd | KeyCode.LeftArrow,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.LeftArrow,
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow]
},
handler: (accessor) => {
const focusedTree = accessor.get(IListService).lastFocusedList;
if (focusedTree && !(focusedTree instanceof List || focusedTree instanceof PagedList)) {
focusedTree.collapseAll();
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.expand',
weight: KeybindingWeight.WorkbenchContrib,

View File

@@ -73,7 +73,7 @@ abstract class BaseNavigationAction extends Action {
return this.panelService.openPanel(activePanelId, true)!;
}
protected navigateToSidebar(): Promise<IViewlet | boolean> {
protected async navigateToSidebar(): Promise<IViewlet | boolean> {
if (!this.layoutService.isVisible(Parts.SIDEBAR_PART)) {
return Promise.resolve(false);
}
@@ -84,8 +84,8 @@ abstract class BaseNavigationAction extends Action {
}
const activeViewletId = activeViewlet.getId();
return this.viewletService.openViewlet(activeViewletId, true)
.then(value => value === null ? false : value);
const value = await this.viewletService.openViewlet(activeViewletId, true);
return value === null ? false : value;
}
protected navigateAcrossEditorGroup(direction: GroupDirection): boolean {

View File

@@ -160,21 +160,18 @@ export class GlobalRemoveRootFolderAction extends Action {
super(id, label);
}
run(): Promise<any> {
async run(): Promise<any> {
const state = this.contextService.getWorkbenchState();
// Workspace / Folder
if (state === WorkbenchState.WORKSPACE || state === WorkbenchState.FOLDER) {
return this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID).then(folder => {
if (folder) {
return this.workspaceEditingService.removeFolders([folder.uri]).then(() => true);
}
return true;
});
const folder = await this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
if (folder) {
await this.workspaceEditingService.removeFolders([folder.uri]);
}
}
return Promise.resolve(true);
return true;
}
}
@@ -193,20 +190,18 @@ export class SaveWorkspaceAsAction extends Action {
super(id, label);
}
run(): Promise<any> {
return this.workspaceEditingService.pickNewWorkspacePath().then((configPathUri): Promise<void> | void => {
if (configPathUri) {
switch (this.contextService.getWorkbenchState()) {
case WorkbenchState.EMPTY:
case WorkbenchState.FOLDER:
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
case WorkbenchState.WORKSPACE:
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
}
async run(): Promise<any> {
const configPathUri = await this.workspaceEditingService.pickNewWorkspacePath();
if (configPathUri) {
switch (this.contextService.getWorkbenchState()) {
case WorkbenchState.EMPTY:
case WorkbenchState.FOLDER:
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
case WorkbenchState.WORKSPACE:
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
}
});
}
}
}
@@ -296,14 +291,13 @@ export class DuplicateWorkspaceInNewWindowAction extends Action {
super(id, label);
}
run(): Promise<any> {
async run(): Promise<any> {
const folders = this.workspaceContextService.getWorkspace().folders;
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
return this.workspacesService.createUntitledWorkspace(folders, remoteAuthority).then(newWorkspace => {
return this.workspaceEditingService.copyWorkspaceSettings(newWorkspace).then(() => {
return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
});
});
const newWorkspace = await this.workspacesService.createUntitledWorkspace(folders, remoteAuthority);
await this.workspaceEditingService.copyWorkspaceSettings(newWorkspace);
return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
}
}

View File

@@ -54,30 +54,28 @@ CommandsRegistry.registerCommand({
CommandsRegistry.registerCommand({
id: ADD_ROOT_FOLDER_COMMAND_ID,
handler: (accessor) => {
handler: async (accessor) => {
const viewletService = accessor.get(IViewletService);
const workspaceEditingService = accessor.get(IWorkspaceEditingService);
const dialogsService = accessor.get(IFileDialogService);
return dialogsService.showOpenDialog({
const folders = await dialogsService.showOpenDialog({
openLabel: mnemonicButtonLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")),
title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"),
canSelectFolders: true,
canSelectMany: true,
defaultUri: dialogsService.defaultFolderPath()
}).then((folders): Promise<any> | null => {
if (!folders || !folders.length) {
return null;
}
// Add and show Files Explorer viewlet
return workspaceEditingService.addFolders(folders.map(folder => ({ uri: resources.removeTrailingPathSeparator(folder) })))
.then(() => viewletService.openViewlet(viewletService.getDefaultViewletId(), true))
.then(() => undefined);
});
if (!folders || !folders.length) {
return;
}
await workspaceEditingService.addFolders(folders.map(folder => ({ uri: resources.removeTrailingPathSeparator(folder) })));
await viewletService.openViewlet(viewletService.getDefaultViewletId(), true);
}
});
CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (accessor, args?: [IPickOptions<IQuickPickItem>, CancellationToken]) {
CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, async function (accessor, args?: [IPickOptions<IQuickPickItem>, CancellationToken]) {
const quickInputService = accessor.get(IQuickInputService);
const labelService = accessor.get(ILabelService);
const contextService = accessor.get(IWorkspaceContextService);
@@ -86,7 +84,7 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
const folders = contextService.getWorkspace().folders;
if (!folders.length) {
return undefined;
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
}
const folderPicks: IQuickPickItem[] = folders.map(folder => {
@@ -113,12 +111,11 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
}
const token: CancellationToken = (args ? args[1] : undefined) || CancellationToken.None;
const pick = await quickInputService.pick(folderPicks, options, token);
return quickInputService.pick(folderPicks, options, token).then(pick => {
if (!pick) {
return undefined;
}
if (pick) {
return folders[folderPicks.indexOf(pick)];
});
}
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
});

View File

@@ -170,53 +170,52 @@ export class ResourcesDropHandler {
) {
}
handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup | undefined, afterDrop: (targetGroup: IEditorGroup | undefined) => void, targetIndex?: number): void {
async handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup | undefined, afterDrop: (targetGroup: IEditorGroup | undefined) => void, targetIndex?: number): Promise<void> {
const untitledOrFileResources = extractResources(event).filter(r => this.fileService.canHandleResource(r.resource) || r.resource.scheme === Schemas.untitled);
if (!untitledOrFileResources.length) {
return;
}
// Make the window active to handle the drop properly within
this.windowService.focusWindow().then(() => {
await this.windowService.focusWindow();
// Check for special things being dropped
return this.doHandleDrop(untitledOrFileResources).then(isWorkspaceOpening => {
if (isWorkspaceOpening) {
return undefined; // return early if the drop operation resulted in this window changing to a workspace
}
// Check for special things being dropped
const isWorkspaceOpening = await this.doHandleDrop(untitledOrFileResources);
// Add external ones to recently open list unless dropped resource is a workspace
const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource }));
if (recents.length) {
this.windowsService.addRecentlyOpened(recents);
}
if (isWorkspaceOpening) {
return; // return early if the drop operation resulted in this window changing to a workspace
}
const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({
resource: untitledOrFileResource.resource,
options: {
pinned: true,
index: targetIndex,
viewState: (untitledOrFileResource as IDraggedEditor).viewState
}
}));
// Add external ones to recently open list unless dropped resource is a workspace
const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource }));
if (recents.length) {
this.windowsService.addRecentlyOpened(recents);
}
// Open in Editor
const targetGroup = resolveTargetGroup();
return this.editorService.openEditors(editors, targetGroup).then(() => {
const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({
resource: untitledOrFileResource.resource,
options: {
pinned: true,
index: targetIndex,
viewState: (untitledOrFileResource as IDraggedEditor).viewState
}
}));
// Finish with provided function
afterDrop(targetGroup);
});
});
});
// Open in Editor
const targetGroup = resolveTargetGroup();
await this.editorService.openEditors(editors, targetGroup);
// Finish with provided function
afterDrop(targetGroup);
}
private doHandleDrop(untitledOrFileResources: Array<IDraggedResource | IDraggedEditor>): Promise<boolean> {
private async doHandleDrop(untitledOrFileResources: Array<IDraggedResource | IDraggedEditor>): Promise<boolean> {
// Check for dirty editors being dropped
const resourcesWithBackups: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).backupResource);
if (resourcesWithBackups.length > 0) {
return Promise.all(resourcesWithBackups.map(resourceWithBackup => this.handleDirtyEditorDrop(resourceWithBackup))).then(() => false);
await Promise.all(resourcesWithBackups.map(resourceWithBackup => this.handleDirtyEditorDrop(resourceWithBackup)));
return false;
}
// Check for workspace file being dropped if we are allowed to do so
@@ -227,10 +226,10 @@ export class ResourcesDropHandler {
}
}
return Promise.resolve(false);
return false;
}
private handleDirtyEditorDrop(droppedDirtyEditor: IDraggedEditor): Promise<boolean> {
private async handleDirtyEditorDrop(droppedDirtyEditor: IDraggedEditor): Promise<boolean> {
// Untitled: always ensure that we open a new untitled for each file we drop
if (droppedDirtyEditor.resource.scheme === Schemas.untitled) {
@@ -239,15 +238,18 @@ export class ResourcesDropHandler {
// Return early if the resource is already dirty in target or opened already
if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen({ resource: droppedDirtyEditor.resource })) {
return Promise.resolve(false);
return false;
}
// Resolve the contents of the dropped dirty resource from source
return this.backupFileService.resolveBackupContent(droppedDirtyEditor.backupResource!).then(content => {
try {
const content = await this.backupFileService.resolveBackupContent((droppedDirtyEditor.backupResource!));
await this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
} catch (e) {
// Ignore error
}
// Set the contents of to the resource to the target
return this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
}).then(() => false, () => false /* ignore any error */);
return false;
}
private getDefaultEOL(): DefaultEndOfLine {
@@ -259,44 +261,50 @@ export class ResourcesDropHandler {
return DefaultEndOfLine.LF;
}
private handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
private async handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
const urisToOpen: IURIToOpen[] = [];
const folderURIs: IWorkspaceFolderCreationData[] = [];
return Promise.all(fileOnDiskResources.map(fileOnDiskResource => {
await Promise.all(fileOnDiskResources.map(async fileOnDiskResource => {
// Check for Workspace
if (hasWorkspaceFileExtension(fileOnDiskResource)) {
urisToOpen.push({ workspaceUri: fileOnDiskResource });
return undefined;
return;
}
// Check for Folder
return this.fileService.resolve(fileOnDiskResource).then(stat => {
try {
const stat = await this.fileService.resolve(fileOnDiskResource);
if (stat.isDirectory) {
urisToOpen.push({ folderUri: stat.resource });
folderURIs.push({ uri: stat.resource });
}
}, error => undefined);
})).then(_ => {
// Return early if no external resource is a folder or workspace
if (urisToOpen.length === 0) {
return false;
} catch (error) {
// Ignore error
}
}));
// Pass focus to window
this.windowService.focusWindow();
// Return early if no external resource is a folder or workspace
if (urisToOpen.length === 0) {
return false;
}
// Open in separate windows if we drop workspaces or just one folder
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
return this.windowService.openWindow(urisToOpen, { forceReuseWindow: true }).then(_ => true);
}
// Pass focus to window
this.windowService.focusWindow();
// folders.length > 1: Multiple folders: Create new workspace with folders and open
return this.workspaceEditingService.createAndEnterWorkspace(folderURIs).then(_ => true);
});
// Open in separate windows if we drop workspaces or just one folder
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
await this.windowService.openWindow(urisToOpen, { forceReuseWindow: true });
}
// folders.length > 1: Multiple folders: Create new workspace with folders and open
else {
await this.workspaceEditingService.createAndEnterWorkspace(folderURIs);
}
return true;
}
}

View File

@@ -42,15 +42,15 @@ export class ViewletActivityAction extends ActivityAction {
super(activity);
}
run(event: any): Promise<any> {
async run(event: any): Promise<any> {
if (event instanceof MouseEvent && event.button === 2) {
return Promise.resolve(false); // do not run on right click
return false; // do not run on right click
}
// prevent accident trigger on a doubleclick (to help nervous people)
const now = Date.now();
if (now > this.lastRun /* https://github.com/Microsoft/vscode/issues/25830 */ && now - this.lastRun < ViewletActivityAction.preventDoubleClickDelay) {
return Promise.resolve(true);
return true;
}
this.lastRun = now;
@@ -61,11 +61,12 @@ export class ViewletActivityAction extends ActivityAction {
if (sideBarVisible && activeViewlet && activeViewlet.getId() === this.activity.id) {
this.logAction('hide');
this.layoutService.setSideBarHidden(true);
return Promise.resolve();
return true;
}
this.logAction('show');
return this.viewletService.openViewlet(this.activity.id, true).then(() => this.activate());
await this.viewletService.openViewlet(this.activity.id, true);
return this.activate();
}
private logAction(action: string) {

View File

@@ -204,12 +204,13 @@ export class CompositeBar extends Widget implements ICompositeBar {
return toDisposable(() => this.model.removeActivity(compositeId, activity));
}
pin(compositeId: string, open?: boolean): void {
async pin(compositeId: string, open?: boolean): Promise<void> {
if (this.model.setPinned(compositeId, true)) {
this.updateCompositeSwitcher();
if (open) {
this.options.openComposite(compositeId).then(() => this.activateComposite(compositeId)); // Activate after opening
await this.options.openComposite(compositeId);
this.activateComposite(compositeId); // Activate after opening
}
}
}

View File

@@ -74,44 +74,33 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
parent.appendChild(this.scrollbar.getDomNode());
}
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
return super.setInput(input, options, token).then(() => {
return input.resolve().then(model => {
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
await super.setInput(input, options, token);
const model = await input.resolve();
// Check for cancellation
if (token.isCancellationRequested) {
return undefined;
}
// Check for cancellation
if (token.isCancellationRequested) {
return;
}
// Assert Model instance
if (!(model instanceof BinaryEditorModel)) {
return Promise.reject(new Error('Unable to open file as binary'));
}
// Assert Model instance
if (!(model instanceof BinaryEditorModel)) {
throw new Error('Unable to open file as binary');
}
// Render Input
this.resourceViewerContext = ResourceViewer.show(
{ name: model.getName(), resource: model.getResource(), size: model.getSize(), etag: model.getETag(), mime: model.getMime() },
this.textFileService,
this.binaryContainer,
this.scrollbar,
{
openInternalClb: _ => this.handleOpenInternalCallback(input, options),
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
metadataClb: meta => this.handleMetadataChanged(meta)
}
);
return undefined;
});
// Render Input
this.resourceViewerContext = ResourceViewer.show({ name: model.getName(), resource: model.getResource(), size: model.getSize(), etag: model.getETag(), mime: model.getMime() }, this.textFileService, this.binaryContainer, this.scrollbar, {
openInternalClb: () => this.handleOpenInternalCallback(input, options),
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
metadataClb: meta => this.handleMetadataChanged(meta)
});
}
private handleOpenInternalCallback(input: EditorInput, options: EditorOptions) {
this.callbacks.openInternal(input, options).then(() => {
private async handleOpenInternalCallback(input: EditorInput, options: EditorOptions): Promise<void> {
await this.callbacks.openInternal(input, options);
// Signal to listeners that the binary editor has been opened in-place
this._onDidOpenInPlace.fire();
});
// Signal to listeners that the binary editor has been opened in-place
this._onDidOpenInPlace.fire();
}
private handleMetadataChanged(meta: string | undefined): void {

View File

@@ -539,23 +539,27 @@ export class RevertAndCloseEditorAction extends Action {
super(id, label);
}
run(): Promise<any> {
async run(): Promise<any> {
const activeControl = this.editorService.activeControl;
if (activeControl) {
const editor = activeControl.input;
const group = activeControl.group;
// first try a normal revert where the contents of the editor are restored
return editor.revert().then(() => group.closeEditor(editor), error => {
try {
await editor.revert();
} catch (error) {
// if that fails, since we are about to close the editor, we accept that
// the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails.
return editor.revert({ soft: true }).then(() => group.closeEditor(editor));
});
await editor.revert({ soft: true });
}
group.closeEditor(editor);
}
return Promise.resolve(false);
return true;
}
}
@@ -618,7 +622,7 @@ export abstract class BaseCloseAllAction extends Action {
return groupsToClose;
}
run(): Promise<any> {
async run(): Promise<any> {
// Just close all if there are no or one dirty editor
if (this.textFileService.getDirty().length < 2) {
@@ -626,26 +630,23 @@ export abstract class BaseCloseAllAction extends Action {
}
// Otherwise ask for combined confirmation
return this.textFileService.confirmSave().then(confirm => {
if (confirm === ConfirmResult.CANCEL) {
return undefined;
}
const confirm = await this.textFileService.confirmSave();
if (confirm === ConfirmResult.CANCEL) {
return;
}
let saveOrRevertPromise: Promise<boolean>;
if (confirm === ConfirmResult.DONT_SAVE) {
saveOrRevertPromise = this.textFileService.revertAll(undefined, { soft: true }).then(() => true);
} else {
saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => !!r.success));
}
let saveOrRevert: boolean;
if (confirm === ConfirmResult.DONT_SAVE) {
await this.textFileService.revertAll(undefined, { soft: true });
saveOrRevert = true;
} else {
const res = await this.textFileService.saveAll(true);
saveOrRevert = res.results.every(r => !!r.success);
}
return saveOrRevertPromise.then(success => {
if (success) {
return this.doCloseAll();
}
return undefined;
});
});
if (saveOrRevert) {
return this.doCloseAll();
}
}
protected abstract doCloseAll(): Promise<any>;
@@ -684,10 +685,10 @@ export class CloseAllEditorGroupsAction extends BaseCloseAllAction {
super(id, label, undefined, textFileService, editorGroupService);
}
protected doCloseAll(): Promise<any> {
return Promise.all(this.groupsToClose.map(g => g.closeAllEditors())).then(() => {
this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
});
protected async doCloseAll(): Promise<any> {
await Promise.all(this.groupsToClose.map(group => group.closeAllEditors()));
this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
}
}

View File

@@ -670,19 +670,17 @@ function registerCloseEditorCommands() {
}
});
CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, (accessor: ServicesAccessor, resourceOrContext: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, async (accessor: ServicesAccessor, resourceOrContext: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
const editorGroupService = accessor.get(IEditorGroupsService);
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
if (group) {
return group.closeAllEditors().then(() => {
if (group.count === 0 && editorGroupService.getGroup(group.id) /* could be gone by now */) {
editorGroupService.removeGroup(group); // only remove group if it is now empty
}
});
}
await group.closeAllEditors();
return undefined;
if (group.count === 0 && editorGroupService.getGroup(group.id) /* could be gone by now */) {
editorGroupService.removeGroup(group); // only remove group if it is now empty
}
}
});
}

View File

@@ -58,7 +58,7 @@ export class EditorControl extends Disposable {
return this._activeControl as IVisibleEditor | null;
}
openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
async openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
// Editor control
const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(editor);
@@ -68,7 +68,8 @@ export class EditorControl extends Disposable {
const control = this.doShowEditorControl(descriptor);
// Set input
return this.doSetInput(control, editor, withUndefinedAsNull(options)).then((editorChanged => (({ control, editorChanged }))));
const editorChanged = await this.doSetInput(control, editor, withUndefinedAsNull(options));
return { control, editorChanged };
}
private doShowEditorControl(descriptor: IEditorDescriptor): BaseEditor {
@@ -150,7 +151,7 @@ export class EditorControl extends Disposable {
this._onDidSizeConstraintsChange.fire(undefined);
}
private doSetInput(control: BaseEditor, editor: EditorInput, options: EditorOptions | null): Promise<boolean> {
private async doSetInput(control: BaseEditor, editor: EditorInput, options: EditorOptions | null): Promise<boolean> {
// If the input did not change, return early and only apply the options
// unless the options instruct us to force open it even if it is the same
@@ -167,7 +168,7 @@ export class EditorControl extends Disposable {
control.focus();
}
return Promise.resolve(false);
return false;
}
// Show progress while setting input after a certain timeout. If the workbench is opening
@@ -176,7 +177,8 @@ export class EditorControl extends Disposable {
// Call into editor control
const editorWillChange = !inputMatches;
return control.setInput(editor, options, operation.token).then(() => {
try {
await control.setInput(editor, options, operation.token);
// Focus (unless prevented or another operation is running)
if (operation.isCurrent()) {
@@ -186,17 +188,10 @@ export class EditorControl extends Disposable {
}
}
// Operation done
operation.stop();
return editorWillChange;
}, e => {
// Operation done
} finally {
operation.stop();
return Promise.reject(e);
});
}
}
private doHideActiveEditorControl(): void {

View File

@@ -406,7 +406,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}
}
private restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> {
private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> {
if (this._group.count === 0) {
return Promise.resolve(); // nothing to show
}
@@ -430,16 +430,15 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const activeElement = document.activeElement;
// Show active editor
return this.doShowEditor(activeEditor, true, options).then(() => {
await this.doShowEditor(activeEditor, true, options);
// Set focused now if this is the active group and focus has
// not changed meanwhile. This prevents focus from being
// stolen accidentally on startup when the user already
// clicked somewhere.
if (this.accessor.activeGroup === this && activeElement === document.activeElement) {
this.focus();
}
});
// Set focused now if this is the active group and focus has
// not changed meanwhile. This prevents focus from being
// stolen accidentally on startup when the user already
// clicked somewhere.
if (this.accessor.activeGroup === this && activeElement === document.activeElement) {
this.focus();
}
}
//#region event handling
@@ -821,34 +820,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
return this.doShowEditor(editor, !!openEditorOptions.active, options);
}
private doShowEditor(editor: EditorInput, active: boolean, options?: EditorOptions): Promise<IEditor | null> {
private async doShowEditor(editor: EditorInput, active: boolean, options?: EditorOptions): Promise<IEditor | null> {
// Show in editor control if the active editor changed
let openEditorPromise: Promise<IEditor | null>;
let openEditor: IEditor | null = null;
if (active) {
openEditorPromise = this.editorControl.openEditor(editor, options).then(result => {
try {
const result = await this.editorControl.openEditor(editor, options);
// Editor change event
if (result.editorChanged) {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor });
}
return result.control;
}, error => {
openEditor = result.control;
} catch (error) {
// Handle errors but do not bubble them up
this.doHandleOpenEditorError(error, editor, options);
return null; // error: return NULL as result to signal this
});
}
} else {
openEditorPromise = Promise.resolve(null); // inactive: return NULL as result to signal this
openEditor = null; // inactive: return NULL as result to signal this
}
// Show in title control after editor control because some actions depend on it
this.titleAreaControl.openEditor(editor);
return openEditorPromise;
return openEditor;
}
private doHandleOpenEditorError(error: Error, editor: EditorInput, options?: EditorOptions): void {
@@ -884,37 +882,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region openEditors()
openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> {
async openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> {
if (!editors.length) {
return Promise.resolve(null);
return null;
}
// Do not modify original array
editors = editors.slice(0);
let result: IEditor | null;
// Use the first editor as active editor
const { editor, options } = editors.shift()!;
return this.openEditor(editor, options).then(activeEditor => {
result = activeEditor; // this can be NULL if the opening failed
let firstEditor = await this.openEditor(editor, options);
const startingIndex = this.getIndexOfEditor(editor) + 1;
// Open the other ones inactive
const startingIndex = this.getIndexOfEditor(editor) + 1;
await Promise.all(editors.map(async ({ editor, options }, index) => {
const adjustedEditorOptions = options || new EditorOptions();
adjustedEditorOptions.inactive = true;
adjustedEditorOptions.pinned = true;
adjustedEditorOptions.index = startingIndex + index;
// Open the other ones inactive
return Promise.all(editors.map(({ editor, options }, index) => {
const adjustedEditorOptions = options || new EditorOptions();
adjustedEditorOptions.inactive = true;
adjustedEditorOptions.pinned = true;
adjustedEditorOptions.index = startingIndex + index;
const openedEditor = await this.openEditor(editor, adjustedEditorOptions);
if (!firstEditor) {
firstEditor = openedEditor; // only take if the first editor opening failed
}
}));
return this.openEditor(editor, adjustedEditorOptions).then(activeEditor => {
if (!result) {
result = activeEditor; // only take if the first editor opening failed
}
});
})).then(() => result);
});
return firstEditor;
}
//#endregion
@@ -995,20 +989,19 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region closeEditor()
closeEditor(editor: EditorInput | undefined = this.activeEditor || undefined, options?: ICloseEditorOptions): Promise<void> {
async closeEditor(editor: EditorInput | undefined = this.activeEditor || undefined, options?: ICloseEditorOptions): Promise<void> {
if (!editor) {
return Promise.resolve();
return;
}
// Check for dirty and veto
return this.handleDirty([editor]).then(veto => {
if (veto) {
return;
}
const veto = await this.handleDirty([editor]);
if (veto) {
return;
}
// Do close
this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined);
});
// Do close
this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined);
}
private doCloseEditor(editor: EditorInput, focusNext = (this.accessor.activeGroup === this), fromError?: boolean): void {
@@ -1113,7 +1106,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this._group.closeEditor(editor);
}
private handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> {
private async handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> {
if (!editors.length) {
return Promise.resolve(false); // no veto
}
@@ -1128,22 +1121,21 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.mapEditorToPendingConfirmation.set(editor, handleDirtyPromise);
}
return handleDirtyPromise.then(veto => {
const veto = await handleDirtyPromise;
// Make sure to remove from our map of cached pending confirmations
this.mapEditorToPendingConfirmation.delete(editor);
// Make sure to remove from our map of cached pending confirmations
this.mapEditorToPendingConfirmation.delete(editor);
// Return for the first veto we got
if (veto) {
return veto;
}
// Return for the first veto we got
if (veto) {
return veto;
}
// Otherwise continue with the remainders
return this.handleDirty(editors);
});
// Otherwise continue with the remainders
return this.handleDirty(editors);
}
private doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> {
private async doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> {
if (
!editor.isDirty() || // editor must be dirty
this.accessor.groups.some(groupView => groupView !== this && groupView.group.contains(editor, true /* support side by side */)) || // editor is opened in other group
@@ -1153,59 +1145,65 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}
// Switch to editor that we want to handle and confirm to save/revert
return this.openEditor(editor).then(() => editor.confirmSave().then(res => {
await this.openEditor(editor);
// It could be that the editor saved meanwhile, so we check again
// to see if anything needs to happen before closing for good.
// This can happen for example if autoSave: onFocusChange is configured
// so that the save happens when the dialog opens.
if (!editor.isDirty()) {
return res === ConfirmResult.CANCEL ? true : false;
}
const res = await editor.confirmSave();
// Otherwise, handle accordingly
switch (res) {
case ConfirmResult.SAVE:
return editor.save().then(ok => !ok);
// It could be that the editor saved meanwhile, so we check again
// to see if anything needs to happen before closing for good.
// This can happen for example if autoSave: onFocusChange is configured
// so that the save happens when the dialog opens.
if (!editor.isDirty()) {
return res === ConfirmResult.CANCEL ? true : false;
}
case ConfirmResult.DONT_SAVE:
// Otherwise, handle accordingly
switch (res) {
case ConfirmResult.SAVE:
const result = await editor.save();
return !result;
case ConfirmResult.DONT_SAVE:
try {
// first try a normal revert where the contents of the editor are restored
return editor.revert().then(ok => !ok, error => {
const result = await editor.revert();
// if that fails, since we are about to close the editor, we accept that
// the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails.
return editor.revert({ soft: true }).then(ok => !ok);
});
return !result;
} catch (error) {
// if that fails, since we are about to close the editor, we accept that
// the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails.
const result = await editor.revert({ soft: true });
case ConfirmResult.CANCEL:
return true; // veto
}
}));
return !result;
}
case ConfirmResult.CANCEL:
return true; // veto
}
}
//#endregion
//#region closeEditors()
closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> {
async closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> {
if (this.isEmpty()) {
return Promise.resolve();
return;
}
const editors = this.getEditorsToClose(args);
// Check for dirty and veto
return this.handleDirty(editors.slice(0)).then(veto => {
if (veto) {
return;
}
const veto = await this.handleDirty(editors.slice(0));
if (veto) {
return;
}
// Do close
this.doCloseEditors(editors, options);
});
// Do close
this.doCloseEditors(editors, options);
}
private getEditorsToClose(editors: EditorInput[] | ICloseEditorsFilter): EditorInput[] {
@@ -1263,7 +1261,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region closeAllEditors()
closeAllEditors(): Promise<void> {
async closeAllEditors(): Promise<void> {
if (this.isEmpty()) {
// If the group is empty and the request is to close all editors, we still close
@@ -1273,19 +1271,18 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.accessor.removeGroup(this);
}
return Promise.resolve();
return;
}
// Check for dirty and veto
const editors = this._group.getEditors(true);
return this.handleDirty(editors.slice(0)).then(veto => {
if (veto) {
return;
}
const veto = await this.handleDirty(editors.slice(0));
if (veto) {
return;
}
// Do close
this.doCloseAllEditors();
});
// Do close
this.doCloseAllEditors();
}
private doCloseAllEditors(): void {
@@ -1308,7 +1305,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region replaceEditors()
replaceEditors(editors: EditorReplacement[]): Promise<void> {
async replaceEditors(editors: EditorReplacement[]): Promise<void> {
// Extract active vs. inactive replacements
let activeReplacement: EditorReplacement | undefined;
@@ -1366,10 +1363,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.titleAreaControl.closeEditor(activeReplacement.editor);
}
return openEditorResult.then(() => undefined);
await openEditorResult;
}
return Promise.resolve();
}
//#endregion

View File

@@ -858,8 +858,8 @@ export class ShowLanguageExtensionsAction extends Action {
this.enabled = galleryService.isEnabled();
}
run(): Promise<void> {
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension).then(() => undefined);
async run(): Promise<void> {
await this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension);
}
}
@@ -883,7 +883,7 @@ export class ChangeModeAction extends Action {
super(actionId, actionLabel);
}
run(): Promise<any> {
async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1038,31 +1038,30 @@ export class ChangeModeAction extends Action {
};
});
setTimeout(() => {
this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) }).then(language => {
if (language) {
const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG);
setTimeout(async () => {
const language = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) });
if (language) {
const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG);
let associationKey: string;
if (extension && base[0] !== '.') {
associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext>
} else {
associationKey = base; // otherwise use the basename (e.g. .gitignore, Dockerfile)
}
// If the association is already being made in the workspace, make sure to target workspace settings
let target = ConfigurationTarget.USER;
if (fileAssociationsConfig.workspace && !!fileAssociationsConfig.workspace[associationKey]) {
target = ConfigurationTarget.WORKSPACE;
}
// Make sure to write into the value of the target and not the merged value from USER and WORKSPACE config
const currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user) || Object.create(null);
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
let associationKey: string;
if (extension && base[0] !== '.') {
associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext>
} else {
associationKey = base; // otherwise use the basename (e.g. .gitignore, Dockerfile)
}
});
// If the association is already being made in the workspace, make sure to target workspace settings
let target = ConfigurationTarget.USER;
if (fileAssociationsConfig.workspace && !!fileAssociationsConfig.workspace[associationKey]) {
target = ConfigurationTarget.WORKSPACE;
}
// Make sure to write into the value of the target and not the merged value from USER and WORKSPACE config
const currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user) || Object.create(null);
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
}
}, 50 /* quick open is sensitive to being opened so soon after another */);
}
}
@@ -1085,7 +1084,7 @@ class ChangeIndentationAction extends Action {
super(actionId, actionLabel);
}
run(): Promise<any> {
async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1117,7 +1116,8 @@ class ChangeIndentationAction extends Action {
picks.splice(3, 0, { type: 'separator', label: nls.localize('indentConvert', "convert file") });
picks.unshift({ type: 'separator', label: nls.localize('indentView', "change view") });
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true }).then(action => action && action.run());
const action = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true });
return action && action.run();
}
}
@@ -1135,7 +1135,7 @@ export class ChangeEOLAction extends Action {
super(actionId, actionLabel);
}
run(): Promise<any> {
async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1145,7 +1145,7 @@ export class ChangeEOLAction extends Action {
return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
}
const textModel = activeTextEditorWidget.getModel();
let textModel = activeTextEditorWidget.getModel();
const EOLOptions: IChangeEOLEntry[] = [
{ label: nlsEOLLF, eol: EndOfLineSequence.LF },
@@ -1154,15 +1154,14 @@ export class ChangeEOLAction extends Action {
const selectedIndex = (textModel && textModel.getEOL() === '\n') ? 0 : 1;
return this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] }).then(eol => {
if (eol) {
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) {
const textModel = activeCodeEditor.getModel();
textModel.pushEOL(eol.eol);
}
const eol = await this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] });
if (eol) {
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) {
textModel = activeCodeEditor.getModel();
textModel.pushEOL(eol.eol);
}
});
}
}
}

View File

@@ -567,16 +567,15 @@ class InlineImageView {
return context;
}
private static imageSrc(descriptor: IResourceDescriptor, textFileService: ITextFileService): Promise<string> {
private static async imageSrc(descriptor: IResourceDescriptor, textFileService: ITextFileService): Promise<string> {
if (descriptor.resource.scheme === Schemas.data) {
return Promise.resolve(descriptor.resource.toString(true /* skip encoding */));
}
return textFileService.read(descriptor.resource, { encoding: 'base64' }).then(data => {
const mime = getMime(descriptor);
const data = await textFileService.read(descriptor.resource, { encoding: 'base64' });
const mime = getMime(descriptor);
return `data:${mime};base64,${data.value}`;
});
return `data:${mime};base64,${data.value}`;
}
}

View File

@@ -93,10 +93,11 @@ export class SideBySideEditor extends BaseEditor {
this.updateStyles();
}
setInput(newInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
async setInput(newInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
const oldInput = this.input as SideBySideEditorInput;
return super.setInput(newInput, options, token)
.then(() => this.updateInput(oldInput, newInput as SideBySideEditorInput, options, token));
await super.setInput(newInput, options, token);
return this.updateInput(oldInput, (newInput as SideBySideEditorInput), options, token);
}
setOptions(options: EditorOptions): void {
@@ -158,7 +159,7 @@ export class SideBySideEditor extends BaseEditor {
return this.detailsEditor;
}
private updateInput(oldInput: SideBySideEditorInput, newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
private async updateInput(oldInput: SideBySideEditorInput, newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
if (!newInput.matches(oldInput)) {
if (oldInput) {
this.disposeEditors();
@@ -166,14 +167,15 @@ export class SideBySideEditor extends BaseEditor {
return this.setNewInput(newInput, options, token);
}
if (!this.detailsEditor || !this.masterEditor) {
return Promise.resolve();
}
return Promise.all([
await Promise.all([
this.detailsEditor.setInput(newInput.details, null, token),
this.masterEditor.setInput(newInput.master, options, token)]
).then(() => undefined);
this.masterEditor.setInput(newInput.master, options, token)
]);
}
private setNewInput(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
@@ -196,7 +198,7 @@ export class SideBySideEditor extends BaseEditor {
return editor;
}
private onEditorsCreated(details: BaseEditor, master: BaseEditor, detailsInput: EditorInput, masterInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
private async onEditorsCreated(details: BaseEditor, master: BaseEditor, detailsInput: EditorInput, masterInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
this.detailsEditor = details;
this.masterEditor = master;
@@ -207,7 +209,12 @@ export class SideBySideEditor extends BaseEditor {
this.onDidCreateEditors.fire(undefined);
return Promise.all([this.detailsEditor.setInput(detailsInput, null, token), this.masterEditor.setInput(masterInput, options, token)]).then(() => this.focus());
await Promise.all([
this.detailsEditor.setInput(detailsInput, null, token),
this.masterEditor.setInput(masterInput, options, token)]
);
return this.focus();
}
updateStyles(): void {

View File

@@ -84,7 +84,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration);
}
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
// Dispose previous diff navigator
this.diffNavigatorDisposables = dispose(this.diffNavigatorDisposables);
@@ -93,56 +93,55 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
this.saveTextDiffEditorViewState(this.input);
// Set input and resolve
return super.setInput(input, options, token).then(() => {
return input.resolve().then(resolvedModel => {
await super.setInput(input, options, token);
// Check for cancellation
if (token.isCancellationRequested) {
return undefined;
}
try {
const resolvedModel = await input.resolve();
// Assert Model Instance
if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) {
return undefined;
}
// Set Editor Model
const diffEditor = this.getControl();
const resolvedDiffEditorModel = <TextDiffEditorModel>resolvedModel;
diffEditor.setModel(resolvedDiffEditorModel.textDiffEditorModel);
// Apply Options from TextOptions
let optionsGotApplied = false;
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
optionsGotApplied = (<TextEditorOptions>options).apply(diffEditor, ScrollType.Immediate);
}
// Otherwise restore View State
let hasPreviousViewState = false;
if (!optionsGotApplied) {
hasPreviousViewState = this.restoreTextDiffEditorViewState(input);
}
// Diff navigator
this.diffNavigator = new DiffNavigator(diffEditor, {
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState // only reveal first change if we had no options or viewstate
});
this.diffNavigatorDisposables.push(this.diffNavigator);
// Readonly flag
diffEditor.updateOptions({ readOnly: resolvedDiffEditorModel.isReadonly() });
// Check for cancellation
if (token.isCancellationRequested) {
return undefined;
}, error => {
}
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
if (this.isFileBinaryError(error) && this.openAsBinary(input, options)) {
return null;
}
// Assert Model Instance
if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) {
return undefined;
}
// Otherwise make sure the error bubbles up
return Promise.reject(error);
// Set Editor Model
const diffEditor = this.getControl();
const resolvedDiffEditorModel = <TextDiffEditorModel>resolvedModel;
diffEditor.setModel(resolvedDiffEditorModel.textDiffEditorModel);
// Apply Options from TextOptions
let optionsGotApplied = false;
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
optionsGotApplied = (<TextEditorOptions>options).apply(diffEditor, ScrollType.Immediate);
}
// Otherwise restore View State
let hasPreviousViewState = false;
if (!optionsGotApplied) {
hasPreviousViewState = this.restoreTextDiffEditorViewState(input);
}
// Diff navigator
this.diffNavigator = new DiffNavigator(diffEditor, {
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState // only reveal first change if we had no options or viewstate
});
});
this.diffNavigatorDisposables.push(this.diffNavigator);
// Readonly flag
diffEditor.updateOptions({ readOnly: resolvedDiffEditorModel.isReadonly() });
} catch (error) {
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
if (this.isFileBinaryError(error) && this.openAsBinary(input, options)) {
return;
}
throw error;
}
}
setOptions(options: EditorOptions): void {

View File

@@ -191,14 +191,13 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, {});
}
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
return super.setInput(input, options, token).then(() => {
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
await super.setInput(input, options, token);
// Update editor options after having set the input. We do this because there can be
// editor input specific options (e.g. an ARIA label depending on the input showing)
this.updateEditorConfiguration();
this._editorContainer.setAttribute('aria-label', this.computeAriaLabel());
});
// Update editor options after having set the input. We do this because there can be
// editor input specific options (e.g. an ARIA label depending on the input showing)
this.updateEditorConfiguration();
this._editorContainer.setAttribute('aria-label', this.computeAriaLabel());
}
protected setEditorVisible(visible: boolean, group: IEditorGroup): void {

View File

@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { TextEditorOptions, EditorModel, EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { TextEditorOptions, EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
@@ -54,45 +54,41 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
return nls.localize('textEditor', "Text Editor");
}
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
// Remember view settings if input changes
this.saveTextResourceEditorViewState(this.input);
// Set input and resolve
return super.setInput(input, options, token).then(() => {
return input.resolve().then((resolvedModel: EditorModel) => {
await super.setInput(input, options, token);
const resolvedModel = await input.resolve();
// Check for cancellation
if (token.isCancellationRequested) {
return undefined;
}
// Check for cancellation
if (token.isCancellationRequested) {
return undefined;
}
// Assert Model instance
if (!(resolvedModel instanceof BaseTextEditorModel)) {
return Promise.reject(new Error('Unable to open file as text'));
}
// Assert Model instance
if (!(resolvedModel instanceof BaseTextEditorModel)) {
return Promise.reject(new Error('Unable to open file as text'));
}
// Set Editor Model
const textEditor = this.getControl();
const textEditorModel = resolvedModel.textEditorModel;
textEditor.setModel(textEditorModel);
// Set Editor Model
const textEditor = this.getControl();
const textEditorModel = resolvedModel.textEditorModel;
textEditor.setModel(textEditorModel);
// Apply Options from TextOptions
let optionsGotApplied = false;
const textOptions = <TextEditorOptions>options;
if (textOptions && types.isFunction(textOptions.apply)) {
optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate);
}
// Apply Options from TextOptions
let optionsGotApplied = false;
const textOptions = <TextEditorOptions>options;
if (textOptions && types.isFunction(textOptions.apply)) {
optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate);
}
// Otherwise restore View State
if (!optionsGotApplied) {
this.restoreTextResourceEditorViewState(input);
}
return undefined;
});
});
// Otherwise restore View State
if (!optionsGotApplied) {
this.restoreTextResourceEditorViewState(input);
}
}
private restoreTextResourceEditorViewState(input: EditorInput) {

View File

@@ -160,7 +160,7 @@ export class NotificationActionRunner extends ActionRunner {
super();
}
protected runAction(action: IAction, context: INotificationViewItem): Promise<any> {
protected async runAction(action: IAction, context: INotificationViewItem): Promise<any> {
/* __GDPR__
"workbenchActionExecuted" : {
@@ -171,8 +171,10 @@ export class NotificationActionRunner extends ActionRunner {
this.telemetryService.publicLog('workbenchActionExecuted', { id: action.id, from: 'message' });
// Run and make sure to notify on any error again
super.runAction(action, context).then(undefined, error => this.notificationService.error(error));
return Promise.resolve();
try {
await super.runAction(action, context);
} catch (error) {
this.notificationService.error(error);
}
}
}

View File

@@ -93,18 +93,17 @@ export class NotificationsToasts extends Themable {
});
}
private onCanShowNotifications(): Promise<void> {
private async onCanShowNotifications(): Promise<void> {
// Wait for the running phase to ensure we can draw notifications properly
return this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
await this.lifecycleService.when(LifecyclePhase.Ready);
// Push notificiations out until either workbench is restored
// or some time has ellapsed to reduce pressure on the startup
return Promise.race([
this.lifecycleService.when(LifecyclePhase.Restored),
timeout(2000)
]);
});
// Push notificiations out until either workbench is restored
// or some time has ellapsed to reduce pressure on the startup
return Promise.race([
this.lifecycleService.when(LifecyclePhase.Restored),
timeout(2000)
]);
}
private onDidNotificationChange(e: INotificationChangeEvent): void {

View File

@@ -259,8 +259,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
// Pass to handlers
for (let prefix in this.mapResolvedHandlersToPrefix) {
const promise = this.mapResolvedHandlersToPrefix[prefix];
promise.then(handler => {
this.mapResolvedHandlersToPrefix[prefix].then(handler => {
this.handlerOnOpenCalled[prefix] = false;
handler.onClose(reason === HideReason.CANCELED); // Don't check if onOpen was called to preserve old behaviour for now
@@ -429,7 +428,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
});
}
private handleDefaultHandler(handler: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
private async handleDefaultHandler(handler: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
// Fill in history results if matching and we are configured to search in history
let matchingHistoryEntries: QuickOpenEntry[];
@@ -444,47 +443,41 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
// Resolve
return this.resolveHandler(handler).then(resolvedHandler => {
const quickOpenModel = new QuickOpenModel(matchingHistoryEntries, this.actionProvider);
const resolvedHandler = await this.resolveHandler(handler);
let inputSet = false;
const quickOpenModel = new QuickOpenModel(matchingHistoryEntries, this.actionProvider);
// If we have matching entries from history we want to show them directly and not wait for the other results to come in
// This also applies when we used to have entries from a previous run and now there are no more history results matching
const previousInput = this.quickOpenWidget.getInput();
const wasShowingHistory = previousInput && previousInput.entries && previousInput.entries.some(e => e instanceof EditorHistoryEntry || e instanceof EditorHistoryEntryGroup);
if (wasShowingHistory || matchingHistoryEntries.length > 0) {
let responseDelay: Promise<void>;
if (resolvedHandler.hasShortResponseTime()) {
responseDelay = timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
} else {
responseDelay = Promise.resolve();
}
let inputSet = false;
responseDelay.then(() => {
if (!token.isCancellationRequested && !inputSet) {
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
inputSet = true;
}
});
// If we have matching entries from history we want to show them directly and not wait for the other results to come in
// This also applies when we used to have entries from a previous run and now there are no more history results matching
const previousInput = this.quickOpenWidget.getInput();
const wasShowingHistory = previousInput && previousInput.entries && previousInput.entries.some(e => e instanceof EditorHistoryEntry || e instanceof EditorHistoryEntryGroup);
if (wasShowingHistory || matchingHistoryEntries.length > 0) {
if (resolvedHandler.hasShortResponseTime()) {
await timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
}
// Get results
return resolvedHandler.getResults(value, token).then(result => {
if (!token.isCancellationRequested) {
if (!token.isCancellationRequested && !inputSet) {
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
inputSet = true;
}
}
// now is the time to show the input if we did not have set it before
if (!inputSet) {
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
inputSet = true;
}
// Get results
const result = await resolvedHandler.getResults(value, token);
if (!token.isCancellationRequested) {
// merge history and default handler results
const handlerResults = (result && result.entries) || [];
this.mergeResults(quickOpenModel, handlerResults, types.withNullAsUndefined(resolvedHandler.getGroupLabel()));
}
});
});
// now is the time to show the input if we did not have set it before
if (!inputSet) {
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
inputSet = true;
}
// merge history and default handler results
const handlerResults = (result && result.entries) || [];
this.mergeResults(quickOpenModel, handlerResults, types.withNullAsUndefined(resolvedHandler.getGroupLabel()));
}
}
private mergeResults(quickOpenModel: QuickOpenModel, handlerResults: QuickOpenEntry[], groupLabel: string | undefined): void {
@@ -516,46 +509,44 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
}
private handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
return this.resolveHandler(handlerDescriptor).then((resolvedHandler: QuickOpenHandler) => {
private async handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
const resolvedHandler = await this.resolveHandler(handlerDescriptor);
// Remove handler prefix from search value
value = value.substr(handlerDescriptor.prefix.length);
// Remove handler prefix from search value
value = value.substr(handlerDescriptor.prefix.length);
// Return early if the handler can not run in the current environment and inform the user
const canRun = resolvedHandler.canRun();
if (types.isUndefinedOrNull(canRun) || (typeof canRun === 'boolean' && !canRun) || typeof canRun === 'string') {
const placeHolderLabel = (typeof canRun === 'string') ? canRun : nls.localize('canNotRunPlaceholder', "This quick open handler can not be used in the current context");
// Return early if the handler can not run in the current environment and inform the user
const canRun = resolvedHandler.canRun();
if (types.isUndefinedOrNull(canRun) || (typeof canRun === 'boolean' && !canRun) || typeof canRun === 'string') {
const placeHolderLabel = (typeof canRun === 'string') ? canRun : nls.localize('canNotRunPlaceholder', "This quick open handler can not be used in the current context");
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(placeHolderLabel)], this.actionProvider);
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(placeHolderLabel)], this.actionProvider);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
return Promise.resolve(undefined);
}
// Support extra class from handler
const extraClass = resolvedHandler.getClass();
if (extraClass) {
this.quickOpenWidget.setExtraClass(extraClass);
}
// When handlers change, clear the result list first before loading the new results
if (this.previousActiveHandlerDescriptor !== handlerDescriptor) {
this.clearModel();
}
// Receive Results from Handler and apply
const result = await resolvedHandler.getResults(value, token);
if (!token.isCancellationRequested) {
if (!result || !result.entries.length) {
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(resolvedHandler.getEmptyLabel(value))]);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
return Promise.resolve(undefined);
} else {
this.showModel(result, resolvedHandler.getAutoFocus(value, { model: result, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
}
// Support extra class from handler
const extraClass = resolvedHandler.getClass();
if (extraClass) {
this.quickOpenWidget.setExtraClass(extraClass);
}
// When handlers change, clear the result list first before loading the new results
if (this.previousActiveHandlerDescriptor !== handlerDescriptor) {
this.clearModel();
}
// Receive Results from Handler and apply
return resolvedHandler.getResults(value, token).then(result => {
if (!token.isCancellationRequested) {
if (!result || !result.entries.length) {
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(resolvedHandler.getEmptyLabel(value))]);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
} else {
this.showModel(result, resolvedHandler.getAutoFocus(value, { model: result, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
}
}
});
});
}
}
private showModel(model: IModel<any>, autoFocus?: IAutoFocus, ariaLabel?: string): void {
@@ -837,7 +828,7 @@ export class RemoveFromEditorHistoryAction extends Action {
super(id, label);
}
run(): Promise<any> {
async run(): Promise<any> {
interface IHistoryPickEntry extends IQuickPickItem {
input: IEditorInput | IResourceInput;
}
@@ -854,11 +845,10 @@ export class RemoveFromEditorHistoryAction extends Action {
};
});
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), matchOnDescription: true }).then(pick => {
if (pick) {
this.historyService.remove(pick.input);
}
});
const pick = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), matchOnDescription: true });
if (pick) {
this.historyService.remove(pick.input);
}
}
}

View File

@@ -23,12 +23,10 @@ export const QUICKOPEN_ACION_LABEL = nls.localize('quickOpen', "Go to File...");
CommandsRegistry.registerCommand({
id: QUICKOPEN_ACTION_ID,
handler: function (accessor: ServicesAccessor, prefix: string | null = null) {
handler: async function (accessor: ServicesAccessor, prefix: string | null = null) {
const quickOpenService = accessor.get(IQuickOpenService);
return quickOpenService.show(typeof prefix === 'string' ? prefix : undefined).then(() => {
return undefined;
});
await quickOpenService.show(typeof prefix === 'string' ? prefix : undefined);
},
description: {
description: `Quick open`,
@@ -42,12 +40,10 @@ CommandsRegistry.registerCommand({
});
export const QUICKOPEN_FOCUS_SECONDARY_ACTION_ID = 'workbench.action.quickOpenPreviousEditor';
CommandsRegistry.registerCommand(QUICKOPEN_FOCUS_SECONDARY_ACTION_ID, function (accessor: ServicesAccessor, prefix: string | null = null) {
CommandsRegistry.registerCommand(QUICKOPEN_FOCUS_SECONDARY_ACTION_ID, async function (accessor: ServicesAccessor, prefix: string | null = null) {
const quickOpenService = accessor.get(IQuickOpenService);
return quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } }).then(() => {
return undefined;
});
await quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } });
});
export class BaseQuickOpenNavigateAction extends Action {

View File

@@ -189,19 +189,18 @@ export class SidebarPart extends CompositePart<Viewlet> implements IViewletServi
this.hideActiveComposite();
}
openViewlet(id: string | undefined, focus?: boolean): Promise<IViewlet | null> {
async openViewlet(id: string | undefined, focus?: boolean): Promise<IViewlet | null> {
if (typeof id === 'string' && this.getViewlet(id)) {
return Promise.resolve(this.doOpenViewlet(id, focus));
}
return this.extensionService.whenInstalledExtensionsRegistered()
.then(() => {
if (typeof id === 'string' && this.getViewlet(id)) {
return this.doOpenViewlet(id, focus);
}
await this.extensionService.whenInstalledExtensionsRegistered();
return null;
});
if (typeof id === 'string' && this.getViewlet(id)) {
return this.doOpenViewlet(id, focus);
}
return null;
}
getViewlets(): ViewletDescriptor[] {

View File

@@ -382,7 +382,7 @@ class StatusBarEntryItem extends Disposable {
}
}
private executeCommand(id: string, args?: unknown[]) {
private async executeCommand(id: string, args?: unknown[]): Promise<void> {
args = args || [];
// Maintain old behaviour of always focusing the editor here
@@ -398,7 +398,11 @@ class StatusBarEntryItem extends Disposable {
}
*/
this.telemetryService.publicLog('workbenchActionExecuted', { id, from: 'status bar' });
this.commandService.executeCommand(id, ...args).then(undefined, err => this.notificationService.error(toErrorMessage(err)));
try {
await this.commandService.executeCommand(id, ...args);
} catch (error) {
this.notificationService.error(toErrorMessage(error));
}
}
dispose(): void {

View File

@@ -391,14 +391,13 @@ export class TitlebarPart extends Part implements ITitleService {
const restoreIconContainer = append(this.windowControls, $('div.window-icon-bg'));
this.maxRestoreControl = append(restoreIconContainer, $('div.window-icon'));
addClass(this.maxRestoreControl, 'window-max-restore');
this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, e => {
this.windowService.isMaximized().then((maximized) => {
if (maximized) {
return this.windowService.unmaximizeWindow();
}
this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, async e => {
const maximized = await this.windowService.isMaximized();
if (maximized) {
return this.windowService.unmaximizeWindow();
}
return this.windowService.maximizeWindow();
});
return this.windowService.maximizeWindow();
}));
// Close

View File

@@ -251,15 +251,13 @@ export class CustomTreeView extends Disposable implements ITreeView {
set dataProvider(dataProvider: ITreeViewDataProvider | null) {
if (dataProvider) {
this._dataProvider = new class implements ITreeViewDataProvider {
getChildren(node: ITreeItem): Promise<ITreeItem[]> {
async getChildren(node: ITreeItem): Promise<ITreeItem[]> {
if (node && node.children) {
return Promise.resolve(node.children);
}
const promise = node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node);
return promise.then(children => {
node.children = children;
return children;
});
const children = await (node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node));
node.children = children;
return children;
}
};
this.updateMessage();
@@ -524,19 +522,16 @@ export class CustomTreeView extends Disposable implements ITreeView {
}
private refreshing: boolean = false;
private doRefresh(elements: ITreeItem[]): Promise<void> {
private async doRefresh(elements: ITreeItem[]): Promise<void> {
if (this.tree) {
this.refreshing = true;
return Promise.all(elements.map(e => this.tree.refresh(e)))
.then(() => {
this.refreshing = false;
this.updateContentAreas();
if (this.focused) {
this.focus();
}
});
await Promise.all(elements.map(e => this.tree.refresh(e)));
this.refreshing = false;
this.updateContentAreas();
if (this.focused) {
this.focus();
}
}
return Promise.resolve(undefined);
}
private updateContentAreas(): void {

View File

@@ -618,21 +618,19 @@ export class ViewsService extends Disposable implements IViewsService {
return viewDescriptorCollectionItem ? viewDescriptorCollectionItem.viewDescriptorCollection : null;
}
openView(id: string, focus: boolean): Promise<IView | null> {
async openView(id: string, focus: boolean): Promise<IView | null> {
const viewContainer = Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).getViewContainer(id);
if (viewContainer) {
const viewletDescriptor = this.viewletService.getViewlet(viewContainer.id);
if (viewletDescriptor) {
return this.viewletService.openViewlet(viewletDescriptor.id, focus)
.then((viewlet: IViewsViewlet) => {
if (viewlet && viewlet.openView) {
return viewlet.openView(id, focus);
}
return null;
});
const viewlet = await this.viewletService.openViewlet(viewletDescriptor.id, focus) as IViewsViewlet | null;
if (viewlet && viewlet.openView) {
return viewlet.openView(id, focus);
}
}
}
return Promise.resolve(null);
return null;
}
private onDidRegisterViewContainer(viewContainer: ViewContainer): void {
@@ -669,7 +667,7 @@ export class ViewsService extends Disposable implements IViewsService {
};
const when = ContextKeyExpr.has(`${viewDescriptor.id}.active`);
disposables.push(CommandsRegistry.registerCommand(command.id, () => this.openView(viewDescriptor.id, true).then(() => null)));
disposables.push(CommandsRegistry.registerCommand(command.id, () => this.openView(viewDescriptor.id, true)));
disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command,

View File

@@ -26,28 +26,27 @@ class CodeRendererMain extends Disposable {
private workbench: Workbench;
open(): Promise<void> {
async open(): Promise<void> {
const services = this.initServices();
return domContentLoaded().then(() => {
mark('willStartWorkbench');
await domContentLoaded();
mark('willStartWorkbench');
// Create Workbench
this.workbench = new Workbench(
document.body,
services.serviceCollection,
services.logService
);
// Create Workbench
this.workbench = new Workbench(
document.body,
services.serviceCollection,
services.logService
);
// Layout
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
// Layout
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
// Workbench Lifecycle
this._register(this.workbench.onShutdown(() => this.dispose()));
// Workbench Lifecycle
this._register(this.workbench.onShutdown(() => this.dispose()));
// Startup
this.workbench.startup();
});
// Startup
this.workbench.startup();
}
private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } {

View File

@@ -131,7 +131,7 @@ export class Workbench extends Layout {
// Services
const instantiationService = this.initServices(this.serviceCollection);
instantiationService.invokeFunction(accessor => {
instantiationService.invokeFunction(async accessor => {
const lifecycleService = accessor.get(ILifecycleService);
const storageService = accessor.get(IStorageService);
const configurationService = accessor.get(IConfigurationService);
@@ -158,7 +158,11 @@ export class Workbench extends Layout {
this.layout();
// Restore
this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService).then(undefined, error => onUnexpectedError(error));
try {
await this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService);
} catch (error) {
onUnexpectedError(error);
}
});
return instantiationService;
@@ -338,7 +342,7 @@ export class Workbench extends Layout {
registerNotificationCommands(notificationsCenter, notificationsToasts);
}
private restoreWorkbench(
private async restoreWorkbench(
editorService: IEditorService,
editorGroupService: IEditorGroupsService,
viewletService: IViewletService,
@@ -349,36 +353,39 @@ export class Workbench extends Layout {
const restorePromises: Promise<void>[] = [];
// Restore editors
mark('willRestoreEditors');
restorePromises.push(editorGroupService.whenRestored.then(() => {
restorePromises.push((async () => {
mark('willRestoreEditors');
function openEditors(editors: IResourceEditor[], editorService: IEditorService) {
if (editors.length) {
return editorService.openEditors(editors);
}
return Promise.resolve(undefined);
}
// first ensure the editor part is restored
await editorGroupService.whenRestored;
// then see for editors to open as instructed
let editors: IResourceEditor[];
if (Array.isArray(this.state.editor.editorsToOpen)) {
return openEditors(this.state.editor.editorsToOpen, editorService);
editors = this.state.editor.editorsToOpen;
} else {
editors = await this.state.editor.editorsToOpen;
}
return this.state.editor.editorsToOpen.then(editors => openEditors(editors, editorService));
}).then(() => mark('didRestoreEditors')));
if (editors.length) {
await editorService.openEditors(editors);
}
mark('didRestoreEditors');
})());
// Restore Sidebar
if (this.state.sideBar.viewletToRestore) {
mark('willRestoreViewlet');
restorePromises.push(viewletService.openViewlet(this.state.sideBar.viewletToRestore)
.then(viewlet => {
if (!viewlet) {
return viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
restorePromises.push((async () => {
mark('willRestoreViewlet');
return viewlet;
})
.then(() => mark('didRestoreViewlet')));
const viewlet = await viewletService.openViewlet(this.state.sideBar.viewletToRestore);
if (!viewlet) {
await viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
mark('didRestoreViewlet');
})());
}
// Restore Panel
@@ -401,23 +408,24 @@ export class Workbench extends Layout {
// Emit a warning after 10s if restore does not complete
const restoreTimeoutHandle = setTimeout(() => logService.warn('Workbench did not finish loading in 10 seconds, that might be a problem that should be reported.'), 10000);
return Promise.all(restorePromises)
.then(() => clearTimeout(restoreTimeoutHandle))
.catch(error => onUnexpectedError(error))
.finally(() => {
try {
await Promise.all(restorePromises);
// Set lifecycle phase to `Restored`
lifecycleService.phase = LifecyclePhase.Restored;
clearTimeout(restoreTimeoutHandle);
} catch (error) {
onUnexpectedError(error);
} finally {
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
setTimeout(() => {
this._register(runWhenIdle(() => {
lifecycleService.phase = LifecyclePhase.Eventually;
}, 2500));
}, 2500);
// Set lifecycle phase to `Restored`
lifecycleService.phase = LifecyclePhase.Restored;
// Telemetry: startup metrics
mark('didStartWorkbench');
});
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
setTimeout(() => {
this._register(runWhenIdle(() => lifecycleService.phase = LifecyclePhase.Eventually, 2500));
}, 2500);
// Telemetry: startup metrics
mark('didStartWorkbench');
}
}
}