提交 b513141f 编写于 作者: J Johannes Rieken

resolve completion item before inserting (except when using commit characters), #73311

上级 72b2139a
......@@ -33,6 +33,7 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ
import { IdleValue } from 'vs/base/common/async';
import { isObject } from 'vs/base/common/types';
import { CommitCharacterController } from './suggestCommitCharacters';
import { CancellationToken } from 'vs/base/common/cancellation';
export class SuggestController implements IEditorContribution {
......@@ -64,10 +65,14 @@ export class SuggestController implements IEditorContribution {
const widget = this._instantiationService.createInstance(SuggestWidget, this._editor);
this._toDispose.push(widget);
this._toDispose.push(widget.onDidSelect(item => this._onDidSelectItem(item, false, true), this));
this._toDispose.push(widget.onDidSelect(item => this._insertSuggestion(item, false, true), this));
// Wire up logic to accept a suggestion on certain characters
const commitCharacterController = new CommitCharacterController(this._editor, widget, item => this._onDidSelectItem(item, false, true));
const commitCharacterController = new CommitCharacterController(
this._editor,
widget,
item => this._insertSuggestion(item, false, true, true)
);
this._toDispose.push(
commitCharacterController,
this._model.onDidSuggest(e => {
......@@ -161,12 +166,23 @@ export class SuggestController implements IEditorContribution {
}
}
protected _onDidSelectItem(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStops: boolean): void {
protected _insertSuggestion(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStops: boolean): Promise<void>;
protected _insertSuggestion(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStops: boolean, noResolve: true): void;
protected async _insertSuggestion(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStops: boolean, noResolve?: true): Promise<void> {
if (!event || !event.item) {
this._alternatives.getValue().reset();
this._model.cancel();
return;
}
if (!noResolve) {
// DEFAULT is to wait for the item to be resolve
// but the current implementation of commit characters
// doesn't allow to wait and that's why there is a
// sync (no resolve) case
await event.item.resolve(CancellationToken.None);
}
if (!this._editor.hasModel()) {
return;
}
......@@ -233,7 +249,7 @@ export class SuggestController implements IEditorContribution {
if (modelVersionNow !== model.getAlternativeVersionId()) {
model.undo();
}
this._onDidSelectItem(next, false, false);
this._insertSuggestion(next, false, false);
break;
}
});
......@@ -315,7 +331,7 @@ export class SuggestController implements IEditorContribution {
return;
}
this._editor.pushUndoStop();
this._onDidSelectItem({ index, item, model: completionModel }, true, false);
this._insertSuggestion({ index, item, model: completionModel }, true, false);
}, undefined, listener);
});
......@@ -327,7 +343,7 @@ export class SuggestController implements IEditorContribution {
acceptSelectedSuggestion(keepAlternativeSuggestions?: boolean): void {
const item = this._widget.getValue().getFocusedItem();
this._onDidSelectItem(item, !!keepAlternativeSuggestions, true);
this._insertSuggestion(item, !!keepAlternativeSuggestions, true);
}
acceptNextSuggestion() {
......
......@@ -30,7 +30,6 @@ import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { CompletionItemKind, completionKindToCssClass } from 'vs/editor/common/modes';
import { IconLabel, IIconLabelValueOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
......@@ -545,10 +544,8 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<Compl
return;
}
item.resolve(CancellationToken.None).then(() => {
this.onDidSelectEmitter.fire({ item, index, model: completionModel });
this.editor.focus();
});
this.onDidSelectEmitter.fire({ item, index, model: completionModel });
this.editor.focus();
}
private _getSuggestionAriaAlertLabel(item: CompletionItem): string {
......
......@@ -671,8 +671,8 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
return withOracle(async (sugget, editor) => {
class TestCtrl extends SuggestController {
_onDidSelectItem(item: ISelectedSuggestion) {
super._onDidSelectItem(item, false, true);
_insertSuggestion(item: ISelectedSuggestion) {
return super._insertSuggestion(item, false, true);
}
}
const ctrl = <TestCtrl>editor.registerAndInstantiateContribution(TestCtrl);
......@@ -687,7 +687,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
const [first] = event.completionModel.items;
assert.equal(first.completion.label, 'bar');
ctrl._onDidSelectItem({ item: first, index: 0, model: event.completionModel });
return ctrl._insertSuggestion({ item: first, index: 0, model: event.completionModel });
});
assert.equal(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册