Skip to content

Commit 4a475be

Browse files
committed
codeService去掉stdoptional
1 parent a313c19 commit 4a475be

32 files changed

+135
-138
lines changed

CodeFormatServer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ target_sources(CodeFormatServer
5050

5151
#Service/AstUtil
5252
${CodeFormatServer_SOURCE_DIR}/src/Service/AstUtil/ModuleFinder.cpp
53+
${CodeFormatServer_SOURCE_DIR}/src/Service/AstUtil/AstPattern.cpp
5354

5455
#service
5556
${CodeFormatServer_SOURCE_DIR}/src/Service/Service.cpp
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "CodeFormatServer/Service/AstUtil/AstPattern.h"
2+
3+
AstPattern::AstPattern(LuaAstNodeType baseType)
4+
{
5+
}
6+
7+
bool AstPattern::Match(std::shared_ptr<LuaAstNode> node)
8+
{
9+
return true;
10+
}

CodeFormatServer/src/Service/CompletionService.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ void CompletionService::Start()
1515
AddCompleteContributor({LuaAstNodeType::NameIdentify},
1616
std::bind(&ModuleService::GetModuleCompletions, GetService<ModuleService>().get(),
1717
_1, _2, _3, _4));
18-
// AddCompleteContributor({LuaAstNodeType::LiteralExpression},
18+
// AddCompleteContributor({
19+
// LuaAstNodeType::LiteralExpression,
20+
// LuaAstNodeType::Expression,
21+
// LuaAstNodeType::CallArgList,
22+
// LuaAstNodeType::CallExpression,
23+
//
24+
//
25+
// },
1926
// std::bind(&ModuleService::GetRequireCompletions, GetService<ModuleService>().get(),
2027
// _1, _2, _3, _4)
2128
// );

CodeFormatServer/src/Service/ModuleService.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ std::vector<vscode::CompletionItem> ModuleService::GetModuleCompletions(std::sha
289289
return result;
290290
}
291291

292-
// std::vector<vscode::CompletionItem> ModuleService::GetRequireCompletions(std::shared_ptr<LuaAstNode> expression,
293-
// std::shared_ptr<LuaParser> parser,
294-
// std::shared_ptr<LuaCodeStyleOptions> options,
295-
// std::string_view uri)
296-
// {
297-
//
298-
// }
292+
std::vector<vscode::CompletionItem> ModuleService::GetRequireCompletions(std::shared_ptr<LuaAstNode> expression,
293+
std::shared_ptr<LuaParser> parser,
294+
std::shared_ptr<LuaCodeStyleOptions> options,
295+
std::string_view uri)
296+
{
297+
return {};
298+
}

CodeService/src/FormatElement/AlignToFirstElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FormatElementType AlignToFirstElement::GetType()
1010
return FormatElementType::AlignToFirstElement;
1111
}
1212

