diff --git a/src/vs/editor/contrib/suggest/suggestController.ts b/src/vs/editor/contrib/suggest/suggestController.ts index ac65ff1abd4d75c321c5d6b04465337786e3b80c..7d7013aaa1a459f5458576d057145409d3d42cd4 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 264040790bbb4e440ac9e4f24a8b6b851c977e6c..d0c081f90a5c953b2b2bfac894328301d5a40684 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"' + ); + }); + }); });