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:
commit
f72b001b23
|
@ -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();
|
||||
|
|
16
tests/cases/fourslash/completionListInImportClause03.ts
Normal file
16
tests/cases/fourslash/completionListInImportClause03.ts
Normal 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();
|
15
tests/cases/fourslash/tsxCompletion5.ts
Normal file
15
tests/cases/fourslash/tsxCompletion5.ts
Normal 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();
|
Loading…
Reference in a new issue