Skip to content

Commit e6d91a4

Browse files
author
Yui T
committed
Merge branch 'release-1.6'
2 parents ca593ec + b962278 commit e6d91a4

File tree

6 files changed

+127
-13
lines changed

6 files changed

+127
-13
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ namespace ts {
18931893

18941894
function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) {
18951895
let targetSymbol = getTargetSymbol(symbol);
1896-
if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface) {
1896+
if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface || targetSymbol.flags & SymbolFlags.TypeAlias) {
18971897
buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
18981898
}
18991899
}

src/services/services.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,10 +3589,11 @@ namespace ts {
35893589
containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, |
35903590
isFunction(containingNodeKind) ||
35913591
containingNodeKind === SyntaxKind.ClassDeclaration || // class A<T, |
3592-
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A<T, |
3592+
containingNodeKind === SyntaxKind.ClassExpression || // var C = class D<T, |
35933593
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A<T, |
3594-
containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [x, y|
3595-
3594+
containingNodeKind === SyntaxKind.ArrayBindingPattern || // var [x, y|
3595+
containingNodeKind === SyntaxKind.TypeAliasDeclaration; // type Map, K, |
3596+
35963597
case SyntaxKind.DotToken:
35973598
return containingNodeKind === SyntaxKind.ArrayBindingPattern; // var [.|
35983599

@@ -3619,8 +3620,9 @@ namespace ts {
36193620

36203621
case SyntaxKind.LessThanToken:
36213622
return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< |
3622-
containingNodeKind === SyntaxKind.FunctionDeclaration || // function A< |
3623+
containingNodeKind === SyntaxKind.ClassExpression || // var C = class D< |
36233624
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A< |
3625+
containingNodeKind === SyntaxKind.TypeAliasDeclaration || // type List< |
36243626
isFunction(containingNodeKind);
36253627

36263628
case SyntaxKind.StaticKeyword:
@@ -4181,6 +4183,7 @@ namespace ts {
41814183
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
41824184
displayParts.push(spacePart());
41834185
addFullSymbolName(symbol);
4186+
writeTypeParametersOfSymbol(symbol, sourceFile);
41844187
displayParts.push(spacePart());
41854188
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
41864189
displayParts.push(spacePart());
@@ -4221,16 +4224,29 @@ namespace ts {
42214224
}
42224225
else {
42234226
// Method/function type parameter
4224-
let signatureDeclaration = <SignatureDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeParameter).parent;
4225-
let signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration);
4226-
if (signatureDeclaration.kind === SyntaxKind.ConstructSignature) {
4227-
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
4228-
displayParts.push(spacePart());
4227+
let container = getContainingFunction(location);
4228+
if (container) {
4229+
let signatureDeclaration = <SignatureDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeParameter).parent;
4230+
let signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration);
4231+
if (signatureDeclaration.kind === SyntaxKind.ConstructSignature) {
4232+
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
4233+
displayParts.push(spacePart());
4234+
}
4235+
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
4236+
addFullSymbolName(signatureDeclaration.symbol);
4237+
}
4238+
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
42294239
}
4230-
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
4231-
addFullSymbolName(signatureDeclaration.symbol);
4240+
else {
4241+
// Type aliash type parameter
4242+
// For example
4243+
// type list<T> = T[]; // Both T will go through same code path
4244+
let declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeParameter).parent;
4245+
displayParts.push(keywordPart(SyntaxKind.TypeKeyword));
4246+
displayParts.push(spacePart());
4247+
addFullSymbolName(declaration.symbol);
4248+
writeTypeParametersOfSymbol(declaration.symbol, sourceFile);
42324249
}
4233-
addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
42344250
}
42354251
}
42364252
if (symbolFlags & SymbolFlags.EnumMember) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////var C0 = class D</*0*/
4+
////var C1 = class D</*1*/T> {}
5+
////var C3 = class D<T, /*2*/
6+
////var C4 = class D<T, /*3*/U>{}
7+
////var C5 = class D<T extends /*4*/>{}
8+
9+
goTo.marker("0");
10+
verify.completionListIsEmpty();
11+
goTo.marker("1");
12+
verify.completionListIsEmpty();
13+
goTo.marker("2");
14+
verify.completionListIsEmpty();
15+
goTo.marker("3");
16+
verify.completionListIsEmpty();
17+
goTo.marker("4");
18+
verify.not.completionListIsEmpty();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////type List1</*0*/
4+
////type List2</*1*/T> = T[];
5+
////type List4<T> = /*2*/T[];
6+
////type List3<T1> = /*3*/;
7+
8+
goTo.marker("0");
9+
verify.completionListIsEmpty();
10+
goTo.marker("1");
11+
verify.not.completionListIsEmpty();
12+
goTo.marker("2");
13+
verify.completionListContains("T");
14+
goTo.marker("3");
15+
verify.not.completionListIsEmpty();
16+
verify.not.completionListContains("T");
17+
verify.completionListContains("T1");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////type Map1<K, /*0*/
4+
////type Map1<K, /*1*/V> = [];
5+
////type Map1<K,V> = /*2*/[];
6+
////type Map1<K1, V1> = </*3*/
7+
8+
goTo.marker("0");
9+
verify.completionListIsEmpty();
10+
goTo.marker("1");
11+
verify.completionListContains("V");
12+
goTo.marker("2");
13+
verify.completionListContains("K");
14+
verify.completionListContains("V");
15+
goTo.marker("3");
16+
verify.not.completionListContains("K");
17+
verify.not.completionListContains("V");
18+
verify.completionListContains("K1");
19+
verify.completionListContains("V1");
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////type /*0*/List</*1*/T> = /*2*/T[]
4+
////type /*3*/List2</*4*/T extends string> = /*5*/T[];
5+
6+
type List2<T extends string> = T[];
7+
8+
type L<T> = T[]
9+
let typeAliashDisplayParts = [{ text: "type", kind: "keyword" }, { text: " ", kind: "space" }, { text: "List", kind: "aliasName" },
10+
{ text: "<", kind: "punctuation" }, { text: "T", kind: "typeParameterName" }, { text: ">", kind: "punctuation" }];
11+
12+
let typeAliashDisplayParts2 = [{ text: "type", kind: "keyword" }, { text: " ", kind: "space" }, { text: "List2", kind: "aliasName" },
13+
{ text: "<", kind: "punctuation" }, { text: "T", kind: "typeParameterName" }, { text: " ", kind: "space" }, { text: "extends", kind: "keyword" },
14+
{ text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: ">", kind: "punctuation" }];
15+
16+
let typeParameterDisplayParts = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" },
17+
{ text: "T", kind: "typeParameterName" }, { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" } ]
18+
19+
20+
goTo.marker('0');
21+
verify.verifyQuickInfoDisplayParts("type", "", { start: test.markerByName("0").position, length: "List".length },
22+
typeAliashDisplayParts.concat([{ text: " ", kind: "space" }, { text: "=", kind: "operator" }, { "text": " ", "kind": "space" }, { text: "T", kind: "typeParameterName" },
23+
{ text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }]), []);
24+
25+
goTo.marker('1');
26+
verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("1").position, length: "T".length },
27+
typeParameterDisplayParts.concat(typeAliashDisplayParts), []);
28+
29+
goTo.marker('2');
30+
verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("2").position, length: "T".length },
31+
typeParameterDisplayParts.concat(typeAliashDisplayParts), []);
32+
33+
goTo.marker('3');
34+
verify.verifyQuickInfoDisplayParts("type", "", { start: test.markerByName("3").position, length: "List2".length },
35+
typeAliashDisplayParts2.concat([{ text: " ", kind: "space" }, { text: "=", kind: "operator" }, { "text": " ", "kind": "space" }, { text: "T", kind: "typeParameterName" },
36+
{ text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }]), []);
37+
38+
goTo.marker('4');
39+
verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("4").position, length: "T".length },
40+
typeParameterDisplayParts.concat(typeAliashDisplayParts2), []);
41+
42+
goTo.marker('5');
43+
verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("5").position, length: "T".length },
44+
typeParameterDisplayParts.concat(typeAliashDisplayParts2), []);

0 commit comments

Comments
 (0)