kadircet created this revision. kadircet added a reviewer: sammccall. Herald added subscribers: usaxena95, arphaman. kadircet requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This is causing weird code patterns in various places and I can't see any difference between None and empty change list. Neither in the current use cases nor in the spec. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D103449 Files: clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h Index: clang-tools-extra/clangd/Protocol.h =================================================================== --- clang-tools-extra/clangd/Protocol.h +++ clang-tools-extra/clangd/Protocol.h @@ -908,7 +908,7 @@ struct WorkspaceEdit { /// Holds changes to existing resources. - llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes; + std::map<std::string, std::vector<TextEdit>> changes; /// Note: "documentChanges" is not currently used because currently there is /// no support for versioned edits. Index: clang-tools-extra/clangd/Protocol.cpp =================================================================== --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -808,10 +808,10 @@ } llvm::json::Value toJSON(const WorkspaceEdit &WE) { - if (!WE.changes) + if (WE.changes.empty()) return llvm::json::Object{}; llvm::json::Object FileChanges; - for (auto &Change : *WE.changes) + for (auto &Change : WE.changes) FileChanges[Change.first] = llvm::json::Array(Change.second); return llvm::json::Object{{"changes", std::move(FileChanges)}}; } Index: clang-tools-extra/clangd/Diagnostics.cpp =================================================================== --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -372,8 +372,7 @@ Action.title = F.Message; Action.kind = std::string(CodeAction::QUICKFIX_KIND); Action.edit.emplace(); - Action.edit->changes.emplace(); - (*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()}; + Action.edit->changes[File.uri()] = {F.Edits.begin(), F.Edits.end()}; return Action; } Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -748,9 +748,8 @@ return Reply(std::move(Err)); WorkspaceEdit WE; - WE.changes.emplace(); for (const auto &It : R->ApplyEdits) { - (*WE.changes)[URI::createFile(It.first()).toString()] = + WE.changes[URI::createFile(It.first()).toString()] = It.second.asTextEdits(); } // ApplyEdit will take care of calling Reply(). @@ -813,22 +812,20 @@ if (!Server->getDraft(File)) return Reply(llvm::make_error<LSPError>( "onRename called for non-added file", ErrorCode::InvalidParams)); - Server->rename( - File, Params.position, Params.newName, Opts.Rename, - [File, Params, Reply = std::move(Reply), - this](llvm::Expected<RenameResult> R) mutable { - if (!R) - return Reply(R.takeError()); - if (auto Err = validateEdits(*Server, R->GlobalChanges)) - return Reply(std::move(Err)); - WorkspaceEdit Result; - Result.changes.emplace(); - for (const auto &Rep : R->GlobalChanges) { - (*Result.changes)[URI::createFile(Rep.first()).toString()] = - Rep.second.asTextEdits(); - } - Reply(Result); - }); + Server->rename(File, Params.position, Params.newName, Opts.Rename, + [File, Params, Reply = std::move(Reply), + this](llvm::Expected<RenameResult> R) mutable { + if (!R) + return Reply(R.takeError()); + if (auto Err = validateEdits(*Server, R->GlobalChanges)) + return Reply(std::move(Err)); + WorkspaceEdit Result; + for (const auto &Rep : R->GlobalChanges) { + Result.changes[URI::createFile(Rep.first()).toString()] = + Rep.second.asTextEdits(); + } + Reply(Result); + }); } void ClangdLSPServer::onDocumentDidClose(
Index: clang-tools-extra/clangd/Protocol.h =================================================================== --- clang-tools-extra/clangd/Protocol.h +++ clang-tools-extra/clangd/Protocol.h @@ -908,7 +908,7 @@ struct WorkspaceEdit { /// Holds changes to existing resources. - llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes; + std::map<std::string, std::vector<TextEdit>> changes; /// Note: "documentChanges" is not currently used because currently there is /// no support for versioned edits. Index: clang-tools-extra/clangd/Protocol.cpp =================================================================== --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -808,10 +808,10 @@ } llvm::json::Value toJSON(const WorkspaceEdit &WE) { - if (!WE.changes) + if (WE.changes.empty()) return llvm::json::Object{}; llvm::json::Object FileChanges; - for (auto &Change : *WE.changes) + for (auto &Change : WE.changes) FileChanges[Change.first] = llvm::json::Array(Change.second); return llvm::json::Object{{"changes", std::move(FileChanges)}}; } Index: clang-tools-extra/clangd/Diagnostics.cpp =================================================================== --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -372,8 +372,7 @@ Action.title = F.Message; Action.kind = std::string(CodeAction::QUICKFIX_KIND); Action.edit.emplace(); - Action.edit->changes.emplace(); - (*Action.edit->changes)[File.uri()] = {F.Edits.begin(), F.Edits.end()}; + Action.edit->changes[File.uri()] = {F.Edits.begin(), F.Edits.end()}; return Action; } Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -748,9 +748,8 @@ return Reply(std::move(Err)); WorkspaceEdit WE; - WE.changes.emplace(); for (const auto &It : R->ApplyEdits) { - (*WE.changes)[URI::createFile(It.first()).toString()] = + WE.changes[URI::createFile(It.first()).toString()] = It.second.asTextEdits(); } // ApplyEdit will take care of calling Reply(). @@ -813,22 +812,20 @@ if (!Server->getDraft(File)) return Reply(llvm::make_error<LSPError>( "onRename called for non-added file", ErrorCode::InvalidParams)); - Server->rename( - File, Params.position, Params.newName, Opts.Rename, - [File, Params, Reply = std::move(Reply), - this](llvm::Expected<RenameResult> R) mutable { - if (!R) - return Reply(R.takeError()); - if (auto Err = validateEdits(*Server, R->GlobalChanges)) - return Reply(std::move(Err)); - WorkspaceEdit Result; - Result.changes.emplace(); - for (const auto &Rep : R->GlobalChanges) { - (*Result.changes)[URI::createFile(Rep.first()).toString()] = - Rep.second.asTextEdits(); - } - Reply(Result); - }); + Server->rename(File, Params.position, Params.newName, Opts.Rename, + [File, Params, Reply = std::move(Reply), + this](llvm::Expected<RenameResult> R) mutable { + if (!R) + return Reply(R.takeError()); + if (auto Err = validateEdits(*Server, R->GlobalChanges)) + return Reply(std::move(Err)); + WorkspaceEdit Result; + for (const auto &Rep : R->GlobalChanges) { + Result.changes[URI::createFile(Rep.first()).toString()] = + Rep.second.asTextEdits(); + } + Reply(Result); + }); } void ClangdLSPServer::onDocumentDidClose(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits