Skip to content

Commit 8b3904f

Browse files
committed
Merge pull request #793 from Microsoft/symbolInfoFormatting
Formatting of symbol information, along with doc comments support
2 parents 400f6eb + 279791e commit 8b3904f

File tree

272 files changed

+5636
-5462
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+5636
-5462
lines changed

src/compiler/checker.ts

Lines changed: 169 additions & 240 deletions
Large diffs are not rendered by default.

src/compiler/emitter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
/// <reference path="parser.ts"/>
55

66
module ts {
7-
interface EmitTextWriter extends TextWriter {
7+
interface EmitTextWriter extends SymbolWriter {
8+
write(s: string): void;
9+
getText(): string;
810
rawWrite(s: string): void;
911
writeLiteral(s: string): void;
1012
getTextPos(): number;
@@ -14,7 +16,7 @@ module ts {
1416
}
1517

1618
var indentStrings: string[] = ["", " "];
17-
function getIndentString(level: number) {
19+
export function getIndentString(level: number) {
1820
if (indentStrings[level] === undefined) {
1921
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
2022
}
@@ -147,9 +149,17 @@ module ts {
147149
}
148150
}
149151

152+
function writeKind(text: string, kind: SymbolDisplayPartKind) {
153+
write(text);
154+
}
155+
function writeSymbol(text: string, symbol: Symbol) {
156+
write(text);
157+
}
150158
return {
151159
write: write,
152160
trackSymbol: trackSymbol,
161+
writeKind: writeKind,
162+
writeSymbol: writeSymbol,
153163
rawWrite: rawWrite,
154164
writeLiteral: writeLiteral,
155165
writeLine: writeLine,
@@ -160,6 +170,7 @@ module ts {
160170
getLine: () => lineCount + 1,
161171
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
162172
getText: () => output,
173+
clear: () => { }
163174
};
164175
}
165176

src/compiler/types.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,19 @@ module ts {
643643
getTypeOfNode(node: Node): Type;
644644
getApparentType(type: Type): ApparentType;
645645
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
646+
writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
646647
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
647-
typeToDisplayParts(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[];
648-
symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[];
648+
writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
649649
getFullyQualifiedName(symbol: Symbol): string;
650650
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
651651
getRootSymbol(symbol: Symbol): Symbol;
652652
getContextualType(node: Node): Type;
653653
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
654+
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
655+
writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
656+
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
657+
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
658+
isImplementationOfOverload(node: FunctionDeclaration): boolean;
654659

655660
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
656661
// computed value.
@@ -660,20 +665,36 @@ module ts {
660665
getAliasedSymbol(symbol: Symbol): Symbol;
661666
}
662667

663-
export interface TextWriter {
664-
write(s: string): void;
665-
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
668+
export interface SymbolWriter {
669+
writeKind(text: string, kind: SymbolDisplayPartKind): void;
670+
writeSymbol(text: string, symbol: Symbol): void;
666671
writeLine(): void;
667672
increaseIndent(): void;
668673
decreaseIndent(): void;
669-
getText(): string;
674+
clear(): void;
675+
676+
// Called when the symbol writer encounters a symbol to write. Currently only used by the
677+
// declaration emitter to help determine if it should patch up the final declaration file
678+
// with import statements it previously saw (but chose not to emit).
679+
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
670680
}
671681

672682
export enum TypeFormatFlags {
673-
None = 0x00000000,
674-
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
675-
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
676-
NoTruncation = 0x00000004, // Don't truncate typeToString result
683+
None = 0x00000000,
684+
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
685+
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
686+
NoTruncation = 0x00000004, // Don't truncate typeToString result
687+
WriteArrowStyleSignature = 0x00000008, // Write arrow style signature
688+
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
689+
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
690+
}
691+
692+
export enum SymbolFormatFlags {
693+
None = 0x00000000,
694+
WriteTypeParametersOrArguments = 0x00000001, // Write symbols's type argument if it is instantiated symbol
695+
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
696+
// var a: C<number>;
697+
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
677698
}
678699

679700
export enum SymbolAccessibility {
@@ -701,8 +722,8 @@ module ts {
701722
hasSemanticErrors(): boolean;
702723
isDeclarationVisible(node: Declaration): boolean;
703724
isImplementationOfOverload(node: FunctionDeclaration): boolean;
704-
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
705-
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
725+
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
726+
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
706727
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
707728
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
708729

@@ -743,6 +764,8 @@ module ts {
743764
Transient = 0x02000000, // Transient symbol (created during type check)
744765
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
745766

767+
Undefined = 0x08000000, // Symbol for the undefined
768+
746769
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
747770
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
748771
Namespace = ValueModule | NamespaceModule,
@@ -1190,46 +1213,24 @@ module ts {
11901213
verticalTab = 0x0B, // \v
11911214
}
11921215

1193-
export class SymbolDisplayPart {
1194-
constructor(public text: string,
1195-
public kind: SymbolDisplayPartKind,
1196-
public symbol: Symbol) {
1197-
}
1198-
1199-
public toJSON() {
1200-
return {
1201-
text: this.text,
1202-
kind: SymbolDisplayPartKind[this.kind]
1203-
};
1204-
}
1205-
1206-
public static toString(parts: SymbolDisplayPart[]) {
1207-
var result = map(parts, p => p.text);
1208-
return result ? result.join("") : "";
1209-
}
1210-
}
1211-
12121216
export enum SymbolDisplayPartKind {
12131217
aliasName,
12141218
className,
12151219
enumName,
12161220
fieldName,
12171221
interfaceName,
12181222
keyword,
1219-
labelName,
12201223
lineBreak,
12211224
numericLiteral,
12221225
stringLiteral,
12231226
localName,
12241227
methodName,
12251228
moduleName,
1226-
namespaceName,
12271229
operator,
12281230
parameterName,
12291231
propertyName,
12301232
punctuation,
12311233
space,
1232-
anonymousTypeIndicator,
12331234
text,
12341235
typeParameterName,
12351236
enumMemberName,

0 commit comments

Comments
 (0)