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

add unit-test for #39893

上级 3155771c
......@@ -193,7 +193,7 @@ export class SuggestController implements IEditorContribution {
}
}
private _onDidSelectItem(item: ICompletionItem): void {
protected _onDidSelectItem(item: ICompletionItem): void {
if (!item) {
this._model.cancel();
return;
......
......@@ -22,15 +22,18 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
import { IStorageService, NullStorageService } from 'vs/platform/storage/common/storage';
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
function createMockEditor(model: Model): TestCodeEditor {
const contextKeyService = new MockContextKeyService();
const telemetryService = NullTelemetryService;
const instantiationService = new InstantiationService(new ServiceCollection(
[IContextKeyService, contextKeyService],
[ITelemetryService, telemetryService]
[ITelemetryService, telemetryService],
[IStorageService, NullStorageService]
));
const editor = new TestCodeEditor(new MockScopeLocation(), {}, instantiationService, contextKeyService);
......@@ -102,7 +105,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
disposables.push(model);
});
function withOracle(callback: (model: SuggestModel, editor: ICodeEditor) => any): TPromise<any> {
function withOracle(callback: (model: SuggestModel, editor: TestCodeEditor) => any): TPromise<any> {
return new TPromise((resolve, reject) => {
const editor = createMockEditor(model);
......@@ -564,4 +567,53 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
});
});
});
test('Text changes for completion CodeAction are affected by the completion #39893', function () {
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
provideCompletionItems(doc, pos): ISuggestResult {
return {
incomplete: true,
suggestions: [{
label: 'bar',
type: 'property',
insertText: 'bar',
overwriteBefore: 2,
additionalTextEdits: [{
text: ', bar',
range: { startLineNumber: 1, endLineNumber: 1, startColumn: 17, endColumn: 17 }
}]
}]
};
}
}));
model.setValue('ba; import { foo } from "./b"');
return withOracle(async (sugget, editor) => {
class TestCtrl extends SuggestController {
_onDidSelectItem(item) {
super._onDidSelectItem(item);
}
}
const ctrl = <TestCtrl>editor.registerAndInstantiateContribution(TestCtrl);
editor.registerAndInstantiateContribution(SnippetController2);
await assertEvent(sugget.onDidSuggest, () => {
editor.setPosition({ lineNumber: 1, column: 3 });
sugget.trigger({ auto: false });
}, event => {
assert.equal(event.completionModel.items.length, 1);
const [first] = event.completionModel.items;
assert.equal(first.suggestion.label, 'bar');
ctrl._onDidSelectItem(first);
});
assert.equal(
model.getValue(),
'bar; import { foo, bar } from "./b"'
);
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册