| 240 | } |
| 241 | |
| 242 | std::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 | |
| 278 | std::shared_ptr<lsp::CodeActionResult> LSPHandle::OnCodeAction(std::shared_ptr<lsp::CodeActionParams> param) { |
| 279 | auto codeActionResult = std::make_shared<lsp::CodeActionResult>(); |
nothing calls this directly
no test coverage detected