diff --git a/src/services/services.ts b/src/services/services.ts index bd77b2d5c0d..f83202df864 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1810,13 +1810,21 @@ module ts { } /// Completion - function getValidCompletionEntryDisplayName(displayName: string, target: ScriptTarget): string { + function getValidCompletionEntryDisplayName(symbol: Symbol, target: ScriptTarget): string { + var displayName = symbol.getName(); if (displayName && displayName.length > 0) { var firstCharCode = displayName.charCodeAt(0); + // First check of the displayName is not external module; if it is an external module, it is not valid entry + if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the symbol is external module, don't show it in the completion list + // (i.e declare module "http" { var x; } | // <= request completion here, "http" should not be there) + return undefined; + } + if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an - // invalid identifer name. We need to check if whatever was inside the quotes is actually a valid identifier name. + // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. displayName = displayName.substring(1, displayName.length - 1); } @@ -1825,6 +1833,7 @@ module ts { isValid = isIdentifierPart(displayName.charCodeAt(i), target); } + if (isValid) { return displayName; } @@ -1837,7 +1846,7 @@ module ts { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) - var displayName = getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target); + var displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target); if (!displayName) { return undefined; } diff --git a/tests/cases/fourslash/completionListWithAmbientDeclaration.ts b/tests/cases/fourslash/completionListWithAmbientDeclaration.ts new file mode 100644 index 00000000000..afb5d96fbb7 --- /dev/null +++ b/tests/cases/fourslash/completionListWithAmbientDeclaration.ts @@ -0,0 +1,15 @@ +/// + +//// declare module "http" { +//// var x; +//// /*1*/ +//// } +//// declare module 'https' { +//// } +//// /*2*/ + +goTo.marker("1"); +verify.not.completionListContains("http"); +goTo.marker("2"); +verify.not.completionListContains("http"); +verify.not.completionListContains("https");