@@ -10,24 +10,24 @@ namespace ts.formatting {
1010
1111 export function getIndentation ( position : number , sourceFile : SourceFile , options : EditorOptions ) : number {
1212 if ( position > sourceFile . text . length ) {
13- return 0 ; // past EOF
13+ return getBaseIndentation ( options ) ; // past EOF
1414 }
1515
1616 // no indentation when the indent style is set to none,
1717 // so we can return fast
1818 if ( options . IndentStyle === IndentStyle . None ) {
19- return 0 ;
19+ return getBaseIndentation ( options ) ;
2020 }
2121
2222 const precedingToken = findPrecedingToken ( position , sourceFile ) ;
2323 if ( ! precedingToken ) {
24- return 0 ;
24+ return getBaseIndentation ( options ) ;
2525 }
2626
2727 // no indentation in string \regex\template literals
2828 const precedingTokenIsLiteral = isStringOrRegularExpressionOrTemplateLiteral ( precedingToken . kind ) ;
2929 if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
30- return 0 ;
30+ return getBaseIndentation ( options ) ;
3131 }
3232
3333 const lineAtPosition = sourceFile . getLineAndCharacterOfPosition ( position ) . line ;
@@ -96,13 +96,17 @@ namespace ts.formatting {
9696 }
9797
9898 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 ) ;
101101 }
102102
103103 return getIndentationForNodeWorker ( current , currentStart , /*ignoreActualIndentationRange*/ undefined , indentationDelta , sourceFile , options ) ;
104104 }
105105
106+ function getBaseIndentation ( options : EditorOptions ) {
107+ return options . BaseIndentSize || 0 ;
108+ }
109+
106110 export function getIndentationForNode ( n : Node , ignoreActualIndentationRange : TextRange , sourceFile : SourceFile , options : FormatCodeOptions ) : number {
107111 const start = sourceFile . getLineAndCharacterOfPosition ( n . getStart ( sourceFile ) ) ;
108112 return getIndentationForNodeWorker ( n , start , ignoreActualIndentationRange , /*indentationDelta*/ 0 , sourceFile , options ) ;
@@ -162,7 +166,7 @@ namespace ts.formatting {
162166 parent = current . parent ;
163167 }
164168
165- return indentationDelta ;
169+ return indentationDelta + getBaseIndentation ( options ) ;
166170 }
167171
168172
0 commit comments