From c275fb2a5d589f8743d8bfbf12f6c8081df9de01 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 21 Sep 2018 13:04:57 +0000 Subject: [PATCH] [clangd] Remember to serialize symbol origin in YAML. llvm-svn: 342730 --- clang-tools-extra/clangd/index/SymbolYAML.cpp | 15 +++++++++++++++ clang-tools-extra/unittests/clangd/SerializationTests.cpp | 3 +++ 2 files changed, 18 insertions(+) diff --git a/clang-tools-extra/clangd/index/SymbolYAML.cpp b/clang-tools-extra/clangd/index/SymbolYAML.cpp index 4dec547..6254187 100644 --- a/clang-tools-extra/clangd/index/SymbolYAML.cpp +++ b/clang-tools-extra/clangd/index/SymbolYAML.cpp @@ -27,6 +27,7 @@ namespace yaml { using clang::clangd::Symbol; using clang::clangd::SymbolID; +using clang::clangd::SymbolOrigin; using clang::clangd::SymbolLocation; using clang::index::SymbolInfo; using clang::index::SymbolKind; @@ -65,6 +66,17 @@ struct NormalizedSymbolFlag { uint8_t Flag = 0; }; +struct NormalizedSymbolOrigin { + NormalizedSymbolOrigin(IO &) {} + NormalizedSymbolOrigin(IO &, SymbolOrigin O) { + Origin = static_cast(O); + } + + SymbolOrigin denormalize(IO &) { return static_cast(Origin); } + + uint8_t Origin = 0; +}; + template <> struct MappingTraits { static void mapping(IO &IO, SymbolLocation::Position &Value) { IO.mapRequired("Line", Value.Line); @@ -102,6 +114,8 @@ template <> struct MappingTraits { MappingNormalization NSymbolID(IO, Sym.ID); MappingNormalization NSymbolFlag( IO, Sym.Flags); + MappingNormalization NSymbolOrigin( + IO, Sym.Origin); IO.mapRequired("ID", NSymbolID->HexString); IO.mapRequired("Name", Sym.Name); IO.mapRequired("Scope", Sym.Scope); @@ -110,6 +124,7 @@ template <> struct MappingTraits { SymbolLocation()); IO.mapOptional("Definition", Sym.Definition, SymbolLocation()); IO.mapOptional("References", Sym.References, 0u); + IO.mapOptional("Origin", NSymbolOrigin->Origin); IO.mapOptional("Flags", NSymbolFlag->Flag); IO.mapOptional("Signature", Sym.Signature); IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); diff --git a/clang-tools-extra/unittests/clangd/SerializationTests.cpp b/clang-tools-extra/unittests/clangd/SerializationTests.cpp index 4a50add..0999c87 100644 --- a/clang-tools-extra/unittests/clangd/SerializationTests.cpp +++ b/clang-tools-extra/unittests/clangd/SerializationTests.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "index/Index.h" #include "index/Serialization.h" #include "index/SymbolYAML.h" #include "llvm/Support/ScopedPrinter.h" @@ -35,6 +36,7 @@ CanonicalDeclaration: End: Line: 1 Column: 1 +Origin: 4 Flags: 1 Documentation: 'Foo doc' ReturnType: 'int' @@ -82,6 +84,7 @@ TEST(SerializationTest, YAMLConversions) { EXPECT_EQ(Sym1.Documentation, "Foo doc"); EXPECT_EQ(Sym1.ReturnType, "int"); EXPECT_EQ(Sym1.CanonicalDeclaration.FileURI, "file:///path/foo.h"); + EXPECT_EQ(Sym1.Origin, SymbolOrigin::Static); EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion); EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated); EXPECT_THAT(Sym1.IncludeHeaders, -- 2.7.4