From ec87b2b666267a3763045c7201792543b61f1a1f Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 11 Dec 2017 10:35:38 +0100 Subject: [PATCH] add unit-test for #39893 --- .../contrib/suggest/suggestController.ts | 2 +- .../contrib/suggest/test/suggestModel.test.ts | 58 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index ac65ff1abd4..7d7013aaa1a 100644 --- a/src/vs/editor/contrib/suggest/suggestController.ts +++ b/src/vs/editor/contrib/suggest/suggestController.ts @@ -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; diff --git a/src/vs/editor/contrib/suggest/test/suggestModel.test.ts b/src/vs/editor/contrib/suggest/test/suggestModel.test.ts index 264040790bb..d0c081f90a5 100644 --- a/src/vs/editor/contrib/suggest/test/suggestModel.test.ts +++ b/src/vs/editor/contrib/suggest/test/suggestModel.test.ts @@ -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 { + function withOracle(callback: (model: SuggestModel, editor: TestCodeEditor) => any): TPromise { 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 = 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"' + ); + }); + }); }); -- GitLab