From 1f32fef5a2e9cfdcd95a2628816c26fed7e633e4 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 9 Dec 2022 18:38:08 +0200 Subject: [PATCH] fix(51077): skip insertText for jsx attribute with existing initializer (#51093) --- src/services/completions.ts | 4 ++- ...ameCompletionWithExistingJsxInitializer.ts | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/jsxTagNameCompletionWithExistingJsxInitializer.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 210524b95dd..ef0be7f0fd6 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1392,7 +1392,9 @@ function createCompletionEntry( sortText = SortText.SortBelow(sortText); } - if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") { + if (isJsxIdentifierExpected && !isRightOfOpenTag + && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle + && preferences.jsxAttributeCompletionStyle !== "none" && !(isJsxAttribute(location.parent) && location.parent.initializer)) { let useBraces = preferences.jsxAttributeCompletionStyle === "braces"; const type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); diff --git a/tests/cases/fourslash/jsxTagNameCompletionWithExistingJsxInitializer.ts b/tests/cases/fourslash/jsxTagNameCompletionWithExistingJsxInitializer.ts new file mode 100644 index 00000000000..49e9fa6373c --- /dev/null +++ b/tests/cases/fourslash/jsxTagNameCompletionWithExistingJsxInitializer.ts @@ -0,0 +1,27 @@ +/// + +// @filename: /foo.tsx +////declare namespace JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// foo: { +//// className: string; +//// } +//// } +////} +//// + +verify.completions({ + marker: "", + includes: { + name: "className", + text: "(property) className: string", + insertText: undefined, + isSnippet: undefined, + }, + preferences: { + jsxAttributeCompletionStyle: "braces", + includeCompletionsWithSnippetText: true, + includeCompletionsWithInsertText: true, + }, +})