@@ -10,24 +10,24 @@ namespace ts.formatting {
10
10
11
11
export function getIndentation ( position : number , sourceFile : SourceFile , options : EditorOptions ) : number {
12
12
if ( position > sourceFile . text . length ) {
13
- return 0 ; // past EOF
13
+ return getBaseIndentation ( options ) ; // past EOF
14
14
}
15
15
16
16
// no indentation when the indent style is set to none,
17
17
// so we can return fast
18
18
if ( options . IndentStyle === IndentStyle . None ) {
19
- return 0 ;
19
+ return getBaseIndentation ( options ) ;
20
20
}
21
21
22
22
const precedingToken = findPrecedingToken ( position , sourceFile ) ;
23
23
if ( ! precedingToken ) {
24
- return 0 ;
24
+ return getBaseIndentation ( options ) ;
25
25
}
26
26
27
27
// no indentation in string \regex\template literals
28
28
const precedingTokenIsLiteral = isStringOrRegularExpressionOrTemplateLiteral ( precedingToken . kind ) ;
29
29
if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
30
- return 0 ;
30
+ return getBaseIndentation ( options ) ;
31
31
}
32
32
33
33
const lineAtPosition = sourceFile . getLineAndCharacterOfPosition ( position ) . line ;
@@ -96,13 +96,17 @@ namespace ts.formatting {
96
96
}
97
97
98
98
if ( ! current ) {
99
- // no parent was found - return 0 to be indented on the level of SourceFile
100
- return 0 ;
99
+ // no parent was found - return the base indentation of the SourceFile
100
+ return getBaseIndentation ( options ) ;
101
101
}
102
102
103
103
return getIndentationForNodeWorker ( current , currentStart , /*ignoreActualIndentationRange*/ undefined , indentationDelta , sourceFile , options ) ;
104
104
}
105
105
106
+ function getBaseIndentation ( options : EditorOptions ) {
107
+ return options . BaseIndentSize || 0 ;
108
+ }
109
+
106
110
export function getIndentationForNode ( n : Node , ignoreActualIndentationRange : TextRange , sourceFile : SourceFile , options : FormatCodeOptions ) : number {
107
111
const start = sourceFile . getLineAndCharacterOfPosition ( n . getStart ( sourceFile ) ) ;
108
112
return getIndentationForNodeWorker ( n , start , ignoreActualIndentationRange , /*indentationDelta*/ 0 , sourceFile , options ) ;
@@ -162,7 +166,7 @@ namespace ts.formatting {
162
166
parent = current . parent ;
163
167
}
164
168
165
- return indentationDelta ;
169
+ return indentationDelta + getBaseIndentation ( options ) ;
166
170
}
167
171
168
172
0 commit comments