|
4 | 4 | #include "CodeService/FormatElement/MinLineElement.h" |
5 | 5 | #include "CodeService/FormatElement/KeepLineElement.h" |
6 | 6 |
|
7 | | -std::shared_ptr<LuaCodeStyleOptions> LuaCodeStyleOptions::ParseFromEditorConfig( |
8 | | - std::shared_ptr<LuaEditorConfig> editorConfig) |
9 | | -{ |
10 | | - auto options = std::make_shared<LuaCodeStyleOptions>(); |
11 | | - if (editorConfig->Exist("indent_style")) |
12 | | - { |
13 | | - if (editorConfig->Get("indent_style") == "space") |
14 | | - { |
15 | | - options->indent_style = IndentStyle::Space; |
16 | | - } |
17 | | - else if (editorConfig->Get("indent_style") == "tab") |
18 | | - { |
19 | | - options->indent_style = IndentStyle::Tab; |
20 | | - } |
21 | | - } |
22 | | - |
23 | | - if (editorConfig->Exist("indent_size")) |
24 | | - { |
25 | | - options->indent_size = std::stoi(editorConfig->Get("indent_size")); |
26 | | - } |
27 | | - |
28 | | - if (editorConfig->Exist("tab_width")) |
29 | | - { |
30 | | - options->tab_width = std::stoi(editorConfig->Get("tab_width")); |
31 | | - } |
32 | | - |
33 | | - |
34 | | - if (editorConfig->Exist("continuation_indent_size")) |
35 | | - { |
36 | | - options->continuation_indent_size = std::stoi(editorConfig->Get("continuation_indent_size")); |
37 | | - } |
38 | | - |
39 | | - if (editorConfig->Exist("align_call_args")) |
40 | | - { |
41 | | - options->align_call_args = editorConfig->Get("align_call_args") == "true"; |
42 | | - } |
43 | | - |
44 | | - if (editorConfig->Exist("keep_one_space_between_call_args_and_bracket")) |
45 | | - { |
46 | | - options->keep_one_space_between_call_args_and_bracket = |
47 | | - editorConfig->Get("keep_one_space_between_call_args_and_bracket") == "true"; |
48 | | - } |
49 | | - |
50 | | - if (editorConfig->Exist("keep_one_space_between_table_and_bracket")) |
51 | | - { |
52 | | - options->keep_one_space_between_table_and_bracket = |
53 | | - editorConfig->Get("keep_one_space_between_table_and_bracket") == "true"; |
54 | | - } |
55 | | - |
56 | | - if (editorConfig->Exist("align_table_field_to_first_field")) |
57 | | - { |
58 | | - options->align_table_field_to_first_field = editorConfig->Get("align_table_field_to_first_field") == "true"; |
59 | | - } |
60 | | - |
61 | | - if (editorConfig->Exist("continuous_assign_statement_align_to_equal_sign")) |
62 | | - { |
63 | | - options->continuous_assign_statement_align_to_equal_sign = |
64 | | - editorConfig->Get("continuous_assign_statement_align_to_equal_sign") == "true"; |
65 | | - } |
66 | | - |
67 | | - if (editorConfig->Exist("continuous_assign_table_field_align_to_equal_sign")) |
68 | | - { |
69 | | - options->continuous_assign_table_field_align_to_equal_sign = |
70 | | - editorConfig->Get("continuous_assign_table_field_align_to_equal_sign") == "true"; |
71 | | - } |
72 | | - |
73 | | - if (editorConfig->Exist("end_of_line")) |
74 | | - { |
75 | | - auto lineSeparatorSymbol = editorConfig->Get("end_of_line"); |
76 | | - if (lineSeparatorSymbol == "crlf") |
77 | | - { |
78 | | - options->end_of_line = "\r\n"; |
79 | | - } |
80 | | - else if (lineSeparatorSymbol == "lf") |
81 | | - { |
82 | | - options->end_of_line = "\n"; |
83 | | - } |
84 | | - } |
85 | | - |
86 | | - if (editorConfig->Exist("max_line_length")) |
87 | | - { |
88 | | - options->max_line_length = std::stoi(editorConfig->Get("max_line_length")); |
89 | | - } |
90 | | - |
91 | | - if (editorConfig->Exist("enable_check_codestyle")) |
92 | | - { |
93 | | - options->enable_check_codestyle = editorConfig->Get("enable_check_codestyle") == "true"; |
94 | | - } |
95 | | - |
96 | | - std::vector<std::pair<std::string, std::shared_ptr<FormatElement>&>> fieldList = { |
97 | | - {"keep_line_after_if_statement", options->keep_line_after_if_statement}, |
98 | | - {"keep_line_after_do_statement", options->keep_line_after_do_statement}, |
99 | | - {"keep_line_after_while_statement", options->keep_line_after_while_statement}, |
100 | | - {"keep_line_after_repeat_statement", options->keep_line_after_repeat_statement}, |
101 | | - {"keep_line_after_for_statement", options->keep_line_after_for_statement}, |
102 | | - {"keep_line_after_local_or_assign_statement", options->keep_line_after_local_or_assign_statement}, |
103 | | - {"keep_line_after_function_define_statement", options->keep_line_after_function_define_statement} |
104 | | - }; |
105 | | - std::regex minLineRegex = std::regex(R"(minLine:\s*(\d+))"); |
106 | | - std::regex keepLineRegex = std::regex(R"(keepLine:\s*(\d+))"); |
107 | | - for (auto& keepLineOption : fieldList) |
108 | | - { |
109 | | - if (editorConfig->Exist(keepLineOption.first)) |
110 | | - { |
111 | | - std::string value = editorConfig->Get(keepLineOption.first); |
112 | | - if (value == "keepLine") |
113 | | - { |
114 | | - keepLineOption.second = std::make_shared<KeepLineElement>(); |
115 | | - continue; |
116 | | - } |
117 | | - std::smatch m; |
118 | | - |
119 | | - if (std::regex_search(value, m, minLineRegex)) |
120 | | - { |
121 | | - keepLineOption.second = std::make_shared<MinLineElement>(std::stoi(m.str(1))); |
122 | | - continue; |
123 | | - } |
124 | | - |
125 | | - if (std::regex_search(value, m, keepLineRegex)) |
126 | | - { |
127 | | - keepLineOption.second = std::make_shared<KeepLineElement>(std::stoi(m.str(1))); |
128 | | - } |
129 | | - } |
130 | | - } |
131 | | - |
132 | | - if (editorConfig->Exist("insert_final_newline")) |
133 | | - { |
134 | | - options->insert_final_newline = editorConfig->Get("insert_final_newline") == "true"; |
135 | | - } |
136 | | - |
137 | | - if (editorConfig->Exist("enable_name_style_check")) |
138 | | - { |
139 | | - options->enable_name_style_check = editorConfig->Get("enable_name_style_check") == "true"; |
140 | | - } |
141 | | - |
142 | | - std::vector<std::pair<std::string, NameStyle&>> styleList = { |
143 | | - {"local_name_define_style", options->local_name_define_style}, |
144 | | - {"function_name_define_style", options->function_name_define_style}, |
145 | | - {"table_field_name_define_style", options->table_field_name_define_style}, |
146 | | - }; |
147 | | - |
148 | | - for (auto& styleOption : styleList) |
149 | | - { |
150 | | - if (editorConfig->Exist(styleOption.first)) |
151 | | - { |
152 | | - std::string value = editorConfig->Get(styleOption.first); |
153 | | - if (value == "off") |
154 | | - { |
155 | | - styleOption.second = NameStyle::Off; |
156 | | - } |
157 | | - else if(value == "snake_case") |
158 | | - { |
159 | | - styleOption.second = NameStyle::SnakeCase; |
160 | | - } |
161 | | - else if(value == "camel_case") |
162 | | - { |
163 | | - styleOption.second = NameStyle::CamelCase; |
164 | | - } |
165 | | - else if(value == "pascal_case") |
166 | | - { |
167 | | - styleOption.second = NameStyle::PascalCase; |
168 | | - } |
169 | | - } |
170 | | - } |
171 | | - |
172 | | - return options; |
173 | | -} |
174 | | - |
175 | 7 | LuaCodeStyleOptions::LuaCodeStyleOptions() |
176 | 8 | : |
177 | 9 | keep_line_after_if_statement(std::make_shared<MinLineElement>(1)), |
|
0 commit comments