@@ -202,7 +202,7 @@ namespace FourSlash {
202202 // Whether or not we should format on keystrokes
203203 public enableFormatting = true ;
204204
205- public formatCodeOptions : ts . FormatCodeOptions ;
205+ public formatCodeSettings : ts . FormatCodeSettings ;
206206
207207 private inputFiles : ts . Map < string > = { } ; // Map between inputFile's fileName and its content for easily looking up when resolving references
208208
@@ -309,22 +309,22 @@ namespace FourSlash {
309309 Harness . Compiler . getDefaultLibrarySourceFile ( ) . text , /*isRootFile*/ false ) ;
310310 }
311311
312- this . formatCodeOptions = {
313- IndentSize : 4 ,
314- TabSize : 4 ,
315- NewLineCharacter : Harness . IO . newLine ( ) ,
316- ConvertTabsToSpaces : true ,
317- IndentStyle : ts . IndentStyle . Smart ,
318- InsertSpaceAfterCommaDelimiter : true ,
319- InsertSpaceAfterSemicolonInForStatements : true ,
320- InsertSpaceBeforeAndAfterBinaryOperators : true ,
321- InsertSpaceAfterKeywordsInControlFlowStatements : true ,
322- InsertSpaceAfterFunctionKeywordForAnonymousFunctions : false ,
323- InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis : false ,
324- InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets : false ,
325- InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces : false ,
326- PlaceOpenBraceOnNewLineForFunctions : false ,
327- PlaceOpenBraceOnNewLineForControlBlocks : false ,
312+ this . formatCodeSettings = {
313+ indentSize : 4 ,
314+ tabSize : 4 ,
315+ newLineCharacter : Harness . IO . newLine ( ) ,
316+ convertTabsToSpaces : true ,
317+ indentStyle : ts . IndentStyle . Smart ,
318+ insertSpaceAfterCommaDelimiter : true ,
319+ insertSpaceAfterSemicolonInForStatements : true ,
320+ insertSpaceBeforeAndAfterBinaryOperators : true ,
321+ insertSpaceAfterKeywordsInControlFlowStatements : true ,
322+ insertSpaceAfterFunctionKeywordForAnonymousFunctions : false ,
323+ insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis : false ,
324+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets : false ,
325+ insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces : false ,
326+ placeOpenBraceOnNewLineForFunctions : false ,
327+ placeOpenBraceOnNewLineForControlBlocks : false ,
328328 } ;
329329
330330 // Open the first file by default
@@ -1278,7 +1278,7 @@ namespace FourSlash {
12781278
12791279 // Handle post-keystroke formatting
12801280 if ( this . enableFormatting ) {
1281- const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeOptions ) ;
1281+ const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
12821282 if ( edits . length ) {
12831283 offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
12841284 // this.checkPostEditInvariants();
@@ -1316,7 +1316,7 @@ namespace FourSlash {
13161316
13171317 // Handle post-keystroke formatting
13181318 if ( this . enableFormatting ) {
1319- const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeOptions ) ;
1319+ const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
13201320 if ( edits . length ) {
13211321 offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
13221322 }
@@ -1369,7 +1369,7 @@ namespace FourSlash {
13691369
13701370 // Handle post-keystroke formatting
13711371 if ( this . enableFormatting ) {
1372- const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeOptions ) ;
1372+ const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , offset , ch , this . formatCodeSettings ) ;
13731373 if ( edits . length ) {
13741374 offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
13751375 // this.checkPostEditInvariants();
@@ -1395,7 +1395,7 @@ namespace FourSlash {
13951395
13961396 // Handle formatting
13971397 if ( this . enableFormatting ) {
1398- const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , offset , this . formatCodeOptions ) ;
1398+ const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , offset , this . formatCodeSettings ) ;
13991399 if ( edits . length ) {
14001400 offset += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
14011401 this . checkPostEditInvariants ( ) ;
@@ -1469,30 +1469,30 @@ namespace FourSlash {
14691469 return runningOffset ;
14701470 }
14711471
1472- public copyFormatOptions ( ) : ts . FormatCodeOptions {
1473- return ts . clone ( this . formatCodeOptions ) ;
1472+ public copyFormatOptions ( ) : ts . FormatCodeSettings {
1473+ return ts . clone ( this . formatCodeSettings ) ;
14741474 }
14751475
1476- public setFormatOptions ( formatCodeOptions : ts . FormatCodeOptions ) : ts . FormatCodeOptions {
1477- const oldFormatCodeOptions = this . formatCodeOptions ;
1478- this . formatCodeOptions = formatCodeOptions ;
1476+ public setFormatOptions ( formatCodeOptions : ts . FormatCodeOptions | ts . FormatCodeSettings ) : ts . FormatCodeSettings {
1477+ const oldFormatCodeOptions = this . formatCodeSettings ;
1478+ this . formatCodeSettings = ts . toEditorSettings ( formatCodeOptions ) ;
14791479 return oldFormatCodeOptions ;
14801480 }
14811481
14821482 public formatDocument ( ) {
1483- const edits = this . languageService . getFormattingEditsForDocument ( this . activeFile . fileName , this . formatCodeOptions ) ;
1483+ const edits = this . languageService . getFormattingEditsForDocument ( this . activeFile . fileName , this . formatCodeSettings ) ;
14841484 this . currentCaretPosition += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
14851485 this . fixCaretPosition ( ) ;
14861486 }
14871487
14881488 public formatSelection ( start : number , end : number ) {
1489- const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , end , this . formatCodeOptions ) ;
1489+ const edits = this . languageService . getFormattingEditsForRange ( this . activeFile . fileName , start , end , this . formatCodeSettings ) ;
14901490 this . currentCaretPosition += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
14911491 this . fixCaretPosition ( ) ;
14921492 }
14931493
14941494 public formatOnType ( pos : number , key : string ) {
1495- const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , pos , key , this . formatCodeOptions ) ;
1495+ const edits = this . languageService . getFormattingEditsAfterKeystroke ( this . activeFile . fileName , pos , key , this . formatCodeSettings ) ;
14961496 this . currentCaretPosition += this . applyEdits ( this . activeFile . fileName , edits , /*isFormattingEdit*/ true ) ;
14971497 this . fixCaretPosition ( ) ;
14981498 }
@@ -1621,8 +1621,8 @@ namespace FourSlash {
16211621
16221622 private getIndentation ( fileName : string , position : number , indentStyle : ts . IndentStyle ) : number {
16231623
1624- const formatOptions = ts . clone ( this . formatCodeOptions ) ;
1625- formatOptions . IndentStyle = indentStyle ;
1624+ const formatOptions = ts . clone ( this . formatCodeSettings ) ;
1625+ formatOptions . indentStyle = indentStyle ;
16261626
16271627 return this . languageService . getIndentationAtPosition ( fileName , position , formatOptions ) ;
16281628 }
@@ -3226,7 +3226,7 @@ namespace FourSlashInterface {
32263226 this . state . formatDocument ( ) ;
32273227 }
32283228
3229- public copyFormatOptions ( ) : ts . FormatCodeOptions {
3229+ public copyFormatOptions ( ) : ts . FormatCodeSettings {
32303230 return this . state . copyFormatOptions ( ) ;
32313231 }
32323232
@@ -3246,7 +3246,7 @@ namespace FourSlashInterface {
32463246 public setOption ( name : string , value : string ) : void ;
32473247 public setOption ( name : string , value : boolean ) : void ;
32483248 public setOption ( name : string , value : any ) : void {
3249- this . state . formatCodeOptions [ name ] = value ;
3249+ ( < any > this . state . formatCodeSettings ) [ name ] = value ;
32503250 }
32513251 }
32523252
0 commit comments