@@ -21,21 +21,6 @@ module ts.server {
2121 }
2222 return spaceCache [ n ] ;
2323 }
24-
25- export function generateIndentString ( n : number , editorOptions : EditorOptions ) : string {
26- if ( editorOptions . ConvertTabsToSpaces ) {
27- return generateSpaces ( n ) ;
28- } else {
29- var result = "" ;
30- for ( var i = 0 ; i < Math . floor ( n / editorOptions . TabSize ) ; i ++ ) {
31- result += "\t" ;
32- }
33- for ( var i = 0 ; i < n % editorOptions . TabSize ; i ++ ) {
34- result += " " ;
35- }
36- return result ;
37- }
38- }
3924
4025 interface FileStart {
4126 file : string ;
@@ -556,29 +541,31 @@ module ts.server {
556541 var editorOptions : ts . EditorOptions = {
557542 IndentSize : formatOptions . IndentSize ,
558543 TabSize : formatOptions . TabSize ,
559- NewLineCharacter : formatOptions . NewLineCharacter ,
544+ NewLineCharacter : "\n" ,
560545 ConvertTabsToSpaces : formatOptions . ConvertTabsToSpaces ,
561546 } ;
562- var preferredIndent = compilerService . languageService . getIndentationAtPosition ( file , position , editorOptions ) ;
563- var hasIndent = 0 ;
547+ var indentPosition =
548+ compilerService . languageService . getIndentationAtPosition ( file , position , editorOptions ) ;
564549 for ( var i = 0 , len = lineText . length ; i < len ; i ++ ) {
565550 if ( lineText . charAt ( i ) == " " ) {
566- hasIndent ++ ;
551+ indentPosition -- ;
567552 }
568553 else if ( lineText . charAt ( i ) == "\t" ) {
569- hasIndent + = editorOptions . TabSize ;
554+ indentPosition - = editorOptions . IndentSize ;
570555 }
571556 else {
572557 break ;
573558 }
574559 }
575- // i points to the first non whitespace character
576- if ( preferredIndent !== hasIndent ) {
577- var firstNoWhiteSpacePosition = lineInfo . offset + i ;
578- edits . push ( {
579- span : ts . createTextSpanFromBounds ( lineInfo . offset , firstNoWhiteSpacePosition ) ,
580- newText : generateIndentString ( preferredIndent , editorOptions )
581- } ) ;
560+ if ( indentPosition > 0 ) {
561+ var spaces = generateSpaces ( indentPosition ) ;
562+ edits . push ( { span : ts . createTextSpanFromBounds ( position , position ) , newText : spaces } ) ;
563+ }
564+ else if ( indentPosition < 0 ) {
565+ edits . push ( {
566+ span : ts . createTextSpanFromBounds ( position , position - indentPosition ) ,
567+ newText : ""
568+ } ) ;
582569 }
583570 }
584571 }
0 commit comments