Skip to content

Commit b4dc8d9

Browse files
committed
clean code
1 parent 5630f38 commit b4dc8d9

File tree

25 files changed

+316
-387
lines changed

25 files changed

+316
-387
lines changed

CodeFormat/src/LuaFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void LuaFormat::SetDefaultStyle(std::map<std::string, std::string, std::less<>>
138138
if (keyValues.empty()) {
139139
return;
140140
}
141-
_defaultStyle.ParseFromMap(keyValues);
141+
_defaultStyle.Parse(keyValues);
142142
}
143143

144144
bool LuaFormat::Reformat() {

CodeFormatCore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ target_sources(CodeFormatCore
4040
src/RangeFormat/RangeFormatBuilder.cpp
4141
# typeFormat
4242
src/TypeFormat/LuaTypeFormat.cpp
43-
src/TypeFormat/LuaTypeFormatOptions.cpp
43+
src/TypeFormat/LuaTypeFormatFeatures.cpp
4444
# diagnostic
4545
src/Diagnostic/DiagnosticBuilder.cpp
4646
# diagnostic/nameStyle

CodeFormatCore/include/CodeFormatCore/Config/LuaStyle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LuaStyle {
1212
public:
1313
LuaStyle() = default;
1414

15-
void ParseFromMap(std::map<std::string, std::string, std::less<>> &configMap);
15+
void Parse(std::map<std::string, std::string, std::less<>> &configMap);
1616
// [basic]
1717
/*
1818
* 缩进风格

CodeFormatCore/include/CodeFormatCore/Format/Analyzer/FormatAnalyzerType.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ enum class FormatAnalyzerType {
66
IndentationAnalyzer,
77
AlignAnalyzer,
88
TokenAnalyzer,
9-
FormatDocAnalyze,
109
SemicolonAnalyzer,
10+
11+
// last
12+
FormatDocAnalyze,
1113
Count,
1214
};
1315

CodeFormatCore/include/CodeFormatCore/RangeFormat/RangeFormatBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "../Format/FormatBuilder.h"
3+
#include "CodeFormatCore/Format/FormatBuilder.h"
44

55
class RangeFormatBuilder : public FormatBuilder {
66
public:
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "../Format/FormatBuilder.h"
4-
#include "LuaTypeFormatOptions.h"
3+
#include "CodeFormatCore/Format/FormatBuilder.h"
4+
#include "LuaTypeFormatFeatures.h"
55

66
class LuaTypeFormat {
77
public:
@@ -10,13 +10,12 @@ class LuaTypeFormat {
1010
std::string Text;
1111
};
1212

13-
LuaTypeFormat(LuaTypeFormatOptions &typeOptions);
13+
explicit LuaTypeFormat(LuaTypeFormatFeatures &features);
1414

1515
void Analyze(
1616
std::string_view trigger, std::size_t line, std::size_t character,
1717
const LuaSyntaxTree &t,
18-
LuaStyle &style
19-
);
18+
LuaStyle &style);
2019

2120
std::vector<Result> GetResult();
2221

@@ -29,19 +28,16 @@ class LuaTypeFormat {
2928
std::size_t character,
3029
const LuaParseError &luaError,
3130
const LuaSyntaxTree &t,
32-
LuaStyle &style
33-
);
31+
LuaStyle &style);
3432

3533
void FormatLine(std::size_t line,
3634
std::size_t character,
3735
const LuaSyntaxTree &t,
38-
LuaStyle &style
39-
);
36+
LuaStyle &style);
4037

4138
void FormatByRange(FormatRange range,
4239
const LuaSyntaxTree &t,
43-
LuaStyle &style
44-
);
40+
LuaStyle &style);
4541

4642
void FixIndent(std::size_t line,
4743
std::size_t character,
@@ -50,7 +46,6 @@ class LuaTypeFormat {
5046

5147
void FixEndIndent(std::size_t line, std::size_t character);
5248

53-
LuaTypeFormatOptions _typeOptions;
49+
LuaTypeFormatFeatures _features;
5450
std::vector<Result> _results;
5551
};
56-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <map>
4+
#include <string>
5+
6+
class LuaTypeFormatFeatures {
7+
public:
8+
static LuaTypeFormatFeatures From(std::map<std::string, std::string, std::less<>> &features);
9+
10+
bool format_line = true;
11+
bool auto_complete_end = true;
12+
bool auto_complete_table_sep = true;
13+
bool fix_indent = true;
14+
};

CodeFormatCore/include/CodeFormatCore/TypeFormat/LuaTypeFormatOptions.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

CodeFormatCore/src/Config/LuaEditorConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ LuaStyle &LuaEditorConfig::Generate(std::string_view filePath) {
8585
auto &luaStyle = _styleMap.at(patternKey);
8686
for (auto i: patternSection) {
8787
auto &configMap = _sections[i].ConfigMap;
88-
luaStyle.ParseFromMap(configMap);
88+
luaStyle.Parse(configMap);
8989
}
9090

9191
return luaStyle;

CodeFormatCore/src/Config/LuaStyle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool IsNumber(std::string_view source) {
2424
op = std::stoi(configMap.at(#op)); \
2525
}
2626

27-
void LuaStyle::ParseFromMap(std::map<std::string, std::string, std::less<>> &configMap) {
27+
void LuaStyle::Parse(std::map<std::string, std::string, std::less<>> &configMap) {
2828
if (configMap.count("indent_style")) {
2929
if (configMap.at("indent_style") == "space") {
3030
indent_style = IndentStyle::Space;

0 commit comments

Comments
 (0)