Skip to content

Commit bef6c5d

Browse files
committed
rename luafile to luaSource, fix typeformat
1 parent 41a22cb commit bef6c5d

File tree

24 files changed

+102
-83
lines changed

24 files changed

+102
-83
lines changed

CHANGELOG_EN.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
# 1.3.0
4+
5+
`REFACTOR` rewrote the tokenization algorithm and related spell-checking.
6+
7+
`FIX` fixed the issue of adding incorrect trailing separators to table entries.
8+
9+
`NEW` added support for the option `end_statement_with_semicolon`. Now you can choose whether to keep the semicolon at the end of statements or enforce it. This option provides corresponding diagnostic messages. Thanks to `@AndreaWalchshoferSCCH`.
10+
11+
`NEW` added support for the option `keep_indents_on_empty_lines`. This option is mainly for IntelliJ platform, which usually has a default option to keep indentation on empty lines. Thanks to `@qq792453582`.
312

413
# 1.2.2
514

CodeFormat/src/LuaFormat.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "CodeFormatCore/Format/FormatBuilder.h"
55
#include "CodeFormatCore/RangeFormat/RangeFormatBuilder.h"
66
#include "LuaParser/Ast/LuaSyntaxTree.h"
7-
#include "LuaParser/File/LuaFile.h"
7+
#include "LuaParser/File/LuaSource.h"
88
#include "LuaParser/Lexer/LuaLexer.h"
99
#include "LuaParser/Parse/LuaParser.h"
1010
#include "LuaParser/Types/TextRange.h"
@@ -155,7 +155,7 @@ bool LuaFormat::Reformat() {
155155
}
156156

