@@ -57,13 +57,13 @@ void CodeFormat::SupportNonStandardSymbol() {
5757 _supportNonStandardSymbol = true ;
5858}
5959
60- char *CodeFormat::Reformat (const std::string &uri, std::string &&text) {
60+ char *CodeFormat::Reformat (const std::string &uri, std::string &&text, FormattingOptions options ) {
6161 auto file = LuaSource::From (std::move (text));
6262 LuaLexer luaLexer (file);
63- if (_supportNonStandardSymbol) {
63+ if (_supportNonStandardSymbol || options. non_standard_symbol ) {
6464 luaLexer.SupportNonStandardSymbol ();
6565 }
66- if (_supportCLikeComments) {
66+ if (_supportCLikeComments || options. non_standard_symbol ) {
6767 luaLexer.SupportCLikeComments ();
6868 }
6969
@@ -80,7 +80,7 @@ char *CodeFormat::Reformat(const std::string &uri, std::string &&text) {
8080 t.BuildTree (p);
8181
8282 LuaStyle style = GetStyle (uri);
83-
83+ SetupStyle (style, options);
8484 FormatBuilder f (style);
8585
8686 auto result = f.GetFormatResult (t);
@@ -92,13 +92,13 @@ char *CodeFormat::Reformat(const std::string &uri, std::string &&text) {
9292}
9393
9494Result<RangeFormatResult> CodeFormat::RangeFormat (const std::string &uri, FormatRange &range,
95- std::string &&text) {
95+ std::string &&text, FormattingOptions options ) {
9696 auto file = std::make_shared<LuaSource>(std::move (text));
9797 LuaLexer luaLexer (file);
98- if (_supportNonStandardSymbol) {
98+ if (_supportNonStandardSymbol || options. non_standard_symbol ) {
9999 luaLexer.SupportNonStandardSymbol ();
100100 }
101- if (_supportCLikeComments) {
101+ if (_supportCLikeComments || options. non_standard_symbol ) {
102102 luaLexer.SupportCLikeComments ();
103103 }
104104
@@ -115,6 +115,7 @@ Result<RangeFormatResult> CodeFormat::RangeFormat(const std::string &uri, Format
115115 t.BuildTree (p);
116116
117117 LuaStyle style = GetStyle (uri);
118+ SetupStyle (style, options);
118119
119120 RangeFormatBuilder f (style, range);
120121
@@ -125,13 +126,25 @@ Result<RangeFormatResult> CodeFormat::RangeFormat(const std::string &uri, Format
125126 std::copy (formattedText.begin (), formattedText.end (), ptr);
126127 ptr[formattedText.size ()] = ' \0 ' ;// [formattedText.size()] = '\0'
127128 return RangeFormatResult{
128- static_cast <int >(range.StartLine ),
129- static_cast <int >(range.StartCol ),
130- static_cast <int >(range.EndLine ),
131- static_cast <int >(range.EndCol ),
129+ static_cast <int32_t >(range.StartLine ),
130+ static_cast <int32_t >(range.StartCol ),
131+ static_cast <int32_t >(range.EndLine ),
132+ static_cast <int32_t >(range.EndCol ),
132133 ptr};
133134}
134135
136+ void CodeFormat::SetupStyle (LuaStyle &style, const FormattingOptions &options) {
137+ if (options.use_tabs ) {
138+ style.indent_style = IndentStyle::Tab;
139+ style.tab_width = options.indent_size ;
140+ } else {
141+ style.indent_style = IndentStyle::Space;
142+ style.indent_size = options.indent_size ;
143+ }
144+
145+ style.insert_final_newline = options.insert_final_newline ;
146+ }
147+
135148Result<std::vector<LuaTypeFormat::Result>>
136149CodeFormat::TypeFormat (const std::string &uri, std::size_t line, std::size_t character, std::string &&text) {
137150 auto file = std::make_shared<LuaSource>(std::move (text));
@@ -157,7 +170,6 @@ CodeFormat::TypeFormat(const std::string &uri, std::size_t line, std::size_t cha
157170
158171 LuaStyle style = GetStyle (uri);
159172
160-
161173 LuaTypeFormatFeatures typeFormatOptions;
162174 typeFormatOptions.auto_complete_end = false ;
163175 LuaTypeFormat tf (typeFormatOptions);
0 commit comments