Skip to content

Commit d1a09da

Browse files
committed
Get the JSDoc comments for the symbols
This also fixed type formatting for single function signatures in the types
1 parent f2880ce commit d1a09da

File tree

5 files changed

+467
-105
lines changed

5 files changed

+467
-105
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,13 +1243,13 @@ module ts {
12431243

12441244
if (allowFunctionOrConstructorTypeLiteral) {
12451245
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
1246-
writeSignature(resolved.callSignatures[0], /*arrowStyle*/ true);
1246+
writeSignature(resolved.callSignatures[0], shouldTypeBeAllowStyleTypeLiteral());
12471247
return;
12481248
}
12491249
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
12501250
writeKeyword(writer, SyntaxKind.NewKeyword);
12511251
writeSpace(writer);
1252-
writeSignature(resolved.constructSignatures[0], /*arrowStyle*/ true);
1252+
writeSignature(resolved.constructSignatures[0], shouldTypeBeAllowStyleTypeLiteral());
12531253
return;
12541254
}
12551255
}
@@ -1328,6 +1328,11 @@ module ts {
13281328
}
13291329
writer.decreaseIndent();
13301330
writePunctuation(writer, SyntaxKind.CloseBraceToken);
1331+
1332+
function shouldTypeBeAllowStyleTypeLiteral() {
1333+
return !typeStack || typeStack.length !== 1 || typeStack[0] !== type || // If this is not a top level type we are writing, arrowStyle is ok
1334+
!(flags & TypeFormatFlags.NoArrowStyleTopLevelSignature);
1335+
}
13311336
}
13321337

13331338
function writeSignature(signature: Signature, arrowStyle?: boolean) {

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ module ts {
673673
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
674674
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
675675
NoTruncation = 0x00000004, // Don't truncate typeToString result
676+
NoArrowStyleTopLevelSignature = 0x00000008, // Do not write type global top level function or constructor literal
676677
}
677678

678679
export enum SymbolAccessibility {

src/harness/fourslash.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -772,35 +772,35 @@ module FourSlash {
772772
var actualQuickInfoSymbolName = actualQuickInfo ? actualQuickInfo.fullSymbolName : "";
773773
var actualQuickInfoKind = actualQuickInfo ? actualQuickInfo.kind : "";
774774

775-
function assertionMessage(name: string, actualValue: string, expectedValue: string) {
776-
return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue;
775+
function assertionMessage(msg: string) {
776+
return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n";
777777
}
778778

779779
if (negative) {
780780
if (expectedTypeName !== undefined) {
781-
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member name", actualQuickInfoMemberName, expectedTypeName));
781+
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member name"));
782782
}
783783
if (docComment != undefined) {
784-
assert.notEqual(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc comment", actualQuickInfoDocComment, docComment));
784+
assert.notEqual(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc comment"));
785785
}
786786
if (symbolName !== undefined) {
787-
assert.notEqual(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name", actualQuickInfoSymbolName, symbolName));
787+
assert.notEqual(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
788788
}
789789
if (kind !== undefined) {
790-
assert.notEqual(actualQuickInfoKind, kind, assertionMessage("quick info kind", actualQuickInfoKind, kind));
790+
assert.notEqual(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
791791
}
792792
} else {
793793
if (expectedTypeName !== undefined) {
794-
assert.equal(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member", actualQuickInfoMemberName, expectedTypeName));
794+
assert.equal(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member"));
795795
}
796796
if (docComment != undefined) {
797-
assert.equal(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc", actualQuickInfoDocComment, docComment));
797+
assert.equal(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc"));
798798
}
799799
if (symbolName !== undefined) {
800-
assert.equal(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name", actualQuickInfoSymbolName, symbolName));
800+
assert.equal(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
801801
}
802802
if (kind !== undefined) {
803-
assert.equal(actualQuickInfoKind, kind, assertionMessage("quick info kind", actualQuickInfoKind, kind));
803+
assert.equal(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
804804
}
805805
}
806806
}

0 commit comments

Comments
 (0)