Skip to content

Commit fab3d06

Browse files
committed
complete #94
1 parent e1d532e commit fab3d06

File tree

7 files changed

+203
-235
lines changed

7 files changed

+203
-235
lines changed

CodeService/src/Diagnostic/CodeStyle/CodeStyleChecker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ void CodeStyleChecker::BasicResolve(LuaSyntaxNode syntaxNode, const LuaSyntaxTre
8080
if (syntaxNode.GetTokenKind(t) == TK_STRING) {
8181
auto text = syntaxNode.GetText(t);
8282
if (text.size() >= 2
83-
&& text.front() == '\"') {
83+
&& text.front() == '\"'
84+
&& !string_util::ExistDel('\'', text)) {
8485
d.PushDiagnostic(DiagnosticType::StringQuote, textRange,
8586
LText("\" should be \' ")
8687
);
@@ -93,7 +94,8 @@ void CodeStyleChecker::BasicResolve(LuaSyntaxNode syntaxNode, const LuaSyntaxTre
9394
if (syntaxNode.GetTokenKind(t) == TK_STRING) {
9495
auto text = syntaxNode.GetText(t);
9596
if (text.size() >= 2
96-
&& text.front() == '\'') {
97+
&& text.front() == '\''
98+
&& !string_util::ExistDel('\"', text)) {
9799
d.PushDiagnostic(DiagnosticType::StringQuote, textRange,
98100
LText("\' should be \" ")
99101
);

CodeService/src/Format/Analyzer/LineBreakAnalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ LineBreakAnalyzer::Query(FormatState &f, LuaSyntaxNode &syntaxNode, const LuaSyn
207207
auto relationNode = LuaSyntaxNode(lineBreakData.Data.Index);
208208
auto guessLineWidth = lineWidth + syntaxNode.GetFirstLineWidth(t) + relationNode.GetFirstLineWidth(t);
209209
if (guessLineWidth > style.max_line_length) {
210-
resolve.SetNextLineBreak(LineSpace(1));
210+
resolve.SetNextLineBreak(LineSpace(1, LineBreakReason::ExceedMaxLine));
211211
}
212212
break;
213213
}

CodeService/src/Format/FormatBuilder.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "LuaParser/Lexer/LuaTokenTypeDetail.h"
33
#include "CodeService/Format/Analyzer/AlignAnalyzer.h"
44
#include "CodeService/Format/Analyzer/IndentationAnalyzer.h"
5+
#include "Util/StringUtil.h"
56

67

78
FormatBuilder::FormatBuilder(LuaStyle &style) {
@@ -41,21 +42,6 @@ void FormatBuilder::WriteSyntaxNode(LuaSyntaxNode &syntaxNode, const LuaSyntaxTr
4142
}
4243
}
4344

44-
bool ExistDel(char del, std::string_view text) {
45-
text = text.substr(1, text.size() - 2);
46-
char ch = '\0';
47-
for (std::size_t i = 0; i < text.size(); ++i) {
48-
ch = text[i];
49-
if (ch == del) {
50-
return true;
51-
} else if (ch == '\\') {
52-
++i;
53-
}
54-
}
55-
56-
return false;
57-
}
58-
5945
void FormatBuilder::DoResolve(LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t, FormatResolve &resolve) {
6046
if (syntaxNode.IsToken(t)) {
6147
if (_state.IsNewLine()) {
@@ -104,7 +90,7 @@ void FormatBuilder::DoResolve(LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t,
10490
auto del = '\'';
10591
if (text.size() >= 2
10692
&& text.front() == '\"'
107-
&& !ExistDel(del, text)) {
93+
&& !string_util::ExistDel(del, text)) {
10894
WriteChar(del);
10995
WriteText(text.substr(1, text.size() - 2));
11096
WriteChar(del);
@@ -121,7 +107,7 @@ void FormatBuilder::DoResolve(LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t,
121107
auto del = '\"';
122108
if (text.size() >= 2
123109
&& text.front() == '\''
124-
&& !ExistDel(del, text)) {
110+
&& !string_util::ExistDel(del, text)) {
125111
WriteChar(del);
126112
WriteText(text.substr(1, text.size() - 2));
127113
WriteChar(del);

0 commit comments

Comments
 (0)