Skip to content

Commit 76de5ab

Browse files
committed
清理无用文件,修复lookahead bug
1 parent 18d192d commit 76de5ab

File tree

7 files changed

+40
-243
lines changed

7 files changed

+40
-243
lines changed

CodeFormat/src/CodeFormat.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
#include <fstream>
44

55
#include "LuaFormat.h"
6-
#include "CodeService/Config/LuaEditorConfig.h"
76
#include "Util/format.h"
87
#include "Util/CommandLine.h"
9-
#include "LuaWorkspaceFormat.h"
108
#include "Util/StringUtil.h"
119

1210
// https://stackoverflow.com/questions/1598985/c-read-binary-stdin
@@ -70,6 +68,7 @@ int main(int argc, char **argv) {
7068
"Use file wildcards to specify how to ignore files\n"
7169
"\t\tseparated by ';'"
7270
)
71+
.Add<bool>("name-style", "ns", "Enable name-style check")
7372
.EnableKeyValueArgs();
7473

7574

@@ -132,6 +131,10 @@ int main(int argc, char **argv) {
132131
format.SetDefaultStyle(cmd.GetKeyValueOptions());
133132
}
134133

134+
if(cmd.Get<bool>("name-style")){
135+
format.SupportNameStyleCheck();
136+
}
137+
135138
if (cmd.GetTarget() == "format") {
136139
if (!format.Reformat()) {
137140
std::cerr << util::format("Exist lua syntax error") << std::endl;

CodeFormat/src/LuaFormat.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Util/FileFinder.h"
1616

1717
LuaFormat::LuaFormat() {
18+
_diagnosticStyle.name_style_check = false;
1819
}
1920

2021
void LuaFormat::SetWorkspace(std::string_view workspace) {
@@ -156,7 +157,15 @@ bool LuaFormat::ReformatSingleFile(std::string_view inputPath, std::string_view
156157

157158
bool LuaFormat::Check() {
158159
if (_mode == WorkMode::File) {
159-
return CheckSingleFile(_inputPath, std::move(_inputFileText));
160+
if (_inputPath != "stdin") {
161+
std::cerr << util::format("Check {} ...", _inputPath) << std::endl;
162+
}
163+
164+
if (CheckSingleFile(_inputPath, std::move(_inputFileText))) {
165+
std::cerr << util::format("Check {} ... ok", _inputPath) << std::endl;
166+
return true;
167+
}
168+
return false;
160169
}
161170
return CheckWorkspace();
162171
}
@@ -167,7 +176,7 @@ void LuaFormat::DiagnosticInspection(std::string_view message, TextRange range,
167176
auto startChar = file->GetColumn(range.StartOffset);
168177
auto endLine = file->GetLine(range.EndOffset);
169178
auto endChar = file->GetColumn(range.EndOffset);
170-
std::cout << util::format("\t{}({}:{} to {}:{}): {}", path, startLine + 1, startChar, endLine + 1, endChar,
179+
std::cerr << util::format("\t{}({}:{} to {}:{}): {}", path, startLine + 1, startChar, endLine + 1, endChar,
171180
message) << std::endl;
172181
}
173182

@@ -269,14 +278,17 @@ bool LuaFormat::CheckWorkspace() {
269278
auto files = finder.FindFiles();
270279
for (auto &filePath: files) {
271280
auto opText = ReadFile(filePath);
281+
std::string displayPath = filePath;
282+
if (!_workspace.empty())
283+
{
284+
displayPath = string_util::GetFileRelativePath(_workspace, filePath);
285+
}
272286
if (opText.has_value()) {
273-
if (CheckSingleFile(filePath, std::move(opText.value()))) {
274-
std::cerr << util::format("Check {} ok.", filePath) << std::endl;
275-
} else {
276-
std::cerr << util::format("Check {} fail.", filePath) << std::endl;
287+
if (CheckSingleFile(displayPath, std::move(opText.value()))) {
288+
std::cerr << util::format("Check {} ok.", displayPath) << std::endl;
277289
}
278290
} else {
279-
std::cerr << util::format("Can not read file {}", filePath) << std::endl;
291+
std::cerr << util::format("Can not read file {}", displayPath) << std::endl;
280292
}
281293
}
282294
return true;
@@ -317,17 +329,26 @@ bool LuaFormat::ReformatWorkspace() {
317329
auto files = finder.FindFiles();
318330
for (auto &filePath: files) {
319331
auto opText = ReadFile(filePath);
332+
std::string displayPath = filePath;
333+
if (!_workspace.empty())
334+
{
335+
displayPath = string_util::GetFileRelativePath(_workspace, filePath);
336+
}
320337
if (opText.has_value()) {
321-
if (ReformatSingleFile(filePath, filePath, std::move(opText.value()))) {
322-
std::cerr << util::format("Reformat {} succeed.", filePath) << std::endl;
338+
if (ReformatSingleFile(displayPath, filePath, std::move(opText.value()))) {
339+
std::cerr << util::format("Reformat {} succeed.", displayPath) << std::endl;
323340
} else {
324-
std::cerr << util::format("Reformat {} fail.", filePath) << std::endl;
341+
std::cerr << util::format("Reformat {} fail.", displayPath) << std::endl;
325342
}
326343
} else {
327-
std::cerr << util::format("Can not read file {}", filePath) << std::endl;
344+
std::cerr << util::format("Can not read file {}", displayPath) << std::endl;
328345
}
329346
}
330347
return true;
331348
}
332349

350+
void LuaFormat::SupportNameStyleCheck() {
351+
_diagnosticStyle.name_style_check = true;
352+
}
353+
333354

CodeFormat/src/LuaFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class LuaFormat {
3838

3939
void AddIgnores(std::string_view pattern);
4040

41+
void SupportNameStyleCheck();
4142
private:
4243
std::optional<std::string> ReadFile(std::string_view path);
4344

CodeFormat/src/LuaWorkspaceFormat.cpp

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

CodeFormat/src/LuaWorkspaceFormat.h

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

LuaParser/src/Parse/LuaParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ LuaTokenKind LuaParser::LookAhead() {
7575
case TK_LONG_COMMENT:
7676
case TK_SHEBANG: {
7777
nextIndex++;
78+
break;
7879
}
7980
default: {
8081
return tk;

Test2/src/FormatTest2.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
int main() {
88
std::string buffer = R"(
9-
local t = {
10-
{ a, b, c = 123 },
11-
{ d, e, f },
12-
{ ddd, weff }
13-
}
9+
local t = {a--[[]]=123}
1410
)";
1511

1612
auto file = std::make_shared<LuaFile>(std::move(buffer));

0 commit comments

Comments
 (0)