Skip to content

Commit a867804

Browse files
committed
修改文件编码为UTF8
1 parent d71d6dd commit a867804

File tree

18 files changed

+60
-60
lines changed

18 files changed

+60
-60
lines changed

CodeFormatServer/src/LanguageService.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnRangeFormatting(
207207
formatter.BuildFormattedElement();
208208

209209
auto& edit = result->edits.emplace_back();
210-
LuaFormatRange formattedRange(param->range.start.line, param->range.end.line);
210+
LuaFormatRange formattedRange(static_cast<int>(param->range.start.line), static_cast<int>(param->range.end.line));
211211

212212
edit.newText = formatter.GetRangeFormattedText(formattedRange);
213213
edit.range = vscode::Range(
@@ -224,7 +224,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnTypeFormatting(
224224
auto position = param->position;
225225

226226
auto result = std::make_shared<vscode::DocumentFormattingResult>();
227-
if (parser->IsEmptyLine(position.line - 1))
227+
if (parser->IsEmptyLine(static_cast<int>(position.line) - 1))
228228
{
229229
result->hasError = true;
230230
return result;
@@ -242,7 +242,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnTypeFormatting(
242242
formatter.BuildFormattedElement();
243243

244244
auto& edit = result->edits.emplace_back();
245-
LuaFormatRange formattedRange(position.line - 1, position.line - 1);
245+
LuaFormatRange formattedRange(static_cast<int>(position.line) - 1, static_cast<int>(position.line) - 1);
246246

247247
edit.newText = formatter.GetRangeFormattedText(formattedRange);
248248
edit.range = vscode::Range(

CodeService/src/FormatElement/AlignmentLayoutElement.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CodeService/FormatElement/AlignmentLayoutElement.h"
1+
#include "CodeService/FormatElement/AlignmentLayoutElement.h"
22
#include "CodeService/FormatElement/StatementElement.h"
33
#include "CodeService/FormatElement/TextElement.h"
44
#include "CodeService/FormatElement/AlignmentElement.h"
@@ -53,9 +53,9 @@ int AlignmentLayoutElement::getAlignPosition(std::shared_ptr<LuaParser> luaParse
5353
{
5454
int eqAlignedPosition = 0;
5555
bool firstContainEq = true;
56-
// 先寻找等号对齐的位置,并且判断连续的带等号的语句是否应该对齐到等号
57-
// 连续的带等号的语句是否应该对齐到等号,这个行为应该由连续语句的首行决定
58-
// 如果被子节点内的其他语句共同决定则很难将连续对齐还原为普通排版
56+
// 先寻找等号对齐的位置,并且判断连续的带等号的语句是否应该对齐到等号
57+
// 连续的带等号的语句是否应该对齐到等号,这个行为应该由连续语句的首行决定
58+
// 如果被子节点内的其他语句共同决定则很难将连续对齐还原为普通排版
5959
for (int statIndex = 0; statIndex != static_cast<int>(_children.size()); statIndex++)
6060
{
6161
auto statChild = _children[statIndex];
@@ -115,7 +115,7 @@ void AlignmentLayoutElement::alignmentSerialize(FormatContext& ctx, int position
115115
auto textElement = std::dynamic_pointer_cast<TextElement>(textChild);
116116
if (textElement->GetText() == "=" && i > 0)
117117
{
118-
// 将控制元素变更为对齐元素
118+
// 将控制元素变更为对齐元素
119119
statChildren[i - 1] = std::make_shared<AlignmentElement>(eqPosition);
120120
break;
121121
}
@@ -141,7 +141,7 @@ void AlignmentLayoutElement::alignmentDiagnosis(DiagnosisContext& ctx, int posit
141141
auto textElement = std::dynamic_pointer_cast<TextElement>(textChild);
142142
if (textElement->GetText() == "=" && i > 0)
143143
{
144-
// 将控制元素变更为对齐元素
144+
// 将控制元素变更为对齐元素
145145
statChildren[i - 1] = std::make_shared<AlignmentElement>(eqPosition);
146146
break;
147147
}

CodeService/src/FormatElement/DiagnosisContext.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include "CodeService/FormatElement/DiagnosisContext.h"
2-
1+
#include "CodeService/FormatElement/DiagnosisContext.h"
32
#include "CodeService/LanguageTranslator.h"
43
#include "Util/format.h"
54

@@ -31,7 +30,7 @@ void DiagnosisContext::AddIndent(int specialIndent)
3130
}
3231
_indentStack.push(newIndent);
3332
}
34-
else //这个算法可能会有问题
33+
else //这个算法可能会有问题
3534
{
3635
int newIndent = 0;
3736
if (specialIndent == -1)
@@ -43,13 +42,13 @@ void DiagnosisContext::AddIndent(int specialIndent)
4342
}
4443

4544
auto& topIndent = _indentStack.top();
46-
// 一次只增一个\t
45+
// 一次只增一个\t
4746
newIndent = 1 + topIndent;
4847
}
4948
else
5049
{
51-
// 我会认为存在一个换算
52-
// 当你制定了一个缩进,则我会认为保底有一个缩进
50+
// 我会认为存在一个换算
51+
// 当你制定了一个缩进,则我会认为保底有一个缩进
5352
newIndent = std::max(1, specialIndent / 8);
5453
}
5554
_indentStack.push(newIndent);

CodeService/src/FormatElement/FormatContext.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CodeService/FormatElement/FormatContext.h"
1+
#include "CodeService/FormatElement/FormatContext.h"
22
#include "CodeService/FormatElement/TextElement.h"
33

44
FormatContext::FormatContext(std::shared_ptr<LuaParser> parser, LuaCodeStyleOptions& options)
@@ -44,7 +44,7 @@ void FormatContext::PrintBlank(int blank)
4444

4545
void FormatContext::PrintIndent(int indent, const std::string& indentString)
4646
{
47-
// 我始终认为使\t来排版就是垃圾
47+
// 我始终认为使\t来排版就是垃圾
4848
for (int i = 0; i < indent; i++)
4949
{
5050
_os << indentString;
@@ -74,7 +74,7 @@ void FormatContext::AddIndent(int specialIndent)
7474
}
7575
_indentStack.push({newIndent, " "});
7676
}
77-
else //这个算法可能会有问题
77+
else //这个算法可能会有问题
7878
{
7979
int newIndent = 0;
8080
if (specialIndent == -1)
@@ -86,13 +86,13 @@ void FormatContext::AddIndent(int specialIndent)
8686
}
8787

8888
auto& topIndent = _indentStack.top();
89-
// 一次只增一个\t
89+
// 一次只增一个\t
9090
newIndent = 1 + topIndent.Indent;
9191
}
9292
else
9393
{
94-
// 我会认为存在一个换算
95-
// 当你制定了一个缩进,则我会认为保底有一个缩进
94+
// 我会认为存在一个换算
95+
// 当你制定了一个缩进,则我会认为保底有一个缩进
9696
newIndent = std::max(1, specialIndent / 8);
9797
}
9898
std::string indentString = "\t";

CodeService/src/FormatElement/FormatElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CodeService/FormatElement/FormatElement.h"
1+
#include "CodeService/FormatElement/FormatElement.h"
22

33
FormatElement::FormatElement(TextRange range)
44
: _textRange(range)
@@ -149,6 +149,6 @@ int FormatElement::getLastValidOffset(int position, FormatElement& parent)
149149
}
150150
}
151151

152-
// 那么一定是往上找不到有效范围元素
152+
// 那么一定是往上找不到有效范围元素
153153
return parent.GetTextRange().StartOffset;
154154
}

CodeService/src/FormatElement/KeepElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CodeService/FormatElement/KeepElement.h"
1+
#include "CodeService/FormatElement/KeepElement.h"
22
#include "Util/format.h"
33

44
KeepElement::KeepElement(int keepBlank, bool hasLinebreak)
@@ -21,7 +21,7 @@ void KeepElement::Serialize(FormatContext& ctx, int position, FormatElement& par
2121
{
2222
return;
2323
}
24-
// 这个条件的意思是如果上一个元素和下一个元素没有实质的换行则保持一定的空格
24+
// 这个条件的意思是如果上一个元素和下一个元素没有实质的换行则保持一定的空格
2525
if (nextElementLine == lastElementLine && ctx.GetCharacterCount() != 0)
2626
{
2727
ctx.PrintBlank(_keepBlank);

CodeService/src/FormatElement/RangeFormatContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::string RangeFormatContext::GetText()
7676
{
7777
std::string formattedText = FormatContext::GetText();
7878

79-
for (int i = formattedText.size() - 1; i >= 0; i--)
79+
for (int i = static_cast<int>(formattedText.size()) - 1; i >= 0; i--)
8080
{
8181
char ch = formattedText[i];
8282

LuaParser/src/LuaTokenParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int LuaTokenParser::GetColumn(int offset)
169169

170170
int bytesLength = offset - lineStartOffset;
171171

172-
int utf8Length = ::utf8nlen(_source.data() + lineStartOffset, bytesLength);
172+
int utf8Length = ::utf8nlen(_source.data() + lineStartOffset, static_cast<std::size_t>(bytesLength));
173173
return utf8Length;
174174
}
175175

@@ -188,7 +188,7 @@ bool LuaTokenParser::IsEmptyLine(int line)
188188
int nextLineStartOffset = 0;
189189
if (line == _linenumber)
190190
{
191-
nextLineStartOffset = _source.size();
191+
nextLineStartOffset = static_cast<int>(_source.size());
192192
}
193193
else
194194
{

Test/src/CodeFormatTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <cassert>
1+
#include <cassert>
22
#include <iostream>
33
#include <filesystem>
44
#include <vector>
@@ -109,7 +109,7 @@ std::string ReadFile(const std::string& path)
109109
return "";
110110
}
111111

112-
// 第一个参数是待格式化文本目录,第二个参数是格式化预期结果
112+
// 第一个参数是待格式化文本目录,第二个参数是格式化预期结果
113113
int main(int argc, char* argv[])
114114
{
115115
CommandLine commandLine;

include/CodeFormatServer/LanguageClient.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#pragma once
1+
#pragma once
22

33
#include <memory>
44
#include "Session/IOSession.h"
55
#include "CodeService/LuaCodeStyleOptions.h"
66
#include "LuaParser/LuaParser.h"
7+
78
class LanguageClient
89
{
910
public:
@@ -34,7 +35,7 @@ class LanguageClient
3435
void RemoveOptions(std::string_view workspaceUri);
3536
private:
3637
std::shared_ptr<IOSession> _session;
37-
// uri µ½file astµÄÓ³Éä
38+
// uri 到file ast的映射
3839
std::map<std::string, std::shared_ptr<LuaParser>, std::less<>> _fileMap;
3940

4041
std::vector<std::pair<std::string, std::shared_ptr<LuaCodeStyleOptions>>> _optionsVector;

0 commit comments

Comments
 (0)