| 135 | } |
| 136 | |
| 137 | std::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 | |
| 174 | std::shared_ptr<lsp::Serializable> LSPHandle::OnClose( |
| 175 | std::shared_ptr<lsp::DidCloseTextDocumentParams> params) { |
nothing calls this directly
no test coverage detected