MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / Reformat

Method Reformat

CodeFormatCLib/src/CodeFormat.cpp:60–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60char *CodeFormat::Reformat(const std::string &uri, std::string &&text, FormattingOptions options) {
61 auto file = LuaSource::From(std::move(text));
62 LuaLexer luaLexer(file);
63 if (_supportNonStandardSymbol || options.non_standard_symbol) {
64 luaLexer.SupportNonStandardSymbol();
65 }
66 if (_supportCLikeComments || options.non_standard_symbol) {
67 luaLexer.SupportCLikeComments();
68 }
69
70 luaLexer.Parse();
71
72 LuaParser p(file, std::move(luaLexer.GetTokens()));
73 p.Parse();
74
75 if (p.HasError()) {
76 return nullptr;
77 }
78
79 LuaSyntaxTree t;
80 t.BuildTree(p);
81
82 LuaStyle style = GetStyle(uri);
83 SetupStyle(style, options);
84 FormatBuilder f(style);
85
86 auto result = f.GetFormatResult(t);
87 auto length = result.size();
88 char *ptr = new char[length + 1];
89 std::copy(result.begin(), result.end(), ptr);
90 ptr[length] = '\0';
91 return ptr;
92}
93
94Result<RangeFormatResult> CodeFormat::RangeFormat(const std::string &uri, FormatRange &range,
95 std::string &&text, FormattingOptions options) {

Callers 1

ReformatLuaCodeFunction · 0.45

Calls 10

GetTokensMethod · 0.80
BuildTreeMethod · 0.80
SupportCLikeCommentsMethod · 0.45
ParseMethod · 0.45
HasErrorMethod · 0.45
GetFormatResultMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected