Merge pull request #884 from Microsoft/moveSymbolDisplayPartKindToServices

Move symbolDisplayPartKind to services side
This commit is contained in:
Sheetal Nandi 2014-10-15 13:57:58 -07:00
commit 781661f719
4 changed files with 81 additions and 58 deletions

View File

@ -33,10 +33,16 @@ module ts {
if (stringWriters.length == 0) {
var str = "";
var writeText: (text: string) => void = text => str += text;
return {
string: () => str,
writeKind: text => str += text,
writeSymbol: text => str += text,
writeKeyword: writeText,
writeOperator: writeText,
writePunctuation: writeText,
writeSpace: writeText,
writeStringLiteral: writeText,
writeParameter: writeText,
writeSymbol: writeText,
// Completely ignore indentation for string writers. And map newlines to
// a single space.
@ -948,19 +954,19 @@ module ts {
}
function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) {
writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.keyword);
writer.writeKeyword(tokenToString(kind));
}
function writePunctuation(writer: SymbolWriter, kind: SyntaxKind) {
writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.punctuation);
writer.writePunctuation(tokenToString(kind));
}
function writeOperator(writer: SymbolWriter, kind: SyntaxKind) {
writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.operator);
writer.writeOperator(tokenToString(kind));
}
function writeSpace(writer: SymbolWriter) {
writer.writeKind(" ", SymbolDisplayPartKind.space);
writer.writeSpace(" ");
}
function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string {
@ -1079,8 +1085,8 @@ module ts {
// Write undefined/null type as any
if (type.flags & TypeFlags.Intrinsic) {
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving
writer.writeKind(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) &&
(type.flags & TypeFlags.Any) ? "any" : (<IntrinsicType>type).intrinsicName, SymbolDisplayPartKind.keyword);
writer.writeKeyword(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) &&
(type.flags & TypeFlags.Any) ? "any" : (<IntrinsicType>type).intrinsicName);
}
else if (type.flags & TypeFlags.Reference) {
writeTypeReference(<TypeReference>type);
@ -1098,7 +1104,7 @@ module ts {
writeAnonymousType(<ObjectType>type, flags);
}
else if (type.flags & TypeFlags.StringLiteral) {
writer.writeKind((<StringLiteralType>type).text, SymbolDisplayPartKind.stringLiteral);
writer.writeStringLiteral((<StringLiteralType>type).text);
}
else {
// Should never get here
@ -1240,7 +1246,7 @@ module ts {
if (resolved.stringIndexType) {
// [x: string]:
writePunctuation(writer, SyntaxKind.OpenBracketToken);
writer.writeKind("x", SymbolDisplayPartKind.parameterName);
writer.writeParameter("x");
writePunctuation(writer, SyntaxKind.ColonToken);
writeSpace(writer);
writeKeyword(writer, SyntaxKind.StringKeyword);
@ -1254,7 +1260,7 @@ module ts {
if (resolved.numberIndexType) {
// [x: number]:
writePunctuation(writer, SyntaxKind.OpenBracketToken);
writer.writeKind("x", SymbolDisplayPartKind.parameterName);
writer.writeParameter("x");
writePunctuation(writer, SyntaxKind.ColonToken);
writeSpace(writer);
writeKeyword(writer, SyntaxKind.NumberKeyword);

View File

@ -4,8 +4,11 @@
/// <reference path="parser.ts"/>
module ts {
interface EmitTextWriter extends SymbolWriter {
interface EmitTextWriter {
write(s: string): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
getText(): string;
rawWrite(s: string): void;
writeLiteral(s: string): void;
@ -15,6 +18,9 @@ module ts {
getIndent(): number;
}
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
}
var indentStrings: string[] = ["", " "];
export function getIndentString(level: number) {
if (indentStrings[level] === undefined) {
@ -103,7 +109,7 @@ module ts {
};
}
function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter {
function createTextWriter(): EmitTextWriter {
var output = "";
var indent = 0;
var lineStart = true;
@ -149,17 +155,8 @@ module ts {
}
}
function writeKind(text: string, kind: SymbolDisplayPartKind) {
write(text);
}
function writeSymbol(text: string, symbol: Symbol) {
write(text);
}
return {
write: write,
trackSymbol: trackSymbol,
writeKind: writeKind,
writeSymbol: writeSymbol,
rawWrite: rawWrite,
writeLiteral: writeLiteral,
writeLine: writeLine,
@ -170,7 +167,6 @@ module ts {
getLine: () => lineCount + 1,
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
getText: () => output,
clear: () => { }
};
}
@ -318,7 +314,7 @@ module ts {
}
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@ -374,8 +370,6 @@ module ts {
/** Sourcemap data that will get encoded */
var sourceMapData: SourceMapData;
function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { }
function initializeEmitterWithSourceMaps() {
var sourceMapDir: string; // The directory in which sourcemap will be
@ -2314,7 +2308,7 @@ module ts {
}
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriterWithSymbolWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@ -2338,11 +2332,24 @@ module ts {
typeName?: Identifier
}
function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
var writer = <EmitTextWriterWithSymbolWriter>createTextWriter();
writer.trackSymbol = trackSymbol;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
writer.writeSpace = writer.write;
writer.writeStringLiteral = writer.writeLiteral;
writer.writeParameter = writer.write;
writer.writeSymbol = writer.write;
return writer;
}
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
var oldWriter = writer;
forEach(importDeclarations, aliasToWrite => {
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
writer = createTextWriter(trackSymbol);
writer = createTextWriterWithSymbolWriter();
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
writer.increaseIndent();
}

View File

@ -673,7 +673,12 @@ module ts {
}
export interface SymbolWriter {
writeKind(text: string, kind: SymbolDisplayPartKind): void;
writeKeyword(text: string): void;
writeOperator(text: string): void;
writePunctuation(text: string): void;
writeSpace(text: string): void;
writeStringLiteral(text: string): void;
writeParameter(text: string): void;
writeSymbol(text: string, symbol: Symbol): void;
writeLine(): void;
increaseIndent(): void;
@ -1232,32 +1237,7 @@ module ts {
tab = 0x09, // \t
verticalTab = 0x0B, // \v
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface CancellationToken {
isCancellationRequested(): boolean;
}

View File

@ -994,12 +994,37 @@ module ts {
containerKind: string;
containerName: string;
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface SymbolDisplayPart {
text: string;
kind: string;
}
export interface QuickInfo {
kind: string;
kindModifiers: string;
@ -1306,7 +1331,12 @@ module ts {
resetWriter();
return {
displayParts: () => displayParts,
writeKind: writeKind,
writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword),
writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator),
writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation),
writeSpace: text => writeKind(text, SymbolDisplayPartKind.space),
writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral),
writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName),
writeSymbol: writeSymbol,
writeLine: writeLine,
increaseIndent: () => { indent++; },