diff --git a/src/services/services.ts b/src/services/services.ts index 3f656fe75ff..94a3345af1f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3463,6 +3463,11 @@ namespace ts { importDeclaration.importClause.namedBindings.kind === SyntaxKind.NamedImports) { forEach((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, symbols: Symbol[]): Symbol[] { + let seenNames: Map = {}; + 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[(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, 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/completionListInImportClause03.ts b/tests/cases/fourslash/completionListInImportClause03.ts new file mode 100644 index 00000000000..7461c83022b --- /dev/null +++ b/tests/cases/fourslash/completionListInImportClause03.ts @@ -0,0 +1,16 @@ +/// + +////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(); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxCompletion5.ts b/tests/cases/fourslash/tsxCompletion5.ts new file mode 100644 index 00000000000..2de6d9a4132 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion5.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x =
; + +goTo.marker(); +verify.completionListContains("ONE"); +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier(); \ No newline at end of file