1+ import { FormattingOptions } from 'vscode' ;
12import { FormattingLiterals , FormattingTags } from "../interfaces" ;
23import { CONFIG } from "../configuration" ;
34
@@ -19,7 +20,7 @@ export class BeautifySmarty {
1920 end : new Set ( [ "block" , "capture" , "for" , "foreach" , "function" , "if" , "literal" , "section" , "setfilter" , "strip" , "while" ] )
2021 } ;
2122
22- public beautify ( docText : String ) : string {
23+ public beautify ( docText : String , options : FormattingOptions ) : string {
2324 const embeddedRegExp : RegExp = / ( < (?: s c r i p t | s t y l e ) [ \s \S ] * ?> ) ( [ \s \S ] * ?) ( < \/ (?: s c r i p t | s t y l e ) > ) / g;
2425 const smartyRegExp : RegExp = / ^ (?: \t | ) * ( .* { { ? [ ^ } \n \s ] } ? .* ) $ / gm;
2526
@@ -34,8 +35,8 @@ export class BeautifySmarty {
3435 } ) ;
3536
3637 // format using js-beautify
37- const beautifyOptions = this . getBeautifyOptions ( ) ;
38- let formatted = beautify ( docText , beautifyOptions ) ;
38+ const beautifyConfig = this . beautifyConfig ( options ) ;
39+ let formatted = beautify ( docText , beautifyConfig ) ;
3940
4041 // split into lines
4142 const literalPattern : string = Object . values ( this . literals ) . map ( r => r . source ) . join ( "|" ) ;
@@ -54,7 +55,7 @@ export class BeautifySmarty {
5455 }
5556 }
5657
57- const indent_char = beautifyOptions . indent_with_tabs ? "\t" : " " . repeat ( beautifyOptions . indent_size ) ;
58+ const indent_char = beautifyConfig . indent_with_tabs ? "\t" : " " . repeat ( beautifyConfig . indent_size ) ;
5859 const region = / { { ? ( \/ ? ) ( \w + ) .* ?} } ? / g;
5960
6061 const startedRegions = [ ] ;
@@ -117,10 +118,10 @@ export class BeautifySmarty {
117118 return formatted ;
118119 }
119120
120- private getBeautifyOptions ( ) {
121- const options = {
122- indent_size : CONFIG . tabSize ,
123- indent_with_tabs : ! CONFIG . insertSpaces ,
121+ private beautifyConfig ( options : FormattingOptions ) {
122+ const config = {
123+ indent_size : options . tabSize ,
124+ indent_with_tabs : ! options . insertSpaces ,
124125 indent_handlebars : false ,
125126 indent_inner_html : CONFIG . indentInnerHtml ,
126127 max_preserve_newlines : CONFIG . maxPreserveNewLines ,
@@ -138,7 +139,7 @@ export class BeautifySmarty {
138139 templating : [ "smarty" ]
139140 } ;
140141
141- return options ;
142+ return config ;
142143 }
143144
144145}
0 commit comments