diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 5fd2af1ffd8..29456c89258 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -455,16 +455,12 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I get terminals() { return extHostTerminalService.terminals; }, - showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): Thenable { - let documentPromise: Promise; - if (URI.isUri(documentOrUri)) { - documentPromise = Promise.resolve(workspace.openTextDocument(documentOrUri)); - } else { - documentPromise = Promise.resolve(documentOrUri); - } - return documentPromise.then(document => { - return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus); - }); + async showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): Promise { + const document = await (URI.isUri(documentOrUri) + ? Promise.resolve(workspace.openTextDocument(documentOrUri)) + : Promise.resolve(documentOrUri)); + + return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus); }, createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType { return extHostEditors.createTextEditorDecorationType(options); diff --git a/src/vs/workbench/api/common/extHostTextEditors.ts b/src/vs/workbench/api/common/extHostTextEditors.ts index 4a61bf07536..e99f513e940 100644 --- a/src/vs/workbench/api/common/extHostTextEditors.ts +++ b/src/vs/workbench/api/common/extHostTextEditors.ts @@ -54,7 +54,7 @@ export class ExtHostEditors implements ExtHostEditorsShape { showTextDocument(document: vscode.TextDocument, column: vscode.ViewColumn, preserveFocus: boolean): Promise; showTextDocument(document: vscode.TextDocument, options: { column: vscode.ViewColumn, preserveFocus: boolean, pinned: boolean }): Promise; showTextDocument(document: vscode.TextDocument, columnOrOptions: vscode.ViewColumn | vscode.TextDocumentShowOptions | undefined, preserveFocus?: boolean): Promise; - showTextDocument(document: vscode.TextDocument, columnOrOptions: vscode.ViewColumn | vscode.TextDocumentShowOptions | undefined, preserveFocus?: boolean): Promise { + async showTextDocument(document: vscode.TextDocument, columnOrOptions: vscode.ViewColumn | vscode.TextDocumentShowOptions | undefined, preserveFocus?: boolean): Promise { let options: ITextDocumentShowOptions; if (typeof columnOrOptions === 'number') { options = { @@ -74,14 +74,18 @@ export class ExtHostEditors implements ExtHostEditorsShape { }; } - return this._proxy.$tryShowTextDocument(document.uri, options).then(id => { - const editor = id && this._extHostDocumentsAndEditors.getEditor(id); - if (editor) { - return editor; - } else { - throw new Error(`Failed to show text document ${document.uri.toString()}, should show in editor #${id}`); - } - }); + const editorId = await this._proxy.$tryShowTextDocument(document.uri, options); + const editor = editorId && this._extHostDocumentsAndEditors.getEditor(editorId); + if (editor) { + return editor; + } + // we have no editor... having an id means that we had an editor + // on the main side and that it isn't the current editor anymore... + if (editorId) { + throw new Error(`Could NOT open editor for "${document.uri.toString()}" because another editor opened in the meantime.`); + } else { + throw new Error(`Could NOT open editor for "${document.uri.toString()}".`); + } } createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {