mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 11:43:18 -05:00
addressed CR feedback, added comments, dropped unused code
This commit is contained in:
@@ -1124,7 +1124,15 @@ module ts {
|
||||
messageText: string;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
/**
|
||||
* Early error - any error (can be produced at parsing\binding\typechecking step) that blocks emit
|
||||
*/
|
||||
isEarly?: boolean;
|
||||
/**
|
||||
* Parse error - error produced by parser when it scanner returns a token
|
||||
* that parser does not understand in its current state
|
||||
* (as opposed to grammar error when parser can interpret the token but interpretation is not legal from the grammar perespective)
|
||||
*/
|
||||
isParseError?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,24 @@ module ts.formatting {
|
||||
* { var x;
|
||||
* }
|
||||
* Normally indentation is applied only to the first token in line so at glance 'var' should not be touched.
|
||||
* However if some format rule removes new line between ')' and '{' 'var' will become
|
||||
* However if some format rule adds new line between '}' and 'var' 'var' will become
|
||||
* the first token in line so it should be indented
|
||||
*/
|
||||
interface DynamicIndentation {
|
||||
getIndentationForToken(tokenLine: number, tokenKind: SyntaxKind): number;
|
||||
getIndentationForComment(owningToken: SyntaxKind): number;
|
||||
/**
|
||||
* Indentation for open and close tokens of the node if it is block or another node that needs special indentation
|
||||
* ... {
|
||||
* .........<child>
|
||||
* ....}
|
||||
* ____ - indentation
|
||||
* ____ - delta
|
||||
**/
|
||||
getIndentation(): number;
|
||||
/**
|
||||
* Prefered relative indentation for child nodes
|
||||
*/
|
||||
getDelta(): number;
|
||||
recomputeIndentation(lineAddedByFormatting: boolean): void;
|
||||
}
|
||||
@@ -99,6 +110,14 @@ module ts.formatting {
|
||||
}
|
||||
|
||||
// walk up and search for the parent node that ends at the same position with precedingToken.
|
||||
// for cases like this
|
||||
//
|
||||
// var x = 1;
|
||||
// while (true) {
|
||||
// }
|
||||
// after typing close curly in while statement we want to reformat just the while statement.
|
||||
// However if we just walk upwards searching for the parent that has the same end value -
|
||||
// we'll end up with the whole source file. isListElement allows to stop on the list element level
|
||||
var current = precedingToken;
|
||||
while (current &&
|
||||
current.parent &&
|
||||
@@ -138,7 +157,14 @@ module ts.formatting {
|
||||
|
||||
function find(n: Node): Node {
|
||||
var candidate = forEachChild(n, c => startEndContainsRange(c.getStart(sourceFile), c.end, range) && c);
|
||||
return (candidate && find(candidate)) || n;
|
||||
if (candidate) {
|
||||
var result = find(candidate);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,9 +256,11 @@ module ts.formatting {
|
||||
// local functions
|
||||
|
||||
/** Tries to compute the indentation for a list element.
|
||||
* If list element is not in range then function will pick its actual indentation
|
||||
* If list element is not in range then
|
||||
* function will pick its actual indentation
|
||||
* so it can be pushed downstream as inherited indentation.
|
||||
* If list element is in the range - its indentation will be equal to inherited indentation from its predecessors.
|
||||
* If list element is in the range - its indentation will be equal
|
||||
* to inherited indentation from its predecessors.
|
||||
*/
|
||||
function tryComputeIndentationForListItem(startPos: number,
|
||||
endPos: number,
|
||||
@@ -440,8 +468,7 @@ module ts.formatting {
|
||||
var childStartPos = child.getStart(sourceFile);
|
||||
|
||||
var childStart = sourceFile.getLineAndCharacterFromPosition(childStartPos);
|
||||
var childIndentationAmount =
|
||||
isListItem
|
||||
var childIndentationAmount = isListItem
|
||||
? tryComputeIndentationForListItem(childStartPos, child.end, parentStartLine, originalRange, inheritedIndentation)
|
||||
: Constants.Unknown;
|
||||
|
||||
|
||||
@@ -959,15 +959,6 @@ module ts {
|
||||
ConvertTabsToSpaces: boolean;
|
||||
}
|
||||
|
||||
export function copyEditorOptions(o: EditorOptions): EditorOptions {
|
||||
return {
|
||||
IndentSize: o.IndentSize,
|
||||
TabSize: o.TabSize,
|
||||
NewLineCharacter: o.NewLineCharacter,
|
||||
ConvertTabsToSpaces: o.ConvertTabsToSpaces
|
||||
};
|
||||
}
|
||||
|
||||
export interface FormatCodeOptions extends EditorOptions {
|
||||
InsertSpaceAfterCommaDelimiter: boolean;
|
||||
InsertSpaceAfterSemicolonInForStatements: boolean;
|
||||
@@ -979,23 +970,6 @@ module ts {
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
||||
}
|
||||
|
||||
export function copyFormatCodeOptions(o: FormatCodeOptions): FormatCodeOptions {
|
||||
return {
|
||||
IndentSize: o.IndentSize,
|
||||
TabSize: o.TabSize,
|
||||
NewLineCharacter: o.NewLineCharacter,
|
||||
ConvertTabsToSpaces: o.ConvertTabsToSpaces,
|
||||
InsertSpaceAfterCommaDelimiter: o.InsertSpaceAfterCommaDelimiter,
|
||||
InsertSpaceAfterSemicolonInForStatements: o.InsertSpaceAfterSemicolonInForStatements,
|
||||
InsertSpaceBeforeAndAfterBinaryOperators: o.InsertSpaceBeforeAndAfterBinaryOperators,
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: o.InsertSpaceAfterKeywordsInControlFlowStatements,
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: o.InsertSpaceAfterFunctionKeywordForAnonymousFunctions,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: o.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis,
|
||||
PlaceOpenBraceOnNewLineForFunctions: o.PlaceOpenBraceOnNewLineForFunctions,
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: o.PlaceOpenBraceOnNewLineForControlBlocks
|
||||
};
|
||||
}
|
||||
|
||||
export interface DefinitionInfo {
|
||||
fileName: string;
|
||||
textSpan: TypeScript.TextSpan;
|
||||
@@ -5224,7 +5198,7 @@ module ts {
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
var result = formatting.SmartIndenter.getIndentation(position, sourceFile, copyEditorOptions(editorOptions));
|
||||
var result = formatting.SmartIndenter.getIndentation(position, sourceFile, editorOptions);
|
||||
host.log("getIndentationAtPosition: computeIndentation : " + (new Date().getTime() - start));
|
||||
|
||||
return result;
|
||||
@@ -5232,7 +5206,6 @@ module ts {
|
||||
|
||||
function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
var options = copyFormatCodeOptions(options);
|
||||
var sourceFile = getCurrentSourceFile(fileName);
|
||||
return formatting.formatSelection(start, end, sourceFile, getRuleProvider(options), options);
|
||||
}
|
||||
@@ -5241,7 +5214,6 @@ module ts {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
|
||||
var sourceFile = getCurrentSourceFile(fileName);
|
||||
var options = copyFormatCodeOptions(options)
|
||||
return formatting.formatDocument(sourceFile, getRuleProvider(options), options);
|
||||
}
|
||||
|
||||
@@ -5249,7 +5221,6 @@ module ts {
|
||||
fileName = switchToForwardSlashes(fileName);
|
||||
|
||||
var sourceFile = getCurrentSourceFile(fileName);
|
||||
var options = copyFormatCodeOptions(options);
|
||||
|
||||
if (key === "}") {
|
||||
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(options), options);
|
||||
|
||||
@@ -298,7 +298,7 @@ module ts.formatting {
|
||||
return column;
|
||||
}
|
||||
|
||||
export function nodeContentIsAlwaysIndented(kind: SyntaxKind): boolean {
|
||||
function nodeContentIsAlwaysIndented(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user