diff --git a/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts b/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts index 36f2d0e6eb1..305635d8524 100644 --- a/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts +++ b/src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts @@ -59,7 +59,7 @@ export class DefinitionAction extends EditorAction { const model = editor.getModel(); const pos = editor.getPosition(); - const definitionPromise = this._getTargetLocationForPosition(model, pos, CancellationToken.None).then(references => { + const definitionPromise = this._getTargetLocationForPosition(model, pos, CancellationToken.None).then(async references => { if (model.isDisposed() || editor.getModel() !== model) { // new model, no more model @@ -98,11 +98,11 @@ export class DefinitionAction extends EditorAction { } else if (result.length === 1 && idxOfCurrent !== -1) { // only the position at which we are -> adjust selection let [current] = result; - this._openReference(editor, editorService, current, false); + return this._openReference(editor, editorService, current, false).then(() => undefined); } else { // handle multile results - this._onResult(editorService, editor, new ReferencesModel(result)); + return this._onResult(editorService, editor, new ReferencesModel(result)); } }, (err) => { @@ -128,7 +128,7 @@ export class DefinitionAction extends EditorAction { return model.references.length > 1 && nls.localize('meta.title', " – {0} definitions", model.references.length); } - private _onResult(editorService: ICodeEditorService, editor: ICodeEditor, model: ReferencesModel) { + private async _onResult(editorService: ICodeEditorService, editor: ICodeEditor, model: ReferencesModel): Promise { const msg = model.getAriaMessage(); alert(msg); @@ -136,14 +136,13 @@ export class DefinitionAction extends EditorAction { if (this._configuration.openInPeek) { this._openInPeek(editorService, editor, model); } else { - let next = model.nearestReference(editor.getModel().uri, editor.getPosition()); - this._openReference(editor, editorService, next, this._configuration.openToSide).then(editor => { - if (editor && model.references.length > 1) { - this._openInPeek(editorService, editor, model); - } else { - model.dispose(); - } - }); + const next = model.nearestReference(editor.getModel().uri, editor.getPosition()); + const targetEditor = await this._openReference(editor, editorService, next, this._configuration.openToSide); + if (targetEditor && model.references.length > 1) { + this._openInPeek(editorService, targetEditor, model); + } else { + model.dispose(); + } } }