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

Method RangeFormat

CodeFormatCLib/src/CodeFormat.cpp:94–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94Result<RangeFormatResult> CodeFormat::RangeFormat(const std::string &uri, FormatRange &range,
95 std::string &&text, FormattingOptions options) {
96 auto file = std::make_shared<LuaSource>(std::move(text));
97 LuaLexer luaLexer(file);
98 if (_supportNonStandardSymbol || options.non_standard_symbol) {
99 luaLexer.SupportNonStandardSymbol();
100 }
101 if (_supportCLikeComments || options.non_standard_symbol) {
102 luaLexer.SupportCLikeComments();
103 }
104
105 luaLexer.Parse();
106
107 LuaParser p(file, std::move(luaLexer.GetTokens()));
108 p.Parse();
109
110 if (p.HasError()) {
111 return ResultType::Err;
112 }
113
114 LuaSyntaxTree t;
115 t.BuildTree(p);
116
117 LuaStyle style = GetStyle(uri);
118 SetupStyle(style, options);
119
120 RangeFormatBuilder f(style, range);
121
122 auto formattedText = f.GetFormatResult(t);
123 range = f.GetReplaceRange();
124
125 char *ptr = new char[formattedText.size() + 1];
126 std::copy(formattedText.begin(), formattedText.end(), ptr);
127 ptr[formattedText.size()] = '\0';// [formattedText.size()] = '\0'
128 return RangeFormatResult{
129 static_cast<int32_t>(range.StartLine),
130 static_cast<int32_t>(range.StartCol),
131 static_cast<int32_t>(range.EndLine),
132 static_cast<int32_t>(range.EndCol),
133 ptr};
134}
135
136void CodeFormat::SetupStyle(LuaStyle &style, const FormattingOptions &options) {
137 if (options.use_tabs) {

Callers 1

Calls 11

GetTokensMethod · 0.80
BuildTreeMethod · 0.80
GetReplaceRangeMethod · 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