Merge pull request #3807 from Microsoft/importSpecifierFilteringForCurrentName

Don't filter out current import specifier names/JSX attributes from completion lists
This commit is contained in:
Daniel Rosenwasser 2015-07-10 10:01:35 -07:00
commit f72b001b23
3 changed files with 57 additions and 15 deletions

View file

@ -3463,6 +3463,11 @@ namespace ts {
importDeclaration.importClause.namedBindings.kind === SyntaxKind.NamedImports) {
forEach((<NamedImports>importDeclaration.importClause.namedBindings).elements, el => {
// If this is the current item we are editing right now, do not filter it out
if (el.getStart() <= position && position <= el.getEnd()) {
return;
}
let name = el.propertyName || el.name;
exisingImports[name.text] = true;
});
@ -3517,23 +3522,29 @@ namespace ts {
return filteredMembers;
}
function filterJsxAttributes(attributes: NodeArray<JsxAttribute | JsxSpreadAttribute>, symbols: Symbol[]): Symbol[] {
let seenNames: Map<boolean> = {};
for (let attr of attributes) {
// If this is the current item we are editing right now, do not filter it out
if (attr.getStart() <= position && position <= attr.getEnd()) {
continue;
}
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 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();

View file

@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
////declare module "M1" {
//// export var abc: number;
//// export var def: string;
////}
////
////declare module "M2" {
//// import { abc/**/ } from "M1";
////}
// Ensure we don't filter out the current item.
goTo.marker();
verify.completionListContains("abc");
verify.completionListContains("def");
verify.not.completionListAllowsNewIdentifier();

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
//@Filename: file.tsx
//// declare module JSX {
//// interface Element { }
//// interface IntrinsicElements {
//// div: { ONE: string; TWO: number; }
//// }
//// }
//// var x = <div ONE/**//>;
goTo.marker();
verify.completionListContains("ONE");
verify.completionListContains("TWO");
verify.not.completionListAllowsNewIdentifier();