Skip to content

Commit 5168364

Browse files
committed
Merge branch 'master' of github.com:CppCXY/EmmyLuaCodeStyle
2 parents 792692e + 26f24fc commit 5168364

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

CodeFormat/src/LuaFormat.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "LuaParser/Parse/LuaParser.h"
1414
#include "CodeService/Diagnostic/DiagnosticBuilder.h"
1515
#include "Util/FileFinder.h"
16+
#include "Util/Url.h"
1617

1718
LuaFormat::LuaFormat() {
1819
_diagnosticStyle.name_style_check = false;

CodeFormatServer/src/Service/ConfigService.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "CodeService/Config/LanguageTranslator.h"
55
#include "LanguageServer.h"
66
#include "DiagnosticService.h"
7+
#include "Util/Url.h"
78

89
ConfigService::ConfigService(LanguageServer *owner)
910
: Service(owner) {
@@ -23,7 +24,8 @@ LuaStyle &ConfigService::GetLuaStyle(std::string_view fileUri) {
2324
}
2425

2526
if (editorConfig) {
26-
return editorConfig->Generate(fileUri);
27+
auto filePath = url::UrlToFilePath(fileUri);
28+
return editorConfig->Generate(filePath);
2729
}
2830
return _defaultStyle;
2931
}

CodeService/src/Config/LuaEditorConfig.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <regex>
77

88
#include "Util/StringUtil.h"
9-
#include "Util/Url.h"
109

1110
std::shared_ptr<LuaEditorConfig> LuaEditorConfig::LoadFromFile(const std::string &path) {
1211
std::fstream fin(path, std::ios::in);
@@ -56,8 +55,7 @@ void LuaEditorConfig::Parse() {
5655
}
5756
}
5857

59-
LuaStyle &LuaEditorConfig::Generate(std::string_view fileUri) {
60-
auto filePath = url::UrlToFilePath(fileUri);
58+
LuaStyle &LuaEditorConfig::Generate(std::string_view filePath) {
6159

6260
std::vector<std::size_t> patternSection;
6361
for (std::size_t i = 0; i != _sections.size(); i++) {

CodeService/src/Format/Analyzer/SpaceAnalyzer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,23 @@ void SpaceAnalyzer::SpaceRight(LuaSyntaxNode &n, const LuaSyntaxTree &t, std::si
314314
_rightSpaces[token.GetIndex()] = space;
315315
}
316316

317-
std::optional<std::size_t> SpaceAnalyzer::GetRightSpace(LuaSyntaxNode &n) const {
317+
SpaceAnalyzer::OptionalInt SpaceAnalyzer::GetRightSpace(LuaSyntaxNode &n) const {
318318
if (_ignoreSpace.count(n.GetIndex())) {
319-
return {};
319+
return OptionalInt();
320320
}
321321

322322
auto it = _rightSpaces.find(n.GetIndex());
323323
if (it == _rightSpaces.end()) {
324-
return {};
324+
return OptionalInt();
325325
}
326-
return it->second;
326+
return OptionalInt(it->second);
327327
}
328328

329329
std::size_t
330330
SpaceAnalyzer::ProcessSpace(const LuaSyntaxTree &t, LuaSyntaxNode &left, LuaSyntaxNode &right) {
331331
auto rightSpaceOfLeftToken = GetRightSpace(left);
332-
if (rightSpaceOfLeftToken.has_value()) {
333-
return rightSpaceOfLeftToken.value();
332+
if (rightSpaceOfLeftToken.HasValue) {
333+
return rightSpaceOfLeftToken.Value;
334334
}
335335
if (!right.IsNull(t)) {
336336
return t.GetStartOffset(right.GetIndex()) - t.GetEndOffset(left.GetIndex()) - 1;

CodeService/src/RangeFormat/RangeFormatBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "LuaParser/Lexer/LuaTokenTypeDetail.h"
33

44
RangeFormatBuilder::RangeFormatBuilder(LuaStyle &style, FormatRange &range)
5-
: FormatBuilder(style), _range(range), _validRange(false) {
5+
: FormatBuilder(style), _validRange(false), _range(range) {
66

77
}
88

LuaParser/src/Ast/LuaSyntaxTree.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ void LuaSyntaxTree::BuildTree(LuaParser &p) {
6464

6565
FinishNode(p);
6666

67-
_syntaxNodes.reserve(_nodeOrTokens.size() - 1);
68-
for (auto i = 0; i != _nodeOrTokens.size() - 1; i++) {
69-
_syntaxNodes.emplace_back(i + 1);
67+
if (!_nodeOrTokens.empty()) {
68+
_syntaxNodes.reserve(_nodeOrTokens.size() - 1);
69+
for (std::size_t i = 0; i != _nodeOrTokens.size() - 1; i++) {
70+
_syntaxNodes.emplace_back(i + 1);
71+
}
7072
}
71-
7273
}
7374

7475
void LuaSyntaxTree::StartNode(LuaSyntaxNodeKind kind, LuaParser &p) {
@@ -368,8 +369,8 @@ std::size_t LuaSyntaxTree::GetNextToken(std::size_t index) const {
368369
}
369370
}
370371

371-
if(tokenNodeIndex != 0) {
372-
auto& token = _nodeOrTokens[tokenNodeIndex];
372+
if (tokenNodeIndex != 0) {
373+
auto &token = _nodeOrTokens[tokenNodeIndex];
373374
if (token.Data.TokenIndex + 1 < _tokens.size()) {
374375
return _tokens[token.Data.TokenIndex + 1].NodeIndex;
375376
}

include/CodeService/Format/Analyzer/SpaceAnalyzer.h

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

3-
#include <optional>
43
#include <unordered_set>
54
#include <unordered_map>
65
#include "CodeService/Format/Analyzer/FormatAnalyzer.h"
@@ -9,6 +8,16 @@ class SpaceAnalyzer : public FormatAnalyzer {
98
public:
109
DECLARE_FORMAT_ANALYZER(SpaceAnalyzer)
1110

11+
// workaround for mac 10.13
12+
struct OptionalInt {
13+
OptionalInt() : HasValue(false), Value(0) {}
14+
15+
explicit OptionalInt(std::size_t value) : HasValue(true), Value(value) {}
16+
17+
bool HasValue;
18+
std::size_t Value;
19+
};
20+
1221
SpaceAnalyzer();
1322

1423
void Analyze(FormatState &f, const LuaSyntaxTree &t) override;
@@ -26,9 +35,7 @@ class SpaceAnalyzer : public FormatAnalyzer {
2635
void SpaceIgnore(LuaSyntaxNode &n, const LuaSyntaxTree &t);
2736

2837
private:
29-
// std::optional<std::size_t> GetLeftSpace(LuaSyntaxNode &n) const;
30-
31-
std::optional<std::size_t> GetRightSpace(LuaSyntaxNode &n) const;
38+
OptionalInt GetRightSpace(LuaSyntaxNode &n) const;
3239

3340
std::size_t ProcessSpace(const LuaSyntaxTree &t, LuaSyntaxNode &left, LuaSyntaxNode &right);
3441

0 commit comments

Comments
 (0)