mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
fix issues in formattingContext - 35 failing tests so far
This commit is contained in:
parent
b6b80817f4
commit
40358a1e65
@ -226,6 +226,7 @@ module ts.formatting {
|
||||
|
||||
while (currentTokenInfo.token && node.end >= currentTokenInfo.token.end) {
|
||||
currentTokenInfo = consumeCurrentToken(node, childContextNode, indentation);
|
||||
childContextNode = node;
|
||||
}
|
||||
|
||||
/// Local functions
|
||||
|
||||
@ -17,17 +17,17 @@
|
||||
|
||||
module ts.formatting {
|
||||
export class FormattingContext {
|
||||
public currentTokenSpan: TextRangeWithKind = null;
|
||||
public nextTokenSpan: TextRangeWithKind = null;
|
||||
public contextNode: Node = null;
|
||||
public currentTokenParent: Node = null;
|
||||
public nextTokenParent: Node = null;
|
||||
public currentTokenSpan: TextRangeWithKind;
|
||||
public nextTokenSpan: TextRangeWithKind;
|
||||
public contextNode: Node;
|
||||
public currentTokenParent: Node;
|
||||
public nextTokenParent: Node;
|
||||
|
||||
private contextNodeAllOnSameLine: boolean = null;
|
||||
private nextNodeAllOnSameLine: boolean = null;
|
||||
private tokensAreOnSameLine: boolean = null;
|
||||
private contextNodeBlockIsOnOneLine: boolean = null;
|
||||
private nextNodeBlockIsOnOneLine: boolean = null;
|
||||
private contextNodeAllOnSameLine: boolean;
|
||||
private nextNodeAllOnSameLine: boolean;
|
||||
private tokensAreOnSameLine: boolean;
|
||||
private contextNodeBlockIsOnOneLine: boolean;
|
||||
private nextNodeBlockIsOnOneLine: boolean;
|
||||
|
||||
constructor(private sourceFile: SourceFile, public formattingRequestKind: FormattingRequestKind) {
|
||||
}
|
||||
@ -98,9 +98,7 @@ module ts.formatting {
|
||||
return this.nextNodeBlockIsOnOneLine;
|
||||
}
|
||||
|
||||
public NodeIsOnOneLine(node: Node): boolean {
|
||||
return;
|
||||
|
||||
private NodeIsOnOneLine(node: Node): boolean {
|
||||
var startLine = this.sourceFile.getLineAndCharacterFromPosition(node.getStart(this.sourceFile)).line;
|
||||
var endLine = this.sourceFile.getLineAndCharacterFromPosition(node.getEnd()).line;
|
||||
//var startLine = this.snapshot.getLineNumberFromPosition(node.start());
|
||||
@ -111,7 +109,7 @@ module ts.formatting {
|
||||
|
||||
// Now we know we have a block (or a fake block represented by some other kind of node with an open and close brace as children).
|
||||
// IMPORTANT!!! This relies on the invariant that IsBlockContext must return true ONLY for nodes with open and close braces as immediate children
|
||||
public BlockIsOnOneLine(node: Node): boolean {
|
||||
private BlockIsOnOneLine(node: Node): boolean {
|
||||
var openBrace = findChildOfKind(node, SyntaxKind.OpenBraceToken, this.sourceFile);
|
||||
var closeBrace = findChildOfKind(node, SyntaxKind.CloseBraceToken, this.sourceFile);
|
||||
if (openBrace && closeBrace) {
|
||||
|
||||
@ -559,6 +559,11 @@ module ts.formatting {
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.ObjectLiteral:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.FunctionBlock:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -668,15 +673,34 @@ module ts.formatting {
|
||||
return context.contextNode.kind === SyntaxKind.TypeLiteral;// && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
|
||||
}
|
||||
|
||||
static IsTypeArgumentOrParameter(tokenKind: SyntaxKind, parentKind: SyntaxKind): boolean {
|
||||
return;
|
||||
//return ((tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) &&
|
||||
static IsTypeArgumentOrParameter(token: TextRangeWithKind, parent: Node): boolean {
|
||||
if (token.kind !== SyntaxKind.LessThanToken && token.kind !== SyntaxKind.GreaterThanToken) {
|
||||
return false;
|
||||
}
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.TypeReference:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.Method:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
//return ((token.kind === SyntaxKind.LessThanToken || token.kind === SyntaxKind.GreaterThanToken) &&
|
||||
// (parentKind === SyntaxKind.TypeParameterList || parentKind === SyntaxKind.TypeArgumentList));
|
||||
}
|
||||
|
||||
static IsTypeArgumentOrParameterContext(context: FormattingContext): boolean {
|
||||
return Rules.IsTypeArgumentOrParameter(context.currentTokenSpan.kind, context.currentTokenParent.kind) ||
|
||||
Rules.IsTypeArgumentOrParameter(context.nextTokenSpan.kind, context.nextTokenParent.kind);
|
||||
return Rules.IsTypeArgumentOrParameter(context.currentTokenSpan, context.currentTokenParent) ||
|
||||
Rules.IsTypeArgumentOrParameter(context.nextTokenSpan, context.nextTokenParent);
|
||||
}
|
||||
|
||||
static IsVoidOpContext(context: FormattingContext): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user