diff --git a/extensions/typescript-language-features/src/test/completions.test.ts b/extensions/typescript-language-features/src/test/completions.test.ts index 6875e882f60..f00fbb530f2 100644 --- a/extensions/typescript-language-features/src/test/completions.test.ts +++ b/extensions/typescript-language-features/src/test/completions.test.ts @@ -267,7 +267,7 @@ suite('TypeScript Completions', () => { )); }); - test('should not de-prioritize this.member suggestion, #74164', async () => { + test('should not de-prioritize `this.member` suggestion, #74164', async () => { await enumerateConfig(Config.insertMode, insertModes, async config => { await createTestEditor(testDocumentUri, `class A {`, @@ -293,6 +293,32 @@ suite('TypeScript Completions', () => { }); }); + test('Member completions for string properties should insert `this.` and use brackets', async () => { + await enumerateConfig(Config.insertMode, insertModes, async config => { + await createTestEditor(testDocumentUri, + `class A {`, + ` ['xyz 123'] = 1`, + ` foo() {`, + ` xyz$0`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class A {`, + ` ['xyz 123'] = 1`, + ` foo() {`, + ` this["xyz 123"]`, + ` }`, + `}`, + ), + `Config: ${config}`); + }); + }); + test('Accepting a completion in word using insert mode should insert', async () => { await updateConfig({ [Config.insertMode]: 'insert' }); @@ -327,6 +353,56 @@ suite('TypeScript Completions', () => { )); }); + test('Accepting a member completion in word using insert mode add `this.` and insert', async () => { + await updateConfig({ [Config.insertMode]: 'insert' }); + + await createTestEditor(testDocumentUri, + `class Foo {`, + ` abc = 1;`, + ` foo() {`, + ` ab$0c`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class Foo {`, + ` abc = 1;`, + ` foo() {`, + ` this.abcc`, + ` }`, + `}`, + )); + }); + + test('Accepting a member completion in word using replace mode should add `this.` and replace', async () => { + await updateConfig({ [Config.insertMode]: 'replace' }); + + await createTestEditor(testDocumentUri, + `class Foo {`, + ` abc = 1;`, + ` foo() {`, + ` ab$0c`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class Foo {`, + ` abc = 1;`, + ` foo() {`, + ` this.abc`, + ` }`, + `}`, + )); + }); + test('Accepting string completion inside string using insert mode should insert', async () => { await updateConfig({ [Config.insertMode]: 'insert' });