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

Method OnTypeFormatting

CodeFormatServer/src/LSP/LSPHandle.cpp:242–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242std::shared_ptr<lsp::Serializable> LSPHandle::OnTypeFormatting(
243 std::shared_ptr<lsp::TextDocumentPositionParams> params) {
244 auto result = std::make_shared<lsp::DocumentFormattingResult>();
245 auto &vfs = _server->GetVFS();
246 auto vFile = vfs.GetVirtualFile(params->textDocument.uri);
247 if (vFile.IsNull()) {
248 result->hasError = true;
249 return result;
250 }
251
252 auto opSyntaxTree = vFile.GetSyntaxTree(vfs);
253 if (!opSyntaxTree.has_value()) {
254 result->hasError = true;
255 return result;
256 }
257
258 auto &syntaxTree = opSyntaxTree.value();
259 LuaStyle &luaStyle = _server->GetService<ConfigService>()->GetLuaStyle(params->textDocument.uri);
260
261 LuaTypeFormatFeatures typeFormatOptions;
262 auto typeFormatResults = _server->GetService<FormatService>()->TypeFormat(
263 "\n",
264 params->position.line,
265 params->position.character,
266 syntaxTree, luaStyle, typeFormatOptions);
267 for (auto &formatResult: typeFormatResults) {
268 auto &edit = result->edits.emplace_back();
269 edit.newText = std::move(formatResult.Text);
270 edit.range = lsp::Range(
271 lsp::Position(formatResult.Range.StartLine, formatResult.Range.StartCol),
272 lsp::Position(formatResult.Range.EndLine, formatResult.Range.EndCol));
273 }
274
275 return result;
276}
277
278std::shared_ptr<lsp::CodeActionResult> LSPHandle::OnCodeAction(std::shared_ptr<lsp::CodeActionParams> param) {
279 auto codeActionResult = std::make_shared<lsp::CodeActionResult>();

Callers

nothing calls this directly

Calls 7

GetVirtualFileMethod · 0.80
GetSyntaxTreeMethod · 0.80
RangeClass · 0.70
PositionClass · 0.70
IsNullMethod · 0.45
valueMethod · 0.45
TypeFormatMethod · 0.45

Tested by

no test coverage detected