Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -60,32 +60,6 @@ static URISchemeRegistry::Add 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 -replacementsToEdits(StringRef Code, - const std::vector &Replacements) { - // Turn the replacements into the format specified by the Language Server - // Protocol. Fuse them into one big JSON array. - std::vector Edits; - for (const auto &R : Replacements) - Edits.push_back(replacementToEdit(Code, R)); - return Edits; -} - -std::vector replacementsToEdits(StringRef Code, - const tooling::Replacements &Repls) { - std::vector 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(SymbolKind::Array); @@ -291,7 +265,11 @@ return replyError(ErrorCode::InternalError, llvm::toString(Replacements.takeError())); - std::vector 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 Edits; + for (const auto &R : *Replacements) + Edits.push_back(replacementToEdit(*Code, R)); WorkspaceEdit WE; WE.changes = {{Params.textDocument.uri.uri(), Edits}}; reply(WE); Index: clang-tools-extra/trunk/clangd/SourceCode.h =================================================================== --- clang-tools-extra/trunk/clangd/SourceCode.h +++ clang-tools-extra/trunk/clangd/SourceCode.h @@ -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 splitQualifiedName(llvm::StringRef QName); +TextEdit replacementToEdit(StringRef Code, const tooling::Replacement &R); + +std::vector replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls); + } // namespace clangd } // namespace clang #endif Index: clang-tools-extra/trunk/clangd/SourceCode.cpp =================================================================== --- clang-tools-extra/trunk/clangd/SourceCode.cpp +++ clang-tools-extra/trunk/clangd/SourceCode.cpp @@ -166,5 +166,20 @@ 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 replacementsToEdits(StringRef Code, + const tooling::Replacements &Repls) { + std::vector Edits; + for (const auto &R : Repls) + Edits.push_back(replacementToEdit(Code, R)); + return Edits; +} + } // namespace clangd } // namespace clang