| 197 | } |
| 198 | |
| 199 | std::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 | |
| 242 | std::shared_ptr<lsp::Serializable> LSPHandle::OnTypeFormatting( |
| 243 | std::shared_ptr<lsp::TextDocumentPositionParams> params) { |
nothing calls this directly
no test coverage detected