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

Method OnFormatting

CodeFormatServer/src/LSP/LSPHandle.cpp:137–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137std::shared_ptr<lsp::Serializable> LSPHandle::OnFormatting(
138 std::shared_ptr<lsp::DocumentFormattingParams> params) {
139 auto result = std::make_shared<lsp::DocumentFormattingResult>();
140 auto &vfs = _server->GetVFS();
141 auto vFile = vfs.GetVirtualFile(params->textDocument.uri);
142 if (vFile.IsNull()) {
143 result->hasError = true;
144 return result;
145 }
146
147 auto opSyntaxTree = vFile.GetSyntaxTree(vfs);
148 if (!opSyntaxTree.has_value()) {
149 result->hasError = true;
150 return result;
151 }
152
153 auto &syntaxTree = opSyntaxTree.value();
154
155 if (syntaxTree.HasError()) {
156 result->hasError = true;
157 return result;
158 }
159
160 LuaStyle &luaStyle = _server->GetService<ConfigService>()->GetLuaStyle(params->textDocument.uri);
161
162 auto newText = _server->GetService<FormatService>()->Format(syntaxTree, luaStyle);
163 auto lineIndex = vFile.GetLineIndex(vfs);
164 auto totalLine = lineIndex->GetTotalLine();
165
166 auto &edit = result->edits.emplace_back();
167 edit.newText = std::move(newText);
168 edit.range = lsp::Range(
169 lsp::Position(0, 0),
170 lsp::Position(totalLine + 1, 0));
171 return result;
172}
173
174std::shared_ptr<lsp::Serializable> LSPHandle::OnClose(
175 std::shared_ptr<lsp::DidCloseTextDocumentParams> params) {

Callers

nothing calls this directly

Calls 10

GetVirtualFileMethod · 0.80
GetSyntaxTreeMethod · 0.80
GetLineIndexMethod · 0.80
RangeClass · 0.70
PositionClass · 0.70
IsNullMethod · 0.45
valueMethod · 0.45
HasErrorMethod · 0.45
FormatMethod · 0.45
GetTotalLineMethod · 0.45

Tested by

no test coverage detected