mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Filter out would-be-duplicate names from JSX attribute completion
This commit is contained in:
@@ -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(<JsxSelfClosingElement>jsxContainer);
|
||||
}
|
||||
else if(jsxContainer.kind === SyntaxKind.JsxOpeningElement) {
|
||||
// Cursor is inside a JSX element
|
||||
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningElement>jsxContainer);
|
||||
}
|
||||
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
|
||||
// Cursor is inside a JSX self-closing element or opening element
|
||||
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningLikeElement>jsxContainer);
|
||||
|
||||
if (attrsType) {
|
||||
symbols = filterJsxAttributes((<JsxOpeningLikeElement>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<JsxAttribute|JsxSpreadAttribute>, symbols: Symbol[]): Symbol[] {
|
||||
let seenNames: Map<boolean> = {};
|
||||
for(let attr of attributes) {
|
||||
if(attr.kind === SyntaxKind.JsxAttribute) {
|
||||
seenNames[(<JsxAttribute>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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user