This revision was automatically updated to reflect the committed changes. Closed by commit rG9c888120e3c8: [clangd] Patch PragmaMarks in preamble section of the file (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146026/new/ https://reviews.llvm.org/D146026 Files: clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/unittests/PreambleTests.cpp
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -829,6 +829,10 @@ } } +MATCHER_P2(Mark, Range, Text, "") { + return std::tie(arg.Rng, arg.Trivia) == std::tie(Range, Text); +} + TEST(PreamblePatch, MacroAndMarkHandling) { Config Cfg; Cfg.Diagnostics.AllowStalePreamble = true; @@ -847,13 +851,18 @@ #ifndef FOO #define FOO #define BAR -#pragma mark XX +#pragma $x[[mark XX +]] +#pragma $y[[mark YY +]] #endif)cpp"); auto AST = createPatchedAST(Code.code(), NewCode.code()); // FIXME: Macros and marks have locations that need to be patched. EXPECT_THAT(AST->getMacros().Names, IsEmpty()); - EXPECT_THAT(AST->getMarks(), IsEmpty()); + EXPECT_THAT(AST->getMarks(), + UnorderedElementsAre(Mark(NewCode.range("x"), " XX"), + Mark(NewCode.range("y"), " YY"))); } } Index: clang-tools-extra/clangd/Preamble.h =================================================================== --- clang-tools-extra/clangd/Preamble.h +++ clang-tools-extra/clangd/Preamble.h @@ -182,6 +182,7 @@ std::vector<Diag> PatchedDiags; PreambleBounds ModifiedBounds = {0, false}; const PreambleData *Baseline = nullptr; + std::vector<PragmaMark> PatchedMarks; }; } // namespace clangd Index: clang-tools-extra/clangd/Preamble.cpp =================================================================== --- clang-tools-extra/clangd/Preamble.cpp +++ clang-tools-extra/clangd/Preamble.cpp @@ -15,7 +15,9 @@ #include "Protocol.h" #include "SourceCode.h" #include "clang-include-cleaner/Record.h" +#include "index/CanonicalIncludes.h" #include "support/Logger.h" +#include "support/Path.h" #include "support/ThreadsafeFS.h" #include "support/Trace.h" #include "clang/AST/DeclTemplate.h" @@ -27,6 +29,7 @@ #include "clang/Basic/TokenKinds.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" +#include "clang/Frontend/PrecompiledPreamble.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/PPCallbacks.h" @@ -42,6 +45,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormatVariadic.h" @@ -50,10 +54,12 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include <cstddef> +#include <functional> #include <memory> #include <optional> #include <string> #include <system_error> +#include <tuple> #include <utility> #include <vector> @@ -318,6 +324,7 @@ // Literal lines of the preamble contents. std::vector<llvm::StringRef> Lines; PreambleBounds Bounds = {0, false}; + std::vector<PragmaMark> Marks; }; /// Scans the preprocessor directives in the preamble section of the file by @@ -372,6 +379,8 @@ SP.Bounds = Bounds; PP.addPPCallbacks( std::make_unique<DirectiveCollector>(PP, SP.TextualDirectives)); + PP.addPPCallbacks( + collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks)); if (llvm::Error Err = Action.Execute()) return std::move(Err); Action.EndSourceFile(); @@ -849,6 +858,7 @@ } PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan); + PP.PatchedMarks = std::move(ModifiedScan->Marks); dlog("Created preamble patch: {0}", Patch.str()); Patch.flush(); return PP; @@ -902,8 +912,7 @@ llvm::ArrayRef<PragmaMark> PreamblePatch::marks() const { if (PatchContents.empty()) return Baseline->Marks; - // FIXME: Patch pragma marks. - return {}; + return PatchedMarks; } MainFileMacros PreamblePatch::mainFileMacros() const {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits