diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -691,6 +691,12 @@ llvm::StringRef Remove = Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, &Invalid); llvm::StringRef Insert = FixIt.CodeToInsert; + if (Insert.empty() && FixIt.InsertFromRange.isValid()) { + bool InvalidInsert = false; + Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, + &InvalidInsert); + Invalid |= InvalidInsert; + } if (!Invalid) { llvm::raw_svector_ostream M(Message); if (!Remove.empty() && !Insert.empty()) { diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -549,6 +549,12 @@ Result.range = halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L)); Result.newText = FixIt.CodeToInsert; + if (Result.newText.empty() && FixIt.InsertFromRange.isValid()) { + bool Invalid = false; + auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, &Invalid); + if (!Invalid) + Result.newText = Insert.str(); + } return Result; }