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

Method Reformat

CodeFormatServer/src/Service/CommandService.cpp:52–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void CommandService::Reformat(std::shared_ptr<lsp::ExecuteCommandParams> params) {
53 if (params->arguments.size() < 2) {
54 return;
55 }
56
57 std::string uri = params->arguments[0];
58 lsp::Range range;
59
60 range.Deserialize(params->arguments[1]);
61
62 auto applyParams = std::make_shared<lsp::ApplyWorkspaceEditParams>();
63
64
65 auto &vfs = _owner->GetVFS();
66 auto vFile = vfs.GetVirtualFile(uri);
67 if (vFile.IsNull()) {
68 return;
69 }
70
71 auto opSyntaxTree = vFile.GetSyntaxTree(vfs);
72 if (!opSyntaxTree.has_value()) {
73 return;
74 }
75
76 auto &syntaxTree = opSyntaxTree.value();
77
78 if (syntaxTree.HasError()) {
79 return;
80 }
81
82 LuaStyle &luaStyle = _owner->GetService<ConfigService>()->GetLuaStyle(uri);
83
84 FormatRange formatRange;
85 formatRange.StartLine = range.start.line;
86 formatRange.EndLine = range.end.line;
87
88 auto it = applyParams->edit.changes.emplace(uri, std::vector<lsp::TextEdit>());
89 auto &change = it.first->second;
90 auto &edit = change.emplace_back();
91
92 edit.newText = _owner->GetService<FormatService>()->RangeFormat(syntaxTree, luaStyle, formatRange);
93
94 edit.range = lsp::Range(
95 lsp::Position(formatRange.StartLine, formatRange.StartCol),
96 lsp::Position(formatRange.EndLine + 1, formatRange.EndCol));
97
98 _owner->SendRequest("workspace/applyEdit", applyParams);
99}
100
101void CommandService::SpellCorrect(std::shared_ptr<lsp::ExecuteCommandParams> params) {
102 if (params->arguments.size() < 3) {

Callers

nothing calls this directly

Calls 12

GetVirtualFileMethod · 0.80
GetSyntaxTreeMethod · 0.80
SendRequestMethod · 0.80
RangeClass · 0.50
PositionClass · 0.50
sizeMethod · 0.45
DeserializeMethod · 0.45
IsNullMethod · 0.45
valueMethod · 0.45
HasErrorMethod · 0.45
emplaceMethod · 0.45
RangeFormatMethod · 0.45

Tested by

no test coverage detected