| 50 | } |
| 51 | |
| 52 | void CommandService::Reformat(std::shared_ptr<lsp::ExecuteCommandParams> params) { |
| 53 | if (params->arguments.size() < 2) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | std::string uri = params->arguments[0]; |
| 58 | lsp::Range range; |
| 59 | |
| 60 | range.Deserialize(params->arguments[1]); |
| 61 | |
| 62 | auto applyParams = std::make_shared<lsp::ApplyWorkspaceEditParams>(); |
| 63 | |
| 64 | |
| 65 | auto &vfs = _owner->GetVFS(); |
| 66 | auto vFile = vfs.GetVirtualFile(uri); |
| 67 | if (vFile.IsNull()) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | auto opSyntaxTree = vFile.GetSyntaxTree(vfs); |
| 72 | if (!opSyntaxTree.has_value()) { |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | auto &syntaxTree = opSyntaxTree.value(); |
| 77 | |
| 78 | if (syntaxTree.HasError()) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | LuaStyle &luaStyle = _owner->GetService<ConfigService>()->GetLuaStyle(uri); |
| 83 | |
| 84 | FormatRange formatRange; |
| 85 | formatRange.StartLine = range.start.line; |
| 86 | formatRange.EndLine = range.end.line; |
| 87 | |
| 88 | auto it = applyParams->edit.changes.emplace(uri, std::vector<lsp::TextEdit>()); |
| 89 | auto &change = it.first->second; |
| 90 | auto &edit = change.emplace_back(); |
| 91 | |
| 92 | edit.newText = _owner->GetService<FormatService>()->RangeFormat(syntaxTree, luaStyle, formatRange); |
| 93 | |
| 94 | edit.range = lsp::Range( |
| 95 | lsp::Position(formatRange.StartLine, formatRange.StartCol), |
| 96 | lsp::Position(formatRange.EndLine + 1, formatRange.EndCol)); |
| 97 | |
| 98 | _owner->SendRequest("workspace/applyEdit", applyParams); |
| 99 | } |
| 100 | |
| 101 | void CommandService::SpellCorrect(std::shared_ptr<lsp::ExecuteCommandParams> params) { |
| 102 | if (params->arguments.size() < 3) { |
nothing calls this directly
no test coverage detected