13-
void AlignToFirstElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
13+
void AlignToFirstElement::Serialize(FormatContext& ctx, ChildIterator& selfIt, FormatElement& parent)
1414
{
1515
for (auto it = _children.begin(); it != _children.end(); ++it)
1616
{
@@ -46,7 +46,7 @@ void AlignToFirstElement::Serialize(FormatContext& ctx, std::optional<FormatElem
4646
}
4747
}
4848

49-
void AlignToFirstElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
49+
void AlignToFirstElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt, FormatElement& parent)
5050
{
5151
for (auto it = _children.begin(); it != _children.end(); ++it)
5252
{

CodeService/src/FormatElement/AlignmentElement.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FormatElementType AlignmentElement::GetType()
1212
return FormatElementType::AlignmentElement;
1313
}
1414

15-
void AlignmentElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt,
15+
void AlignmentElement::Serialize(FormatContext& ctx, ChildIterator& selfIt,
1616
FormatElement& parent)
1717
{
1818
const int blank = _alignmentPosition - static_cast<int>(ctx.GetCharacterCount());
@@ -22,15 +22,10 @@ void AlignmentElement::Serialize(FormatContext& ctx, std::optional<FormatElement
2222
}
2323
}
2424

25-
void AlignmentElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt,
25+
void AlignmentElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt,
2626
FormatElement& parent)
2727
{
28-
if (!selfIt.has_value())
29-
{
30-
return;
31-
}
32-
auto it = selfIt.value();
33-
const int nextOffset = GetNextValidOffset(it, parent);
28+
const int nextOffset = GetNextValidOffset(selfIt, parent);
3429
if (nextOffset == -1)
3530
{
3631
return;

CodeService/src/FormatElement/AlignmentLayoutElement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FormatElementType AlignmentLayoutElement::GetType()
2222
return FormatElementType::AlignmentLayoutElement;
2323
}
2424

25-
void AlignmentLayoutElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt,
25+
void AlignmentLayoutElement::Serialize(FormatContext& ctx, ChildIterator& selfIt,
2626
FormatElement& parent)
2727
{
2828
const auto eqPosition = GetAlignPosition(ctx.GetParser());
@@ -37,7 +37,7 @@ void AlignmentLayoutElement::Serialize(FormatContext& ctx, std::optional<FormatE
3737
}
3838
}
3939

40-
void AlignmentLayoutElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt,
40+
void AlignmentLayoutElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt,
4141
FormatElement& parent)
4242
{
4343
const auto eqPosition = GetAlignPosition(ctx.GetParser());
@@ -103,7 +103,7 @@ int AlignmentLayoutElement::GetAlignPosition(std::shared_ptr<LuaParser> luaParse
103103
return eqAlignedPosition;
104104
}
105105

106-
void AlignmentLayoutElement::AlignmentSerialize(FormatContext& ctx, std::optional<ChildIterator> selfIt, int eqPosition,
106+
void AlignmentLayoutElement::AlignmentSerialize(FormatContext& ctx, ChildIterator& selfIt, int eqPosition,
107107
FormatElement& parent)
108108
{
109109
for (const auto& statChild : _children)
@@ -132,7 +132,7 @@ void AlignmentLayoutElement::AlignmentSerialize(FormatContext& ctx, std::optiona
132132
}
133133

134134
void AlignmentLayoutElement::AlignmentDiagnosis(DiagnosisContext& ctx,
135-
std::optional<FormatElement::ChildIterator> selfIt,
135+
ChildIterator& selfIt,
136136
int eqPosition, FormatElement& parent)
137137
{
138138
for (const auto& statChild : _children)

CodeService/src/FormatElement/FormatElement.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ std::shared_ptr<FormatElement> FormatElement::LastValidElement() const
6161
return nullptr;
6262
}
6363

64-
void FormatElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
64+
void FormatElement::Serialize(FormatContext& ctx, ChildIterator& selfIt, FormatElement& parent)
6565
{
6666
for (auto it = _children.begin(); it != _children.end(); ++it)
6767
{
6868
(*it)->Serialize(ctx, it, *this);
6969
}
7070
}
7171

72-
void FormatElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
72+
void FormatElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt, FormatElement& parent)
7373
{
7474
for (auto it = _children.begin(); it != _children.end(); ++it)
7575
{
@@ -80,13 +80,19 @@ void FormatElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement
8080
void FormatElement::Format(FormatContext& ctx)
8181
{
8282
// workaround
83-
return Serialize(ctx, {}, *this);
83+
for (auto it = _children.begin(); it != _children.end(); ++it)
84+
{
85+
(*it)->Serialize(ctx, it, *this);
86+
}
8487
}
8588

8689
void FormatElement::DiagnosisCodeStyle(DiagnosisContext& ctx)
8790
{
8891
// workaround
89-
return Diagnosis(ctx, {}, *this);
92+
for (auto it = _children.begin(); it != _children.end(); ++it)
93+
{
94+
(*it)->Diagnosis(ctx, it, *this);
95+
}
9096
}
9197

9298
void FormatElement::AddTextRange(TextRange range)
@@ -126,10 +132,10 @@ int FormatElement::GetNextValidLine(FormatContext& ctx, ChildIterator it, Format
126132
}
127133
}
128134

129-
int FormatElement::GetLastValidOffset(ChildIterator it, FormatElement& parent)
135+
int FormatElement::GetLastValidOffset(ChildIterator& it, FormatElement& parent)
130136
{
131137
auto& siblings = parent.GetChildren();
132-
auto rIt = std::reverse_iterator<decltype(it)>(it);
138+
auto rIt = std::reverse_iterator<std::remove_reference_t<decltype(it)>>(it);
133139

134140
for (; rIt != siblings.rend(); ++rIt)
135141
{
@@ -145,7 +151,7 @@ int FormatElement::GetLastValidOffset(ChildIterator it, FormatElement& parent)
145151
return parent.GetTextRange().StartOffset;
146152
}
147153

148-
int FormatElement::GetNextValidOffset(ChildIterator it, FormatElement& parent)
154+
int FormatElement::GetNextValidOffset(ChildIterator& it, FormatElement& parent)
149155
{
150156

151157
auto& siblings = parent.GetChildren();

CodeService/src/FormatElement/IndentElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FormatElementType IndentElement::GetType()
1313
return FormatElementType::IndentElement;
1414
}
1515

16-
void IndentElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
16+
void IndentElement::Serialize(FormatContext& ctx, ChildIterator& selfIt, FormatElement& parent)
1717
{
1818
ctx.AddIndent(_specialIndent);
1919

@@ -22,7 +22,7 @@ void IndentElement::Serialize(FormatContext& ctx, std::optional<FormatElement::C
2222
ctx.RecoverIndent();
2323
}
2424

25-
void IndentElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
25+
void IndentElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt, FormatElement& parent)
2626
{
2727
ctx.AddIndent(_specialIndent);
2828

CodeService/src/FormatElement/KeepBlankElement.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,21 @@ FormatElementType KeepBlankElement::GetType()
1212
return FormatElementType::KeepBlankElement;
1313
}
1414

15-
void KeepBlankElement::Serialize(FormatContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
15+
void KeepBlankElement::Serialize(FormatContext& ctx, ChildIterator& selfIt, FormatElement& parent)
1616
{
17-
if(selfIt.has_value())
17+
int nextOffset = GetNextValidOffset(selfIt, parent);
18+
if (nextOffset != -1)
1819
{
19-
int nextOffset = GetNextValidOffset(selfIt.value(), parent);
20-
if (nextOffset != -1)
21-
{
22-
ctx.PrintBlank(_blank);
23-
}
20+
ctx.PrintBlank(_blank);
2421
}
2522
}
2623

27-
void KeepBlankElement::Diagnosis(DiagnosisContext& ctx, std::optional<FormatElement::ChildIterator> selfIt, FormatElement& parent)
24+
void KeepBlankElement::Diagnosis(DiagnosisContext& ctx, ChildIterator& selfIt, FormatElement& parent)
2825
{
29-
if(!selfIt.has_value())
30-
{
31-
return;
32-
}
33-
34-
const int lastOffset = GetLastValidOffset(selfIt.value(), parent);
35-
const int nextOffset = GetNextValidOffset(selfIt.value(), parent);
26+
const int lastOffset = GetLastValidOffset(selfIt, parent);
27+
const int nextOffset = GetNextValidOffset(selfIt, parent);
3628

37-
if (nextOffset == -1)
29+
if (nextOffset == -1)
3830
{
3931
return;
4032
}

0 commit comments

Comments
 (0)