diff --git a/src/services/services.ts b/src/services/services.ts index c193b53582b..395bd41ac92 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3062,20 +3062,17 @@ namespace ts { } else if(jsxContainer) { let attrsType: Type; - if (jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) { - // Cursor is inside a JSX self-closing element - attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); - } - else if(jsxContainer.kind === SyntaxKind.JsxOpeningElement) { - // Cursor is inside a JSX element - attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); - } + if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) { + // Cursor is inside a JSX self-closing element or opening element + attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); + + if (attrsType) { + symbols = filterJsxAttributes((jsxContainer).attributes, typeChecker.getPropertiesOfType(attrsType)); + isMemberCompletion = true; + isNewIdentifierLocation = false; + return true; + } - if (attrsType) { - symbols = typeChecker.getPropertiesOfType(attrsType); - isMemberCompletion = true; - isNewIdentifierLocation = false; - return true; } } @@ -3476,6 +3473,22 @@ namespace ts { } } + function filterJsxAttributes(attributes: NodeArray, symbols: Symbol[]): Symbol[] { + let seenNames: Map = {}; + for(let attr of attributes) { + if(attr.kind === SyntaxKind.JsxAttribute) { + seenNames[(attr).name.text] = true; + } + } + let result: Symbol[] = []; + for(let sym of symbols) { + if(!seenNames[sym.name]) { + result.push(sym); + } + } + return result; + } + function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { synchronizeHostData(); diff --git a/tests/cases/fourslash/tsxCompletion3.ts b/tests/cases/fourslash/tsxCompletion3.ts index 2d87d7ed056..5ee712f7e96 100644 --- a/tests/cases/fourslash/tsxCompletion3.ts +++ b/tests/cases/fourslash/tsxCompletion3.ts @@ -11,3 +11,4 @@ goTo.marker(); verify.completionListContains('two'); +verify.not.completionListContains('one');