[clang-tools-extra] 5bbf6ad - Add an option to fill container for ref

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu May 19 07:05:53 PDT 2022


Author: Utkarsh Saxena
Date: 2022-05-19T16:05:38+02:00
New Revision: 5bbf6ad5b64c2b3cc669ce7698e1bbf5a7f09539

URL: https://github.com/llvm/llvm-project/commit/5bbf6ad5b64c2b3cc669ce7698e1bbf5a7f09539
DIFF: https://github.com/llvm/llvm-project/commit/5bbf6ad5b64c2b3cc669ce7698e1bbf5a7f09539.diff

LOG: Add an option to fill container for ref

This allows index implementations to fill container details when required specially when computing containerID is expensive.

Differential Revision: https://reviews.llvm.org/D125925

Added: 
    

Modified: 
    clang-tools-extra/clangd/XRefs.cpp
    clang-tools-extra/clangd/index/Index.h
    clang-tools-extra/clangd/index/remote/Index.proto
    clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index e090c01435c8..fa8320ea9618 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -2112,6 +2112,7 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
   // FIXME: Consider also using AST information when feasible.
   RefsRequest Request;
   Request.IDs.insert(*ID);
+  Request.WantContainer = true;
   // We could restrict more specifically to calls by introducing a new RefKind,
   // but non-call references (such as address-of-function) can still be
   // interesting as they can indicate indirect calls.

diff  --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h
index d79feaabe457..3c032a5caeb5 100644
--- a/clang-tools-extra/clangd/index/Index.h
+++ b/clang-tools-extra/clangd/index/Index.h
@@ -72,6 +72,9 @@ struct RefsRequest {
   /// choose to return less than this, e.g. it tries to avoid returning stale
   /// results.
   llvm::Optional<uint32_t> Limit;
+  /// If set, populates the container of the reference.
+  /// Index implementations may chose to populate containers no matter what.
+  bool WantContainer = false;
 };
 
 struct RelationsRequest {

diff  --git a/clang-tools-extra/clangd/index/remote/Index.proto b/clang-tools-extra/clangd/index/remote/Index.proto
index aa5bcc0b1797..062feafeb735 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -47,6 +47,7 @@ message RefsRequest {
   repeated string ids = 1;
   optional uint32 filter = 2;
   optional uint32 limit = 3;
+  optional bool want_container = 4;
 }
 
 // The response is a stream of reference messages, and one terminating has_more

diff  --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 488f5794d353..4271fd79db02 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -122,6 +122,7 @@ Marshaller::fromProtobuf(const RefsRequest *Message) {
     Req.Filter = clangd::RefKind::All;
   if (Message->limit())
     Req.Limit = Message->limit();
+  Req.WantContainer = Message->want_container();
   return Req;
 }
 
@@ -239,6 +240,7 @@ RefsRequest Marshaller::toProtobuf(const clangd::RefsRequest &From) {
   RPCRequest.set_filter(static_cast<uint32_t>(From.Filter));
   if (From.Limit)
     RPCRequest.set_limit(*From.Limit);
+  RPCRequest.set_want_container(From.WantContainer);
   return RPCRequest;
 }
 


        


More information about the cfe-commits mailing list