157157
bool LuaFormat::ReformatSingleFile(std::string_view inputPath, std::string_view outPath, std::string &&sourceText) {
158-
auto file = std::make_shared<LuaFile>(std::move(sourceText));
158+
auto file = LuaSource::From(std::move(sourceText));
159159
LuaLexer luaLexer(file);
160160
if (_isSupportNonStandardLua) {
161161
luaLexer.SupportNonStandardSymbol();
@@ -195,7 +195,7 @@ bool LuaFormat::ReformatSingleFile(std::string_view inputPath, std::string_view
195195

196196

197197
bool LuaFormat::RangeReformat() {
198-
auto file = std::make_shared<LuaFile>(std::move(_inputFileText));
198+
auto file = LuaSource::From(std::move(_inputFileText));
199199
LuaLexer luaLexer(file);
200200
if (_isSupportNonStandardLua) {
201201
luaLexer.SupportNonStandardSymbol();
@@ -267,7 +267,7 @@ bool LuaFormat::Check() {
267267
return CheckWorkspace();
268268
}
269269

270-
void LuaFormat::DiagnosticInspection(std::string_view message, TextRange range, std::shared_ptr<LuaFile> file,
270+
void LuaFormat::DiagnosticInspection(std::string_view message, TextRange range, std::shared_ptr<LuaSource> file,
271271
std::string_view path) {
272272
auto startLine = file->GetLine(range.StartOffset);
273273
auto startChar = file->GetColumn(range.StartOffset);
@@ -318,7 +318,7 @@ LuaStyle LuaFormat::GetStyle(std::string_view path) {
318318
}
319319

320320
bool LuaFormat::CheckSingleFile(std::string_view inputPath, std::string &&sourceText) {
321-
auto file = std::make_shared<LuaFile>(std::move(sourceText));
321+
auto file = std::make_shared<LuaSource>(std::move(sourceText));
322322
LuaLexer luaLexer(file);
323323
if (_isSupportNonStandardLua) {
324324
luaLexer.SupportNonStandardSymbol();

CodeFormat/src/LuaFormat.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#pragma once
22

3-
#include <string>
4-
#include <string_view>
5-
#include <filesystem>
6-
#include <cstring>
7-
#include <optional>
3+
#include "CodeFormatCore/Config/LuaDiagnosticStyle.h"
84
#include "CodeFormatCore/Config/LuaStyle.h"
9-
#include "LuaParser/File/LuaFile.h"
5+
#include "LuaParser/File/LuaSource.h"
106
#include "LuaParser/Types/TextRange.h"
117
#include "Types.h"
12-
#include "CodeFormatCore/Config/LuaDiagnosticStyle.h"
8+
#include <cstring>
9+
#include <filesystem>
10+
#include <optional>
11+
#include <string>
12+
#include <string_view>
1313

1414
class LuaFormat {
1515
public:
@@ -55,7 +55,7 @@ class LuaFormat {
5555

5656
LuaStyle GetStyle(std::string_view path);
5757

58-
void DiagnosticInspection(std::string_view message, TextRange range, std::shared_ptr<LuaFile> file,
58+
void DiagnosticInspection(std::string_view message, TextRange range, std::shared_ptr<LuaSource> file,
5959
std::string_view path);
6060

6161
bool ReformatSingleFile(std::string_view inputPath, std::string_view outPath, std::string&& sourceText);

CodeFormatCore/src/Config/FunctionOption.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
void FunctionOption::Parse(std::string_view option) {
66
std::string text(option);
7-
auto virtualFile = std::make_shared<LuaFile>(std::move(text));
7+
auto virtualFile = LuaSource::From(std::move(text));
88
LuaLexer lexer(virtualFile);
99
lexer.Parse();
1010
if (lexer.HasError()) {

CodeFormatCore/src/TypeFormat/LuaTypeFormat.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ void LuaTypeFormat::FormatLine(std::size_t line, std::size_t character, const Lu
186186
}
187187
}
188188
tempStyle.call_arg_parentheses = CallArgParentheses::Keep;
189+
tempStyle.keep_indents_on_empty_lines = false;
189190
return FormatByRange(formatRange, t, tempStyle);
190191
}
191192

CodeFormatLib/src/LuaCodeFormat.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void LuaCodeFormat::LoadSpellDictionaryFromBuffer(const std::string &buffer) {
6868
}
6969

7070
Result<std::string> LuaCodeFormat::Reformat(const std::string &uri, std::string &&text, ConfigMap &configMap) {
71-
auto file = std::make_shared<LuaFile>(std::move(text));
71+
auto file = std::make_shared<LuaSource>(std::move(text));
7272
LuaLexer luaLexer(file);
7373
if (_supportNonStandardSymbol){
7474
luaLexer.SupportNonStandardSymbol();
@@ -96,7 +96,7 @@ Result<std::string> LuaCodeFormat::Reformat(const std::string &uri, std::string
9696
Result<std::string> LuaCodeFormat::RangeFormat(const std::string &uri, FormatRange &range,
9797
std::string &&text,
9898
ConfigMap &configMap) {
99-
auto file = std::make_shared<LuaFile>(std::move(text));
99+
auto file = std::make_shared<LuaSource>(std::move(text));
100100
LuaLexer luaLexer(file);
101101
if (_supportNonStandardSymbol){
102102
luaLexer.SupportNonStandardSymbol();
@@ -126,7 +126,7 @@ Result<std::string> LuaCodeFormat::RangeFormat(const std::string &uri, FormatRan
126126
Result<std::vector<LuaTypeFormat::Result>>
127127
LuaCodeFormat::TypeFormat(const std::string &uri, std::size_t line, std::size_t character, std::string &&text,
128128
ConfigMap &configMap, ConfigMap &stringTypeOptions) {
129-
auto file = std::make_shared<LuaFile>(std::move(text));
129+
auto file = std::make_shared<LuaSource>(std::move(text));
130130
LuaLexer luaLexer(file);
131131
if (_supportNonStandardSymbol){
132132
luaLexer.SupportNonStandardSymbol();
@@ -154,7 +154,7 @@ LuaCodeFormat::TypeFormat(const std::string &uri, std::size_t line, std::size_t
154154
}
155155

156156
Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::Diagnostic(const std::string &uri, std::string &&text) {
157-
auto file = std::make_shared<LuaFile>(std::move(text));
157+
auto file = std::make_shared<LuaSource>(std::move(text));
158158
LuaLexer luaLexer(file);
159159
if (_supportNonStandardSymbol){
160160
luaLexer.SupportNonStandardSymbol();
@@ -180,7 +180,7 @@ Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::Diagnostic(const std::stri
180180

181181
Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::SpellCheck(const std::string &uri, std::string &&text,
182182
const CodeSpellChecker::CustomDictionary &tempDict) {
183-
auto file = std::make_shared<LuaFile>(std::move(text));
183+
auto file = LuaSource::From(std::move(text));
184184
LuaLexer luaLexer(file);
185185
if (_supportNonStandardSymbol){
186186
luaLexer.SupportNonStandardSymbol();
@@ -206,7 +206,7 @@ Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::SpellCheck(const std::stri
206206
}
207207

208208
Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::NameStyleCheck(const std::string &uri, std::string &&text) {
209-
auto file = std::make_shared<LuaFile>(std::move(text));
209+
auto file = LuaSource::From(std::move(text));
210210
LuaLexer luaLexer(file);
211211
if (_supportNonStandardSymbol){
212212
luaLexer.SupportNonStandardSymbol();
@@ -272,7 +272,7 @@ LuaStyle &LuaCodeFormat::GetStyle(const std::string &uri) {
272272
}
273273

274274
std::vector<LuaDiagnosticInfo> LuaCodeFormat::MakeDiagnosticInfo(const std::vector<LuaDiagnostic> &diagnostics,
275-
std::shared_ptr<LuaFile> file) {
275+
std::shared_ptr<LuaSource> file) {
276276
std::vector<LuaDiagnosticInfo> results;
277277
for (auto &diagnostic: diagnostics) {
278278
auto& result = results.emplace_back();

CodeFormatLib/src/LuaCodeFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class LuaCodeFormat {
5555
LuaStyle &GetStyle(const std::string &uri);
5656
private:
5757
std::vector<LuaDiagnosticInfo> MakeDiagnosticInfo(const std::vector<LuaDiagnostic>& diagnostics,
58-
std::shared_ptr<LuaFile> file);
58+
std::shared_ptr<LuaSource> file);
5959

6060
void CalculateTempStyle(LuaStyle& style, ConfigMap &configMap);
6161

CodeFormatServer/src/VFS/VirtualFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ std::optional<LuaSyntaxTree> VirtualFile::GetSyntaxTree(VirtualFileSystem &vfs)
1414
auto opText = db.Query(_fileId);
1515
if (opText.has_value()) {
1616
auto text = *std::move(opText.value());
17-
auto file = std::make_shared<LuaFile>(std::move(text));
17+
auto file = std::make_shared<LuaSource>(std::move(text));
1818
LuaLexer luaLexer(file);
1919
luaLexer.Parse();
2020

LuaParser/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ target_sources(LuaParser
3333
src/Types/TextRange.cpp
3434

3535
# file
36-
src/File/LuaFile.cpp
36+
src/File/LuaSource.cpp
3737

3838
#exception
3939
src/exception/LuaParseException.cpp

LuaParser/include/LuaParser/Ast/LuaSyntaxTree.h

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

3-
#include "LuaParser/File/LuaFile.h"
3+
#include "LuaParser/File/LuaSource.h"
44
#include "LuaParser/Lexer/LuaToken.h"
55
#include "LuaParser/Parse/Mark.h"
66
#include "LuaSyntaxNode.h"
@@ -15,7 +15,7 @@ class LuaSyntaxTree {
1515

1616
void BuildTree(LuaParser &p);
1717

18-
const LuaFile &GetFile() const;
18+
const LuaSource &GetFile() const;
1919

2020
std::size_t GetStartOffset(std::size_t index) const;
2121

@@ -81,7 +81,7 @@ class LuaSyntaxTree {
8181

8282
void BuildToken(LuaToken &token);
8383

84-
std::shared_ptr<LuaFile> _file;
84+
std::shared_ptr<LuaSource> _source;
8585
std::vector<NodeOrToken> _nodeOrTokens;
8686
std::vector<IncrementalToken> _tokens;
8787
std::vector<LuaSyntaxNode> _syntaxNodes;

0 commit comments

Comments
 (0)