[clang-tools-extra] 4169c52 - [clangd] Add symbol origin for remote index
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 28 06:41:23 PST 2020
Author: Kirill Bobyrev
Date: 2020-11-28T15:38:11+01:00
New Revision: 4169c520f6d7029d87098997e9f256a0170aa8cf
URL: https://github.com/llvm/llvm-project/commit/4169c520f6d7029d87098997e9f256a0170aa8cf
DIFF: https://github.com/llvm/llvm-project/commit/4169c520f6d7029d87098997e9f256a0170aa8cf.diff
LOG: [clangd] Add symbol origin for remote index
Makes it easier to diagnose remote index issues with --debug-origins flag.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D92202
Added:
Modified:
clang-tools-extra/clangd/index/SymbolOrigin.cpp
clang-tools-extra/clangd/index/SymbolOrigin.h
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/index/SymbolOrigin.cpp b/clang-tools-extra/clangd/index/SymbolOrigin.cpp
index e98308a2dbdf..79e32137f7b8 100644
--- a/clang-tools-extra/clangd/index/SymbolOrigin.cpp
+++ b/clang-tools-extra/clangd/index/SymbolOrigin.cpp
@@ -14,7 +14,7 @@ namespace clangd {
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) {
if (O == SymbolOrigin::Unknown)
return OS << "unknown";
- constexpr static char Sigils[] = "ADSMI567";
+ constexpr static char Sigils[] = "ADSMIR67";
for (unsigned I = 0; I < sizeof(Sigils); ++I)
if (static_cast<uint8_t>(O) & 1u << I)
OS << Sigils[I];
diff --git a/clang-tools-extra/clangd/index/SymbolOrigin.h b/clang-tools-extra/clangd/index/SymbolOrigin.h
index 8af113c75564..dd3a83230b0e 100644
--- a/clang-tools-extra/clangd/index/SymbolOrigin.h
+++ b/clang-tools-extra/clangd/index/SymbolOrigin.h
@@ -25,6 +25,7 @@ enum class SymbolOrigin : uint8_t {
Static = 1 << 2, // From the static, externally-built index.
Merge = 1 << 3, // A non-trivial index merge was performed.
Identifier = 1 << 4, // Raw identifiers in file.
+ Remote = 1 << 5, // Remote index.
// Remaining bits reserved for index implementations.
};
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 296f99cdfa38..a96a6ef1ea7a 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -161,7 +161,8 @@ llvm::Expected<clangd::Symbol> Marshaller::fromProtobuf(const Symbol &Message) {
return Declaration.takeError();
Result.CanonicalDeclaration = *Declaration;
Result.References = Message.references();
- Result.Origin = static_cast<clangd::SymbolOrigin>(Message.origin());
+ // Overwrite symbol origin: it's coming from remote index.
+ Result.Origin = clangd::SymbolOrigin::Remote;
Result.Signature = Message.signature();
Result.TemplateSpecializationArgs = Message.template_specialization_args();
Result.CompletionSnippetSuffix = Message.completion_snippet_suffix();
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index 6ef8da59861f..88627df0f624 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -16,6 +16,7 @@
#include "index/Symbol.h"
#include "index/SymbolID.h"
#include "index/SymbolLocation.h"
+#include "index/SymbolOrigin.h"
#include "index/remote/marshalling/Marshalling.h"
#include "clang/Index/IndexSymbol.h"
#include "llvm/ADT/SmallString.h"
@@ -154,6 +155,8 @@ TEST(RemoteMarshallingTest, SymbolSerialization) {
ASSERT_TRUE(bool(Serialized));
auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
ASSERT_TRUE(bool(Deserialized));
+ // Origin is overwritten when deserializing.
+ Sym.Origin = SymbolOrigin::Remote;
EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
// Serialized paths are relative and have UNIX slashes.
EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
@@ -258,6 +261,7 @@ TEST(RemoteMarshallingTest, IncludeHeaderURIs) {
Sym.IncludeHeaders.size());
auto Deserialized = ProtobufMarshaller.fromProtobuf(*Serialized);
ASSERT_TRUE(bool(Deserialized));
+ Sym.Origin = SymbolOrigin::Remote;
EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
// This is an absolute path to a header: can not be transmitted over the wire.
More information about the cfe-commits
mailing list