Skip to content

Commit 685d131

Browse files
committed
addressed CR feedback: use isDeclaration from parser, drop 'useTabs' check
1 parent aa7ffdb commit 685d131

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/compiler/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,15 @@ module ts {
979979
AMD,
980980
}
981981

982+
export interface LineAndCharacter {
983+
line: number;
984+
/*
985+
* This value denotes the character position in line and is different from the 'column' because of tab characters.
986+
*/
987+
character: number;
988+
}
989+
990+
982991
export enum ScriptTarget {
983992
ES3,
984993
ES5,

src/services/formatting/smartIndenter.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
module ts.formatting {
44
export module SmartIndenter {
55

6-
interface LineAndCharacter {
7-
line: number;
8-
character: number;
9-
}
10-
116
export function getIndentation(position: number, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {
127
if (position > sourceFile.text.length) {
138
return 0; // past EOF
@@ -111,23 +106,6 @@ module ts.formatting {
111106
return indentation;
112107
}
113108

114-
function isDeclaration(n: Node): boolean {
115-
switch(n.kind) {
116-
case SyntaxKind.ClassDeclaration:
117-
case SyntaxKind.EnumDeclaration:
118-
case SyntaxKind.FunctionDeclaration:
119-
case SyntaxKind.ImportDeclaration:
120-
case SyntaxKind.Method:
121-
case SyntaxKind.Property:
122-
case SyntaxKind.ModuleDeclaration:
123-
case SyntaxKind.InterfaceDeclaration:
124-
case SyntaxKind.VariableDeclaration:
125-
return true;
126-
default:
127-
return false;
128-
}
129-
}
130-
131109
function isStatement(n: Node): boolean {
132110
switch(n.kind) {
133111
case SyntaxKind.BreakStatement:
@@ -153,7 +131,9 @@ module ts.formatting {
153131
}
154132
}
155133

156-
// function returns -1 if indentation cannot be determined
134+
/*
135+
* Function returns -1 if indentation cannot be determined
136+
*/
157137
function getActualIndentationForListItemBeforeComma(commaToken: Node, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {
158138
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
159139
var precedingListItem = findPrecedingListItem(commaToken);
@@ -167,7 +147,9 @@ module ts.formatting {
167147
return -1;
168148
}
169149

170-
// function returns -1 if actual indentation for node should not be used (i.e because node is nested expression)
150+
/*
151+
* Function returns -1 if actual indentation for node should not be used (i.e because node is nested expression)
152+
*/
171153
function getActualIndentationForNode(current: Node, parent: Node, currentLineAndChar: LineAndCharacter, parentAndChildShareLine: boolean, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {
172154
var useActualIndentation =
173155
(isDeclaration(current) || isStatement(current)) &&
@@ -306,7 +288,7 @@ module ts.formatting {
306288
return column;
307289
}
308290

309-
if (charCode === CharacterCodes.tab && !options.useTabs) {
291+
if (charCode === CharacterCodes.tab) {
310292
column += options.spacesPerTab;
311293
}
312294
else {
@@ -391,7 +373,9 @@ module ts.formatting {
391373
}
392374
}
393375

394-
/// checks if node is something that can contain tokens (except EOF) - filters out EOF tokens, Missing\Omitted expressions, empty SyntaxLists and expression statements that wrap any of listed nodes.
376+
/*
377+
* Checks if node is something that can contain tokens (except EOF) - filters out EOF tokens, Missing\Omitted expressions, empty SyntaxLists and expression statements that wrap any of listed nodes.
378+
*/
395379
function isCandidateNode(n: Node): boolean {
396380
if (n.kind === SyntaxKind.ExpressionStatement) {
397381
return isCandidateNode((<ExpressionStatement>n).expression);
@@ -456,8 +440,10 @@ module ts.formatting {
456440
}
457441
}
458442

459-
/// checks if node ends with 'expectedLastToken'.
460-
/// If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'.
443+
/*
444+
* Checks if node ends with 'expectedLastToken'.
445+
* If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'.
446+
*/
461447
function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean {
462448
var children = n.getChildren(sourceFile);
463449
if (children.length) {
@@ -472,7 +458,9 @@ module ts.formatting {
472458
return false;
473459
}
474460

475-
// this function is always called when position of the cursor is located after the node
461+
/*
462+
* This function is always called when position of the cursor is located after the node
463+
*/
476464
function isCompletedNode(n: Node, sourceFile: SourceFile): boolean {
477465
switch (n.kind) {
478466
case SyntaxKind.ClassDeclaration:

0 commit comments

Comments
 (0)