Skip to content

Commit 471d80d

Browse files
committed
Show better alias information in completion entry and quickInfo
1 parent 8ff6251 commit 471d80d

9 files changed

+46
-14
lines changed

src/services/services.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,11 +2917,28 @@ module ts {
29172917
}
29182918
if (symbolFlags & SymbolFlags.Import) {
29192919
addNewLineIfDisplayPartsExist();
2920-
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
2921-
displayParts.push(textPart("alias"));
2922-
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
2920+
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
29232921
displayParts.push(spacePart());
29242922
addFullSymbolName(symbol);
2923+
displayParts.push(spacePart());
2924+
displayParts.push(punctuationPart(SyntaxKind.EqualsToken));
2925+
displayParts.push(spacePart());
2926+
ts.forEach(symbol.declarations, declaration => {
2927+
if (declaration.kind === SyntaxKind.ImportDeclaration) {
2928+
var importDeclaration = <ImportDeclaration>declaration;
2929+
if (importDeclaration.externalModuleName) {
2930+
displayParts.push(keywordPart(SyntaxKind.RequireKeyword));
2931+
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
2932+
displayParts.push(displayPart(getTextOfNode(importDeclaration.externalModuleName), SymbolDisplayPartKind.stringLiteral));
2933+
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
2934+
}
2935+
else {
2936+
var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName);
2937+
addFullSymbolName(internalAliasSymbol, enclosingDeclaration);
2938+
}
2939+
return true;
2940+
}
2941+
});
29252942
}
29262943
if (!hasAddedSymbolInfo) {
29272944
if (symbolKind !== ScriptElementKind.unknown) {
@@ -3028,7 +3045,7 @@ module ts {
30283045
case SyntaxKind.QualifiedName:
30293046
case SyntaxKind.ThisKeyword:
30303047
case SyntaxKind.SuperKeyword:
3031-
// For the identifiers/this/usper etc get the type at position
3048+
// For the identifiers/this/super etc get the type at position
30323049
var type = typeInfoResolver.getTypeOfNode(node);
30333050
if (type) {
30343051
return {

tests/cases/fourslash/commentsExternalModules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ verify.memberListContains("i", "(var) m1.m2.i: m1.m2.c", "i");
6969

7070
goTo.file("commentsExternalModules_file1.ts");
7171
goTo.marker('9');
72-
verify.quickInfoIs('(alias) extMod', "This is on import declaration");
72+
verify.quickInfoIs('import extMod = require("commentsExternalModules_file0")', "This is on import declaration");
7373

7474
goTo.marker('10');
75-
verify.completionListContains("extMod", "(alias) extMod", "This is on import declaration");
75+
verify.completionListContains("extMod", 'import extMod = require("commentsExternalModules_file0")', "This is on import declaration");
7676

7777
goTo.marker('11');
7878
verify.memberListContains("m1", "module extMod.m1");

tests/cases/fourslash/commentsImportDeclaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ goTo.marker('2');
2828
verify.quickInfoIs("module m1", "ModuleComment");
2929

3030
goTo.marker('3');
31-
verify.quickInfoIs("(alias) extMod", "Import declaration");
31+
verify.quickInfoIs('import extMod = require("commentsImportDeclaration_file0")', "Import declaration");
3232

3333
goTo.marker('6');
3434
verify.memberListContains("m1", "module extMod.m1");

tests/cases/fourslash/completionListOnAliases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
////}
1010

1111
goTo.marker("1");
12-
verify.memberListContains("x", "(alias) x", undefined);
12+
verify.memberListContains("x", "import x = M", undefined);
1313

1414
goTo.marker("2");
1515
verify.memberListContains("value");

tests/cases/fourslash/exportEqualTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
////var /*3*/r2 = t./*4*/foo; // t should have 'foo' in dropdown list and be of type 'string'
1616

1717
goTo.marker('1');
18-
verify.quickInfoIs('(alias) test');
18+
verify.quickInfoIs("import test = require('exportEqualTypes_file0')");
1919
goTo.marker('2');
2020
verify.quickInfoIs('(var) r1: Date');
2121
goTo.marker('3');

tests/cases/fourslash/externalModuleWithExportAssignment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
goTo.file("externalModuleWithExportAssignment_file1.ts");
3232
goTo.marker('1');
33-
verify.quickInfoIs("(alias) a1");
33+
verify.quickInfoIs('import a1 = require("externalModuleWithExportAssignment_file0")');
3434

3535
goTo.marker('2');
3636
verify.quickInfoIs("(var) a: {\n (): a1.connectExport;\n test1: a1.connectModule;\n test2(): a1.connectModule;\n}", undefined);

tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
edit.insert('');
2020

2121
goTo.marker('1');
22-
verify.quickInfoIs('(alias) Foo');
22+
verify.quickInfoIs("import Foo = require('mergedDeclarationsWithExportAssignment1_file0')");
2323

2424
goTo.marker('2');
2525
verify.completionListContains('Foo');

tests/cases/fourslash/quickInfoOnInternalAliases.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@
1111
////}
1212
/////**This is on import declaration*/
1313
////import /*2*/internalAlias = m1.m2./*3*/c;
14+
////var /*4*/newVar = new /*5*/internalAlias();
15+
////var /*6*/anotherAliasVar = /*7*/internalAlias;
16+
1417

1518
goTo.marker('1');
1619
verify.quickInfoIs("class m1.m2.c", "class comment;");
1720

1821
goTo.marker('2');
19-
verify.quickInfoIs('(alias) internalAlias', "This is on import declaration");
22+
verify.quickInfoIs('import internalAlias = m1.m2.c', "This is on import declaration");
2023

2124
goTo.marker('3');
22-
verify.quickInfoIs("class m1.m2.c", "class comment;");
25+
verify.quickInfoIs("class m1.m2.c", "class comment;");
26+
27+
goTo.marker('4');
28+
verify.quickInfoIs("(var) newVar: internalAlias", "");
29+
30+
goTo.marker('5');
31+
verify.quickInfoIs("import internalAlias = m1.m2.c", "This is on import declaration");
32+
33+
goTo.marker('6');
34+
verify.quickInfoIs("(var) anotherAliasVar: typeof internalAlias", "");
35+
36+
goTo.marker('7');
37+
verify.quickInfoIs("import internalAlias = m1.m2.c", "This is on import declaration");

tests/cases/fourslash/selfReferencedExternalModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
////A./**/I
66

77
goTo.marker();
8-
verify.completionListContains("A", "(alias) A");
8+
verify.completionListContains("A", "import A = require('app')");
99
verify.completionListContains("I", "(var) I: number");

0 commit comments

Comments
 (0)