Author: ioeric Date: Fri May 11 05:12:08 2018 New Revision: 332089 URL: http://llvm.org/viewvc/llvm-project?rev=332089&view=rev Log: [clangd] Move helpers that convert Replacements to TextEdits to SourceCode.h
Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46670 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/SourceCode.cpp clang-tools-extra/trunk/clangd/SourceCode.h Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=332089&r1=332088&r2=332089&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri May 11 05:12:08 2018 @@ -60,32 +60,6 @@ public: static URISchemeRegistry::Add<TestScheme> X("test", "Test scheme for clangd lit tests."); -TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) { - Range ReplacementRange = { - offsetToPosition(Code, R.getOffset()), - offsetToPosition(Code, R.getOffset() + R.getLength())}; - return {ReplacementRange, R.getReplacementText()}; -} - -std::vector<TextEdit> -replacementsToEdits(StringRef Code, - const std::vector<tooling::Replacement> &Replacements) { - // Turn the replacements into the format specified by the Language Server - // Protocol. Fuse them into one big JSON array. - std::vector<TextEdit> Edits; - for (const auto &R : Replacements) - Edits.push_back(replacementToEdit(Code, R)); - return Edits; -} - -std::vector<TextEdit> replacementsToEdits(StringRef Code, - const tooling::Replacements &Repls) { - std::vector<TextEdit> Edits; - for (const auto &R : Repls) - Edits.push_back(replacementToEdit(Code, R)); - return Edits; -} - SymbolKindBitset defaultSymbolKinds() { SymbolKindBitset Defaults; for (size_t I = SymbolKindMin; I <= static_cast<size_t>(SymbolKind::Array); @@ -291,7 +265,11 @@ void ClangdLSPServer::onRename(RenamePar return replyError(ErrorCode::InternalError, llvm::toString(Replacements.takeError())); - std::vector<TextEdit> Edits = replacementsToEdits(*Code, *Replacements); + // Turn the replacements into the format specified by the Language + // Server Protocol. Fuse them into one big JSON array. + std::vector<TextEdit> Edits; + for (const auto &R : *Replacements) + Edits.push_back(replacementToEdit(*Code, R)); WorkspaceEdit WE; WE.changes = {{Params.textDocument.uri.uri(), Edits}}; reply(WE); Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=332089&r1=332088&r2=332089&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/SourceCode.cpp (original) +++ clang-tools-extra/trunk/clangd/SourceCode.cpp Fri May 11 05:12:08 2018 @@ -166,5 +166,20 @@ splitQualifiedName(llvm::StringRef QName return {QName.substr(0, Pos + 2), QName.substr(Pos + 2)}; } +TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R) { + Range ReplacementRange = { + offsetToPosition(Code, R.getOffset()), + offsetToPosition(Code, R.getOffset() + R.getLength())}; + return {ReplacementRange, R.getReplacementText()}; +} + +std::vector<TextEdit> replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls) { + std::vector<TextEdit> Edits; + for (const auto &R : Repls) + Edits.push_back(replacementToEdit(Code, R)); + return Edits; +} + } // namespace clangd } // namespace clang Modified: clang-tools-extra/trunk/clangd/SourceCode.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.h?rev=332089&r1=332088&r2=332089&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/SourceCode.h (original) +++ clang-tools-extra/trunk/clangd/SourceCode.h Fri May 11 05:12:08 2018 @@ -15,6 +15,7 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H #include "Protocol.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Tooling/Core/Replacement.h" namespace clang { class SourceManager; @@ -55,6 +56,11 @@ std::pair<size_t, size_t> offsetToClangL std::pair<llvm::StringRef, llvm::StringRef> splitQualifiedName(llvm::StringRef QName); +TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R); + +std::vector<TextEdit> replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls); + } // namespace clangd } // namespace clang #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits