Skip to content

Commit 10743f2

Browse files
committed
命名风格诊断信息更具可读性
1 parent 6606b51 commit 10743f2

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

CodeService/src/LuaCodeStyleOptions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ LuaCodeStyleOptions::LuaCodeStyleOptions()
3030
keep_line_after_local_or_assign_statement(std::make_shared<KeepLineElement>()),
3131
keep_line_after_function_define_statement(std::make_shared<KeepLineElement>(1)),
3232

33-
local_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
34-
function_param_name_style(std::make_shared<NameStyleRuleMatcher>()),
35-
function_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
36-
local_function_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
37-
table_field_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
38-
global_variable_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
39-
module_name_define_style(std::make_shared<NameStyleRuleMatcher>()),
40-
require_module_name_style(std::make_shared<NameStyleRuleMatcher>()),
41-
class_name_define_style(std::make_shared<NameStyleRuleMatcher>())
33+
local_name_define_style(std::make_shared<NameStyleRuleMatcher>("Local")),
34+
function_param_name_style(std::make_shared<NameStyleRuleMatcher>("Parameters")),
35+
function_name_define_style(std::make_shared<NameStyleRuleMatcher>("Class method")),
36+
local_function_name_define_style(std::make_shared<NameStyleRuleMatcher>("Local method")),
37+
table_field_name_define_style(std::make_shared<NameStyleRuleMatcher>("Table field")),
38+
global_variable_name_define_style(std::make_shared<NameStyleRuleMatcher>("Global")),
39+
module_name_define_style(std::make_shared<NameStyleRuleMatcher>("Module")),
40+
require_module_name_style(std::make_shared<NameStyleRuleMatcher>("Require module")),
41+
class_name_define_style(std::make_shared<NameStyleRuleMatcher>("Class"))
4242
{
4343
}

CodeService/src/LuaEditorConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void LuaEditorConfig::ParseFromSection(std::shared_ptr<LuaCodeStyleOptions> opti
395395
if (configMap.count(styleOption.first))
396396
{
397397
std::string value = configMap.at(styleOption.first);
398-
styleOption.second = NameStyleRuleMatcher::ParseFrom(value);
398+
styleOption.second->ParseRule(value);
399399
}
400400
}
401401

CodeService/src/NameStyle/NameStyleRuleMatcher.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ NameStyleRuleMatcher::NameStyleRule::NameStyleRule(NameStyleType type, std::vect
1616
{
1717
}
1818

19-
std::shared_ptr<NameStyleRuleMatcher> NameStyleRuleMatcher::ParseFrom(std::string_view rule)
20-
{
21-
auto matcher = std::make_shared<NameStyleRuleMatcher>();
22-
matcher->ParseRule(rule);
23-
return matcher;
24-
}
25-
26-
NameStyleRuleMatcher::NameStyleRuleMatcher()
19+
NameStyleRuleMatcher::NameStyleRuleMatcher(std::string_view name)
20+
: _name(name)
2721
{
2822
}
2923

@@ -129,7 +123,7 @@ void NameStyleRuleMatcher::Diagnosis(DiagnosisContext& ctx, std::shared_ptr<Chec
129123
}
130124
}
131125

132-
ctx.PushDiagnosis(format(LText("{} not match name rule {}"), checkElement->Node->GetText(), ruleMessage),
126+
ctx.PushDiagnosis(format(LText("Name '{}' does not match rule '{}', which require '{}'"), checkElement->Node->GetText(), _name, ruleMessage),
133127
checkElement->Node->GetTextRange());
134128
}
135129

include/CodeService/LuaCodeStyleEnum.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ enum class QuoteStyle
1212
Single,
1313
Double
1414
};
15+
16+
enum class CallArgParentheses
17+
{
18+
Keep,
19+
Remove,
20+
Always
21+
};
22+

include/CodeService/LuaCodeStyleOptions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class LuaCodeStyleOptions
3333

3434
QuoteStyle quote_style = QuoteStyle::None;
3535

36+
CallArgParentheses call_arg_parentheses = CallArgParentheses::Keep;
3637
/*
3738
* 延续行缩进
3839
*/
@@ -108,8 +109,6 @@ class LuaCodeStyleOptions
108109

109110
bool long_chain_expression_allow_one_space_after_colon = false;
110111

111-
bool call_expression_no_parentheses_when_only_one_string_or_table_arg = false;
112-
113112
std::string end_of_line = "\r\n";
114113

115114
bool insert_final_newline = true;

include/CodeService/NameStyle/NameStyleRuleMatcher.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class NameStyleRuleMatcher
2929
std::vector<std::string> Param;
3030
};
3131

32-
static std::shared_ptr<NameStyleRuleMatcher> ParseFrom(std::string_view rule);
33-
34-
NameStyleRuleMatcher();
32+
NameStyleRuleMatcher(std::string_view name);
3533

3634
void Diagnosis(DiagnosisContext& ctx, std::shared_ptr<CheckElement> checkElement);
3735

@@ -53,4 +51,5 @@ class NameStyleRuleMatcher
5351
static std::vector<std::string_view> SplitPart(std::string_view source);
5452

5553
std::vector<NameStyleRule> _rulers;
54+
std::string _name;
5655
};

0 commit comments

Comments
 (0)