Skip to content

Commit 835d0ac

Browse files
author
Yui T
committed
Address code review
1 parent b37e8fc commit 835d0ac

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/services/services.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,9 +1681,17 @@ module ts {
16811681
}
16821682

16831683
/// Completion
1684-
function getValidCompletionEntryDisplayName(displayName: string, target: ScriptTarget): string {
1684+
function getValidCompletionEntryDisplayName(symbol: Symbol, target: ScriptTarget): string {
1685+
var displayName = symbol.getName();
16851686
if (displayName && displayName.length > 0) {
16861687
var firstCharCode = displayName.charCodeAt(0);
1688+
// First check of the displayName is not external module; if it is an external module, it is not valid entry
1689+
if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
1690+
// If the symbol is external module, don't show it in the completion list
1691+
// (i.e declare module "http" { var x; } | // <= request completion here, "http" should not be there)
1692+
return undefined;
1693+
}
1694+
16871695
if (displayName && displayName.length >= 2 && firstCharCode === displayName.charCodeAt(displayName.length - 1) &&
16881696
(firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
16891697
// If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an
@@ -1696,6 +1704,7 @@ module ts {
16961704
isValid = isIdentifierPart(displayName.charCodeAt(i), target);
16971705
}
16981706

1707+
16991708
if (isValid) {
17001709
return displayName;
17011710
}
@@ -1708,14 +1717,7 @@ module ts {
17081717
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
17091718
// We would like to only show things that can be added after a dot, so for instance numeric properties can
17101719
// not be accessed with a dot (a.1 <- invalid)
1711-
var firstCharCode = symbol.name.charCodeAt(0);
1712-
if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
1713-
// If the symbol is external module, don't show it in the completion list
1714-
// (i.e declare module "http" { var x; } | // <= request completion here, "http" should not be there)
1715-
return undefined;
1716-
}
1717-
1718-
var displayName = getValidCompletionEntryDisplayName(symbol.getName(), program.getCompilerOptions().target);
1720+
var displayName = getValidCompletionEntryDisplayName(symbol, program.getCompilerOptions().target);
17191721
if (!displayName) {
17201722
return undefined;
17211723
}

tests/cases/fourslash/completionListWithAmbientDeclaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//// /**/
77

88
goTo.marker();
9-
verifyNegatable.completionListContains("http");
9+
verify.not.completionListContains("http");

tests/cases/fourslash/fourslash.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ function verifyOperationIsCancelled(f) {
630630
var test = new FourSlashInterface.test_();
631631
var goTo = new FourSlashInterface.goTo();
632632
var verify = new FourSlashInterface.verify();
633-
var verifyNegatable = new FourSlashInterface.verifyNegatable(true);
634633
var edit = new FourSlashInterface.edit();
635634
var debug = new FourSlashInterface.debug();
636635
var format = new FourSlashInterface.format();

0 commit comments

Comments
 (0)