99#include " CodeService/FormatElement/MinLineElement.h"
1010#include " CodeService/NameStyle/NameStyleRuleMatcher.h"
1111
12+ bool isNumber (std::string_view source)
13+ {
14+ for (auto c : source)
15+ {
16+ if (c > ' 9' || c < ' 0' )
17+ {
18+ return false ;
19+ }
20+ }
21+ return true ;
22+ }
23+
1224std::shared_ptr<LuaEditorConfig> LuaEditorConfig::LoadFromFile (const std::string& path)
1325{
1426 std::fstream fin (path, std::ios::in);
@@ -85,14 +97,14 @@ std::shared_ptr<LuaCodeStyleOptions> LuaEditorConfig::Generate(std::string_view
8597 patternKey.append (" #" ).append (sectionPattern);
8698 luaSections.push_back (section);
8799 }
88- // [{test.lua,lib.lua}]
89- else if (StringUtil::StartWith (sectionPattern," {" ) && StringUtil::EndWith (sectionPattern, " }" ))
100+ // [{test.lua,lib.lua}]
101+ else if (StringUtil::StartWith (sectionPattern, " {" ) && StringUtil::EndWith (sectionPattern, " }" ))
90102 {
91103 auto fileListText = sectionPattern.substr (1 , sectionPattern.size () - 2 );
92104 auto fileList = StringUtil::Split (fileListText, " ," );
93105 for (auto fileMatchUri : fileList)
94106 {
95- if (StringUtil::EndWith (fileUri,StringUtil::TrimSpace (fileMatchUri)))
107+ if (StringUtil::EndWith (fileUri, StringUtil::TrimSpace (fileMatchUri)))
96108 {
97109 patternKey.append (" #" ).append (sectionPattern);
98110 luaSections.push_back (section);
@@ -101,7 +113,7 @@ std::shared_ptr<LuaCodeStyleOptions> LuaEditorConfig::Generate(std::string_view
101113 }
102114 }
103115#ifndef NOT_SURPPORT_FILE_SYSTEM
104- // [lib/**.lua]
116+ // [lib/**.lua]
105117 else if (StringUtil::EndWith (sectionPattern, " **.lua" ))
106118 {
107119 std::string prefix = sectionPattern.substr (0 , sectionPattern.size () - 6 );
@@ -111,13 +123,13 @@ std::shared_ptr<LuaCodeStyleOptions> LuaEditorConfig::Generate(std::string_view
111123 std::filesystem::path file (fileUri);
112124 auto dirNormal = dirname.lexically_normal ();
113125 auto fileNormal = file.lexically_normal ();
114- if (StringUtil::StartWith (fileNormal.string (),dirNormal.string ()))
126+ if (StringUtil::StartWith (fileNormal.string (), dirNormal.string ()))
115127 {
116128 patternKey.append (" #" ).append (sectionPattern);
117129 luaSections.push_back (section);
118130 }
119131 }
120- // [aaa/bbb.lua]
132+ // [aaa/bbb.lua]
121133 else
122134 {
123135 std::filesystem::path workspace (_workspace);
@@ -129,7 +141,6 @@ std::shared_ptr<LuaCodeStyleOptions> LuaEditorConfig::Generate(std::string_view
129141 }
130142 }
131143#endif
132-
133144 }
134145
135146 if (_optionPatternMap.count (patternKey) > 0 )
@@ -174,27 +185,37 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
174185 }
175186 }
176187
177- if (configMap.count (" indent_size" ))
188+ if (configMap.count (" indent_size" )
189+ && isNumber (configMap.at (" indent_size" ))
190+ )
178191 {
179192 options->indent_size = std::stoi (configMap.at (" indent_size" ));
180193 }
181194
182- if (configMap.count (" tab_width" ))
195+ if (configMap.count (" tab_width" )
196+ && isNumber (configMap.at (" tab_width" )))
183197 {
184198 options->tab_width = std::stoi (configMap.at (" tab_width" ));
185199 }
186200
187- if (configMap.count (" continuation_indent_size" ))
201+ if (configMap.count (" continuation_indent_size" )
202+ && isNumber (configMap.at (" continuation_indent_size" )))
188203 {
189204 options->continuation_indent_size = std::stoi (configMap.at (" continuation_indent_size" ));
190205 }
191206
192- if (configMap.count (" local_assign_continuation_align_to_first_expression" ))
207+ if (configMap.count (" local_assign_continuation_align_to_first_expression" ))
193208 {
194209 options->local_assign_continuation_align_to_first_expression =
195210 configMap.at (" local_assign_continuation_align_to_first_expression" ) == " true" ;
196211 }
197212
213+ if (configMap.count (" table_field_continuation_align_to_first_sub_expression" ))
214+ {
215+ options->table_field_continuation_align_to_first_sub_expression =
216+ configMap.at (" table_field_continuation_align_to_first_sub_expression" ) == " true" ;
217+ }
218+
198219 if (configMap.count (" align_call_args" ))
199220 {
200221 options->align_call_args = configMap.at (" align_call_args" ) == " true" ;
@@ -212,23 +233,23 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
212233 configMap.at (" keep_one_space_between_table_and_bracket" ) == " true" ;
213234 }
214235
215- if (configMap.count (" keep_one_space_between_namedef_and_attribute" ))
236+ if (configMap.count (" keep_one_space_between_namedef_and_attribute" ))
216237 {
217238 options->keep_one_space_between_namedef_and_attribute =
218239 configMap.at (" keep_one_space_between_namedef_and_attribute" ) == " true" ;
219240 }
220241
221- if (configMap.count (" label_no_indent" ))
242+ if (configMap.count (" label_no_indent" ))
222243 {
223244 options->label_no_indent = configMap.at (" label_no_indent" ) == " true" ;
224245 }
225246
226- if (configMap.count (" do_statement_no_indent" ))
247+ if (configMap.count (" do_statement_no_indent" ))
227248 {
228249 options->do_statement_no_indent = configMap.at (" do_statement_no_indent" ) == " true" ;
229250 }
230251
231- if (configMap.count (" if_condition_no_continuation_indent" ))
252+ if (configMap.count (" if_condition_no_continuation_indent" ))
232253 {
233254 options->if_condition_no_continuation_indent = configMap.at (" if_condition_no_continuation_indent" ) == " true" ;
234255 }
@@ -238,6 +259,19 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
238259 options->align_table_field_to_first_field = configMap.at (" align_table_field_to_first_field" ) == " true" ;
239260 }
240261
262+ if (configMap.count (" max_continuous_line_distance" )
263+ && isNumber (configMap.at (" max_continuous_line_distance" )))
264+ {
265+ options->max_continuous_line_distance =
266+ std::stoi (configMap.at (" max_continuous_line_distance" ));
267+ }
268+
269+ if (configMap.count (" weak_alignment_rule" ))
270+ {
271+ options->weak_alignment_rule =
272+ configMap.at (" weak_alignment_rule" ) == " true" ;
273+ }
274+
241275 if (configMap.count (" continuous_assign_statement_align_to_equal_sign" ))
242276 {
243277 options->continuous_assign_statement_align_to_equal_sign =
@@ -263,7 +297,8 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
263297 }
264298 }
265299
266- if (configMap.count (" max_line_length" ))
300+ if (configMap.count (" max_line_length" )
301+ && isNumber (configMap.at (" max_line_length" )))
267302 {
268303 options->max_line_length = std::stoi (configMap.at (" max_line_length" ));
269304 }
@@ -340,7 +375,7 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
340375 }
341376 }
342377
343- if (options->indent_style == IndentStyle::Tab)
378+ if (options->indent_style == IndentStyle::Tab)
344379 {
345380 options->align_table_field_to_first_field = false ;
346381 }
0 commit comments