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

Method OnRangeFormatting

CodeFormatServer/src/LSP/LSPHandle.cpp:199–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199std::shared_ptr<lsp::Serializable> LSPHandle::OnRangeFormatting(
200 std::shared_ptr<lsp::DocumentRangeFormattingParams> params) {
201 auto result = std::make_shared<lsp::DocumentFormattingResult>();
202 auto &vfs = _server->GetVFS();
203 auto vFile = vfs.GetVirtualFile(params->textDocument.uri);
204 if (vFile.IsNull()) {
205 result->hasError = true;
206 return result;
207 }
208
209 auto opSyntaxTree = vFile.GetSyntaxTree(vfs);
210 if (!opSyntaxTree.has_value()) {
211 result->hasError = true;
212 return result;
213 }
214
215 auto &syntaxTree = opSyntaxTree.value();
216
217 if (syntaxTree.HasError()) {
218 result->hasError = true;
219 return result;
220 }
221
222 LuaStyle &luaStyle = _server->GetService<ConfigService>()->GetLuaStyle(params->textDocument.uri);
223
224 FormatRange range;
225 range.StartLine = params->range.start.line;
226 range.EndLine = params->range.end.line;
227
228 auto newText = _server->GetService<FormatService>()->RangeFormat(syntaxTree, luaStyle, range);
229 if (newText.empty()) {
230 result->hasError = true;
231 return result;
232 }
233
234 auto &edit = result->edits.emplace_back();
235 edit.newText = std::move(newText);
236 edit.range = lsp::Range(
237 lsp::Position(range.StartLine, range.StartCol),
238 lsp::Position(range.EndLine + 1, 0));
239 return result;
240}
241
242std::shared_ptr<lsp::Serializable> LSPHandle::OnTypeFormatting(
243 std::shared_ptr<lsp::TextDocumentPositionParams> params) {

Callers

nothing calls this directly

Calls 9

GetVirtualFileMethod · 0.80
GetSyntaxTreeMethod · 0.80
RangeClass · 0.70
PositionClass · 0.70
IsNullMethod · 0.45
valueMethod · 0.45
HasErrorMethod · 0.45
RangeFormatMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected