[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
kadircet added inline comments. Comment at: clang-tools-extra/clangd/SourceCode.cpp:555 +auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, ); +if (!Invalid) + Result.newText = Insert.str(); njames93 wrote: > kadircet wrote: > > njames93 wrote: > > > kadircet wrote: > > > > it feels like correct semantics would be to make this function fail > > > > now. as the resulting value will likely be used for editing the source > > > > code and we don't want to propagate some garbage. > > > While I agree with this in principal. We currently don't handle the case > > > where RemoveRange doesn't correspond to a FileCharRange which would > > > likely need propagating. Though likely in a separate patch. > > i discussed the situation with sam offline (as you've also noticed most of > > the sourcelocation -> lsp conversations within this file doesn't really > > check for errors), and it looks like this was intentional. we are trying to > > cover as much ground as possible in diagnostics.cpp, especially in > > https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Diagnostics.cpp#L677. > > we should do the same for `InsertFromRange`. all the macroarg logic isn't > > necessary (until we notice it is), so just bailing out when the > > `InsertFromRange` is a macroid or outside mainfile in `AddFix` should be > > enough. > > > > as for testing it, looks like you can invoke a fixit with `InsertFromRange` > > via: > > ``` > > struct Foo {}; > > struct Bar : public [[noreturn]] Foo {}; > > ``` > > > > it would be nice to also check with an attribute coming from a macro > > expansions. > Can you elaborate on why we should disregard `InsertFromRange` if it points > outside the main file. That seems like an unnecessary restriction. It's > probably also safe if its a macro ID, though there's more likely to be some > edge case there. > > As for the diagnostic. I don't think there's any value testing that. The test > in `SourceCodeTests` covers inserting from range pretty well. It would be > nice to test the synthetic messages, but I don't think any diagnostic in > clang/clang-tidy contains just 1 fix-it that's an InsertFromRange. > Can you elaborate on why we should disregard InsertFromRange if it points > outside the main file. That seems like an unnecessary restriction. because we build preamble and main file separately, the sourcemanager is likely missing files apart from the main file. hence when one tries to access a sourcelocation in them, the file will be re-read from disk and if contents on disk change for some reason, clangd might crash when the offsets are off. > It's probably also safe if its a macro ID, though there's more likely to be > some edge case there. safeness is a little wrinkly here due to the edge cases (that are hard to predict, until we see them in practice) you point out as well. but moreover, do we really want to introduce a piece of text coming from a macro expansion into source code? is there any use cases for that? (i'd say it should be the macro name that should be inserted, not its expansion.) > As for the diagnostic. I don't think there's any value testing that. i wasn't suggesting to introduce a diagnostic test to check the behaviour of `toTextEdit`. it was for testing the new logic we'll introduce into diagnostics.cpp, sorry if i wasn't clear:/. the tests you currently have are totally fine for testing `toTextEdit`. Comment at: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp:805 +Expected sourceRangeInMainFile(SourceManager , Range R) { + if (auto Beg = sourceLocationInMainFile(SM, R.start)) { sorry if i was vague in preivous comment, i was suggesting making this function return a SourceRange all the time by wrapping `sourceLocationInMainFile`s with `cantFail`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
njames93 marked an inline comment as done. njames93 added inline comments. Comment at: clang-tools-extra/clangd/SourceCode.cpp:555 +auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, ); +if (!Invalid) + Result.newText = Insert.str(); kadircet wrote: > njames93 wrote: > > kadircet wrote: > > > it feels like correct semantics would be to make this function fail now. > > > as the resulting value will likely be used for editing the source code > > > and we don't want to propagate some garbage. > > While I agree with this in principal. We currently don't handle the case > > where RemoveRange doesn't correspond to a FileCharRange which would likely > > need propagating. Though likely in a separate patch. > i discussed the situation with sam offline (as you've also noticed most of > the sourcelocation -> lsp conversations within this file doesn't really check > for errors), and it looks like this was intentional. we are trying to cover > as much ground as possible in diagnostics.cpp, especially in > https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Diagnostics.cpp#L677. > we should do the same for `InsertFromRange`. all the macroarg logic isn't > necessary (until we notice it is), so just bailing out when the > `InsertFromRange` is a macroid or outside mainfile in `AddFix` should be > enough. > > as for testing it, looks like you can invoke a fixit with `InsertFromRange` > via: > ``` > struct Foo {}; > struct Bar : public [[noreturn]] Foo {}; > ``` > > it would be nice to also check with an attribute coming from a macro > expansions. Can you elaborate on why we should disregard `InsertFromRange` if it points outside the main file. That seems like an unnecessary restriction. It's probably also safe if its a macro ID, though there's more likely to be some edge case there. As for the diagnostic. I don't think there's any value testing that. The test in `SourceCodeTests` covers inserting from range pretty well. It would be nice to test the synthetic messages, but I don't think any diagnostic in clang/clang-tidy contains just 1 fix-it that's an InsertFromRange. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
njames93 updated this revision to Diff 325826. njames93 added a comment. Update tests. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/unittests/SourceCodeTests.cpp Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp === --- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -802,6 +802,49 @@ EXPECT_FALSE(isKeyword("override", LangOpts)); } +Expected sourceRangeInMainFile(SourceManager , Range R) { + if (auto Beg = sourceLocationInMainFile(SM, R.start)) { +if (auto End = sourceLocationInMainFile(SM, R.end)) { + return SourceRange(*Beg, *End); +} else { + return End.takeError(); +} + } else { +return Beg.takeError(); + } +} + +TEST(SourceCodeTests, FixItToTextEdit) { + Annotations Code(R"( +int Var = $V1[[$V1^Value1]] + $V2[[$V2^Value2]]; + )"); + SourceManagerForFile SMFF("File", Code.code()); + SourceManager = SMFF.get(); + LangOptions LangOpts; + SourceRange V1Char = cantFail(sourceRangeInMainFile(SM, Code.range("V1"))); + SourceRange V2Char = cantFail(sourceRangeInMainFile(SM, Code.range("V2"))); + SourceLocation V1Tok = + cantFail(sourceLocationInMainFile(SM, Code.point("V1"))); + SourceLocation V2Tok = + cantFail(sourceLocationInMainFile(SM, Code.point("V2"))); + { +FixItHint Hint; +Hint.RemoveRange = CharSourceRange::getCharRange(V1Char); +Hint.InsertFromRange = CharSourceRange::getCharRange(V2Char); +TextEdit E = toTextEdit(Hint, SM, LangOpts); +EXPECT_EQ(E.range, Code.range("V1")); +EXPECT_EQ(E.newText, "Value2"); + } + { +FixItHint Hint; +Hint.RemoveRange = CharSourceRange::getTokenRange(V1Tok, V1Tok); +Hint.InsertFromRange = CharSourceRange::getTokenRange(V2Tok); +TextEdit E = toTextEdit(Hint, SM, LangOpts); +EXPECT_EQ(E.range, Code.range("V1")); +EXPECT_EQ(E.newText, "Value2"); + } +} + } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/SourceCode.cpp === --- clang-tools-extra/clangd/SourceCode.cpp +++ clang-tools-extra/clangd/SourceCode.cpp @@ -548,7 +548,15 @@ TextEdit Result; Result.range = halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L)); - Result.newText = FixIt.CodeToInsert; + + if (FixIt.InsertFromRange.isValid()) { +assert(FixIt.CodeToInsert.empty() && + "Cannot insert text when range is specified"); +// FIXME: Propagate errors from getSourceText +Result.newText = Lexer::getSourceText(FixIt.InsertFromRange, M, L).str(); + } else { +Result.newText = FixIt.CodeToInsert; + } return Result; } Index: clang-tools-extra/clangd/Diagnostics.cpp === --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -691,6 +691,13 @@ llvm::StringRef Remove = Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, ); llvm::StringRef Insert = FixIt.CodeToInsert; + if (FixIt.InsertFromRange.isValid()) { +assert(FixIt.CodeToInsert.empty() && + "Cannot insert text when range is specified"); +if (!Invalid) + Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, +); + } if (!Invalid) { llvm::raw_svector_ostream M(Message); if (!Remove.empty() && !Insert.empty()) { Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp === --- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -802,6 +802,49 @@ EXPECT_FALSE(isKeyword("override", LangOpts)); } +Expected sourceRangeInMainFile(SourceManager , Range R) { + if (auto Beg = sourceLocationInMainFile(SM, R.start)) { +if (auto End = sourceLocationInMainFile(SM, R.end)) { + return SourceRange(*Beg, *End); +} else { + return End.takeError(); +} + } else { +return Beg.takeError(); + } +} + +TEST(SourceCodeTests, FixItToTextEdit) { + Annotations Code(R"( +int Var = $V1[[$V1^Value1]] + $V2[[$V2^Value2]]; + )"); + SourceManagerForFile SMFF("File", Code.code()); + SourceManager = SMFF.get(); + LangOptions LangOpts; + SourceRange V1Char = cantFail(sourceRangeInMainFile(SM, Code.range("V1"))); + SourceRange V2Char = cantFail(sourceRangeInMainFile(SM, Code.range("V2"))); + SourceLocation V1Tok = + cantFail(sourceLocationInMainFile(SM, Code.point("V1"))); + SourceLocation V2Tok = +
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
kadircet added inline comments. Comment at: clang-tools-extra/clangd/SourceCode.cpp:555 +auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, ); +if (!Invalid) + Result.newText = Insert.str(); njames93 wrote: > kadircet wrote: > > it feels like correct semantics would be to make this function fail now. as > > the resulting value will likely be used for editing the source code and we > > don't want to propagate some garbage. > While I agree with this in principal. We currently don't handle the case > where RemoveRange doesn't correspond to a FileCharRange which would likely > need propagating. Though likely in a separate patch. i discussed the situation with sam offline (as you've also noticed most of the sourcelocation -> lsp conversations within this file doesn't really check for errors), and it looks like this was intentional. we are trying to cover as much ground as possible in diagnostics.cpp, especially in https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/Diagnostics.cpp#L677. we should do the same for `InsertFromRange`. all the macroarg logic isn't necessary (until we notice it is), so just bailing out when the `InsertFromRange` is a macroid or outside mainfile in `AddFix` should be enough. as for testing it, looks like you can invoke a fixit with `InsertFromRange` via: ``` struct Foo {}; struct Bar : public [[noreturn]] Foo {}; ``` it would be nice to also check with an attribute coming from a macro expansions. Comment at: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp:826 + Expected V2Char = sourceRangeInMainFile(SM, Code.range("V2")); + auto V1Tok = sourceLocationInMainFile(SM, Code.point("V1")); + auto V2Tok = sourceLocationInMainFile(SM, Code.point("V2")); nit: I would just wrap these in `llvm::cantFail`, similarly for `sourceRangeInMainFile`. these are just tests, and we don't really expect them to be outside mainfile. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
njames93 updated this revision to Diff 325515. njames93 added a comment. Sort of added tests. Though they seem hacked in and I can't find a simple way to test the synthetic diagnostic messages. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/unittests/SourceCodeTests.cpp Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp === --- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -802,6 +802,61 @@ EXPECT_FALSE(isKeyword("override", LangOpts)); } +Expected sourceRangeInMainFile(SourceManager , Range R) { + if (auto Beg = sourceLocationInMainFile(SM, R.start)) { +if (auto End = sourceLocationInMainFile(SM, R.end)) { + return SourceRange(*Beg, *End); +} else { + return End.takeError(); +} + } else { +return Beg.takeError(); + } +} + +TEST(SourceCodeTests, FixItToTextEdit) { + Annotations Code(R"( +int Var = $V1[[$V1^Value1]] + $V2[[$V2^Value2]]; + )"); + SourceManagerForFile SMFF("File", Code.code()); + SourceManager = SMFF.get(); + LangOptions LangOpts; + Expected V1Char = sourceRangeInMainFile(SM, Code.range("V1")); + Expected V2Char = sourceRangeInMainFile(SM, Code.range("V2")); + auto V1Tok = sourceLocationInMainFile(SM, Code.point("V1")); + auto V2Tok = sourceLocationInMainFile(SM, Code.point("V2")); + ASSERT_TRUE(V1Char && V1Char->isValid()); + ASSERT_TRUE(V2Char && V2Char->isValid()); + ASSERT_TRUE(V1Tok && V1Tok->isValid()); + ASSERT_TRUE(V2Tok && V2Tok->isValid()); + auto RemoveCharRange = CharSourceRange::getCharRange(*V1Char); + auto RemoveTokRange = CharSourceRange::getTokenRange(*V1Tok, *V1Tok); + { +FixItHint Hint; +Hint.RemoveRange = RemoveCharRange; +Hint.InsertFromRange = CharSourceRange::getCharRange(*V2Char); +TextEdit E = toTextEdit(Hint, SM, LangOpts); +EXPECT_EQ(E.range, Code.range("V1")); +EXPECT_EQ(E.newText, "Value2"); + } + { +FixItHint Hint; +Hint.RemoveRange = RemoveCharRange; +Hint.InsertFromRange = CharSourceRange::getTokenRange(*V2Tok); +TextEdit E = toTextEdit(Hint, SM, LangOpts); +EXPECT_EQ(E.range, Code.range("V1")); +EXPECT_EQ(E.newText, "Value2"); + } + { +FixItHint Hint; +Hint.RemoveRange = RemoveTokRange; +Hint.CodeToInsert = "Value2"; +TextEdit E = toTextEdit(Hint, SM, LangOpts); +EXPECT_EQ(E.range, Code.range("V1")); +EXPECT_EQ(E.newText, "Value2"); + } +} + } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/SourceCode.cpp === --- clang-tools-extra/clangd/SourceCode.cpp +++ clang-tools-extra/clangd/SourceCode.cpp @@ -548,7 +548,15 @@ TextEdit Result; Result.range = halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L)); - Result.newText = FixIt.CodeToInsert; + + if (FixIt.InsertFromRange.isValid()) { +assert(FixIt.CodeToInsert.empty() && + "Cannot insert text when range is specified"); +// FIXME: Propagate errors from getSourceText +Result.newText = Lexer::getSourceText(FixIt.InsertFromRange, M, L).str(); + } else { +Result.newText = FixIt.CodeToInsert; + } return Result; } Index: clang-tools-extra/clangd/Diagnostics.cpp === --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -691,6 +691,13 @@ llvm::StringRef Remove = Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, ); llvm::StringRef Insert = FixIt.CodeToInsert; + if (FixIt.InsertFromRange.isValid()) { +assert(FixIt.CodeToInsert.empty() && + "Cannot insert text when range is specified"); +if (!Invalid) + Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, +); + } if (!Invalid) { llvm::raw_svector_ostream M(Message); if (!Remove.empty() && !Insert.empty()) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
njames93 added inline comments. Comment at: clang-tools-extra/clangd/Diagnostics.cpp:695 + if (Insert.empty() && FixIt.InsertFromRange.isValid()) { +bool InvalidInsert = false; +Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, kadircet wrote: > nit: I would rather make `!Invalid` a condition and just make use of it in > here as well. Good point, that's much nicer. Comment at: clang-tools-extra/clangd/SourceCode.cpp:555 +auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, ); +if (!Invalid) + Result.newText = Insert.str(); kadircet wrote: > it feels like correct semantics would be to make this function fail now. as > the resulting value will likely be used for editing the source code and we > don't want to propagate some garbage. While I agree with this in principal. We currently don't handle the case where RemoveRange doesn't correspond to a FileCharRange which would likely need propagating. Though likely in a separate patch. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
kadircet added inline comments. Comment at: clang-tools-extra/clangd/SourceCode.cpp:552 Result.newText = FixIt.CodeToInsert; + if (Result.newText.empty() && FixIt.InsertFromRange.isValid()) { +bool Invalid = false; oh btw, i think the condition should only check for validness of the `InsertFromRange`, and then we should assert for the emptyness of `CodeToInsert`. (same for the piece in Diagnostics.cpp) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
kadircet added a comment. mostly LG, can you also add some tests? Comment at: clang-tools-extra/clangd/Diagnostics.cpp:695 + if (Insert.empty() && FixIt.InsertFromRange.isValid()) { +bool InvalidInsert = false; +Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, nit: I would rather make `!Invalid` a condition and just make use of it in here as well. Comment at: clang-tools-extra/clangd/SourceCode.cpp:555 +auto Insert = Lexer::getSourceText(FixIt.InsertFromRange, M, L, ); +if (!Invalid) + Result.newText = Insert.str(); it feels like correct semantics would be to make this function fail now. as the resulting value will likely be used for editing the source code and we don't want to propagate some garbage. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97123/new/ https://reviews.llvm.org/D97123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97123: [clangd] Support FixIts that use InsertFromRange instead of inserting raw text
njames93 created this revision. njames93 added reviewers: sammccall, kadircet. Herald added subscribers: usaxena95, arphaman. njames93 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang. Currently clangd will ignore FixItHint::InsertFromRange when computing edits. This leads to malformed fixes for diagnostics that choose to use it. In this patch we will try to grab source text if CodeToInsert is empty. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D97123 Files: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/SourceCode.cpp Index: clang-tools-extra/clangd/SourceCode.cpp === --- clang-tools-extra/clangd/SourceCode.cpp +++ 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, ); +if (!Invalid) + Result.newText = Insert.str(); + } return Result; } Index: clang-tools-extra/clangd/Diagnostics.cpp === --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -691,6 +691,12 @@ llvm::StringRef Remove = Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, ); llvm::StringRef Insert = FixIt.CodeToInsert; + if (Insert.empty() && FixIt.InsertFromRange.isValid()) { +bool InvalidInsert = false; +Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, + ); +Invalid |= InvalidInsert; + } if (!Invalid) { llvm::raw_svector_ostream M(Message); if (!Remove.empty() && !Insert.empty()) { Index: clang-tools-extra/clangd/SourceCode.cpp === --- clang-tools-extra/clangd/SourceCode.cpp +++ 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, ); +if (!Invalid) + Result.newText = Insert.str(); + } return Result; } Index: clang-tools-extra/clangd/Diagnostics.cpp === --- clang-tools-extra/clangd/Diagnostics.cpp +++ clang-tools-extra/clangd/Diagnostics.cpp @@ -691,6 +691,12 @@ llvm::StringRef Remove = Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, ); llvm::StringRef Insert = FixIt.CodeToInsert; + if (Insert.empty() && FixIt.InsertFromRange.isValid()) { +bool InvalidInsert = false; +Insert = Lexer::getSourceText(FixIt.InsertFromRange, SM, *LangOpts, + ); +Invalid |= InvalidInsert; + } if (!Invalid) { llvm::raw_svector_ostream M(Message); if (!Remove.empty() && !Insert.empty()) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits