[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-03-05 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 6c1b25686a214a178efb6f6b8216de9329d37ad0 Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Rpc Request ID in trace events

Included in a new field, `rid,` this allows us to associate each trace
log with the incoming request that sent them. Helpful for associating
insights from clangd logs with logging on an lsp client side - such as a
vscode extension.
---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 11 +--
 clang-tools-extra/clangd/support/Trace.cpp   |  6 ++
 clang-tools-extra/clangd/support/Trace.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..632cdd04cf6fc4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,7 +229,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
@@ -252,7 +252,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 
 Callback ReplyHandler = nullptr;
  

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-03-04 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 6c1b25686a214a178efb6f6b8216de9329d37ad0 Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Rpc Request ID in trace events

Included in a new field, `rid,` this allows us to associate each trace
log with the incoming request that sent them. Helpful for associating
insights from clangd logs with logging on an lsp client side - such as a
vscode extension.
---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 11 +--
 clang-tools-extra/clangd/support/Trace.cpp   |  6 ++
 clang-tools-extra/clangd/support/Trace.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..632cdd04cf6fc4 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,7 +229,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
@@ -252,7 +252,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 
 Callback ReplyHandler = nullptr;
  

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-03-04 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 0355db6b05ef7f588b70de179ae43db5416068e2 Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Request ID in trace events

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 13 +++--
 clang-tools-extra/clangd/support/Trace.cpp   |  6 ++
 clang-tools-extra/clangd/support/Trace.h |  2 ++
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..5bb1ac66167e82 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,7 +229,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
@@ -252,7 +252,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 
 Callback ReplyHandler = nullptr;
 if (auto IntID = ID.getAsInteger()) {
@@ -415,6 +415,15 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 Server.Opts.Encoding.value_or(OffsetEncoding::UTF16));
   }
 
+  Context handlerContext

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-03-04 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 77dccd3eb10cef5c58148ad3637273ca2872ca4a Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Request ID in trace events

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 13 +++--
 clang-tools-extra/clangd/ClangdServer.cpp|  2 +-
 clang-tools-extra/clangd/support/Trace.cpp   |  6 ++
 clang-tools-extra/clangd/support/Trace.h |  2 ++
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..5bb1ac66167e82 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,7 +229,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
@@ -252,7 +252,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 
 Callback ReplyHandler = nullptr;
 if (auto IntID = ID.getAsInteger()) {
@@ -415,6 +415,15 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 Server.Opts.Encoding.value_or(Off

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-02-28 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 5784bf85bc5143266565586ece0113cd773a8616 
81271a1a536ca950eba328e5e84571e20a37d46e -- 
clang-tools-extra/clangd/ClangdLSPServer.cpp 
clang-tools-extra/clangd/ClangdServer.cpp 
clang-tools-extra/clangd/index/YAMLSerialization.cpp 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
clang-tools-extra/clangd/support/Trace.cpp 
clang-tools-extra/clangd/support/Trace.h 
clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
clang-tools-extra/clangd/unittests/support/TraceTests.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 562d33a362..e6840faed1 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -416,13 +416,11 @@ private:
 Server.Opts.Encoding.value_or(OffsetEncoding::UTF16));
   }
 
-  Context handlerContext(const std::string& ID) const {
-return Context::current().derive(
-kCurrentOffsetEncoding,
-Server.Opts.Encoding.value_or(OffsetEncoding::UTF16)).derive(
-  trace::EventTracer::kRequestId,
-  ID
-);
+  Context handlerContext(const std::string &ID) const {
+return Context::current()
+.derive(kCurrentOffsetEncoding,
+Server.Opts.Encoding.value_or(OffsetEncoding::UTF16))
+.derive(trace::EventTracer::kRequestId, ID);
   }
 
   // We run cancelable requests in a context that does two things:
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 48be7576f8..fcf990372b 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -781,15 +781,15 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, 
StringRef TweakID,
 
 void ClangdServer::locateSymbolAt(PathRef File, Position Pos,
   Callback> CB) {
-  // Copy over the request ID from the current thread to the worker thread 
action
+  // Copy over the request ID from the current thread to the worker thread
+  // action
   const auto rid = Context::current().get(trace::EventTracer::kRequestId);
   auto Action = [Pos, CB = std::move(CB), rid,
  this](llvm::Expected InpAST) mutable {
 if (!InpAST)
   return CB(InpAST.takeError());
 if (rid)
-  Context::current().derive(trace::EventTracer::kRequestId,
-  *rid);
+  Context::current().derive(trace::EventTracer::kRequestId, *rid);
 CB(clangd::locateSymbolAt(InpAST->AST, Pos, Index));
   };
 
diff --git a/clang-tools-extra/clangd/support/Trace.cpp 
b/clang-tools-extra/clangd/support/Trace.cpp
index 78c4dda658..22e12bbf5d 100644
--- a/clang-tools-extra/clangd/support/Trace.cpp
+++ b/clang-tools-extra/clangd/support/Trace.cpp
@@ -88,8 +88,10 @@ public:
 
   /// Called whenever a metrics records a measurement.
   void record(const Metric &Metric, double Value,
-  llvm::StringRef Label) override {
-  instant("Metric", llvm::json::Object{{"name", Metric.Name}, {"value", 
Value}, {"label", Label}});
+  llvm::StringRef Label) override {
+instant("Metric", llvm::json::Object{{"name", Metric.Name},
+ {"value", Value},
+ {"label", Label}});
   }
 
 private:

``




https://github.com/llvm/llvm-project/pull/71605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-02-28 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH 1/2] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

>From 81271a1a536ca950eba328e5e84571e20a37d46e Mon Sep 17 00:00:00 2001
From: dup 
Date: Wed, 28 Feb 2024 18:19:19 -0800
Subject: [PATCH 2/2] [clangd] Include Json Request ID in trace events

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp   | 14 --
 clang-tools-extra/clangd/ClangdServer.cpp  |  7 ++-
 clang-tools-extra/clangd/support/Trace.cpp | 12 
 clang-tools-extra/clangd/support/Trace.h   |  2 ++
 .../clangd/unittests/support/TraceTests.cpp|  3 +++
 5 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f29dadde2b86d5..562d33a362cc90 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -229,11 +229,12 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onCall(llvm::StringRef Method, llvm::json::Value Params,
   llvm::json::Value ID) override {
-WithContext HandlerContext(handlerContext());
+WithContext HandlerContext(handlerContext(llvm::to_string(ID)));
 // Calls can be canceled by the client. Add cancellation context.
 WithContext WithCancel(cancelableRequestContext(ID));
 trace::Span Tracer(Method, LSPLatency);
 SPAN_ATTACH(Tracer, "Params", Params);
+SPAN_ATTACH(Tracer, "Rid", ID);
 ReplyOnce Reply(ID, Method, &Server, Tracer.Args);
 log("<-- {0}({1})", Method, ID);
 auto Handler = Server.Handlers.MethodHandlers.find(Method);
@@ -252,7 +253,7 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
 
   bool onReply(llvm::json::Value ID,
llvm::Expected Result) override {
-   

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-02-28 Thread via cfe-commits

https://github.com/tdupes updated 
https://github.com/llvm/llvm-project/pull/71605

>From 4282c39fd0b40c26c68f57257c150b984264f50b Mon Sep 17 00:00:00 2001
From: dup 
Date: Fri, 3 Nov 2023 09:03:24 -0700
Subject: [PATCH] Add container field to remote index Refs grpc method

---
 clang-tools-extra/clangd/index/YAMLSerialization.cpp  | 1 +
 clang-tools-extra/clangd/index/remote/Index.proto | 1 +
 .../clangd/index/remote/marshalling/Marshalling.cpp   | 4 
 .../clangd/unittests/remote/MarshallingTests.cpp  | 1 +
 4 files changed, 7 insertions(+)

diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 214a847b5eddb3..495d8a2ff487aa 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -319,6 +319,7 @@ template <> struct MappingTraits {
 MappingNormalization NKind(IO, R.Kind);
 IO.mapRequired("Kind", NKind->Kind);
 IO.mapRequired("Location", R.Location);
+IO.mapOptional("Container", R.Container);
   }
 };
 
diff --git a/clang-tools-extra/clangd/index/remote/Index.proto 
b/clang-tools-extra/clangd/index/remote/Index.proto
index 3072299d8f345f..33bf095d88598f 100644
--- a/clang-tools-extra/clangd/index/remote/Index.proto
+++ b/clang-tools-extra/clangd/index/remote/Index.proto
@@ -81,6 +81,7 @@ message Symbol {
 message Ref {
   optional SymbolLocation location = 1;
   optional uint32 kind = 2;
+  optional string container = 3;
 }
 
 message SymbolInfo {
diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp 
b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
index 7e31ada18a6579..e9f0972ba91c3f 100644
--- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -189,6 +189,9 @@ llvm::Expected Marshaller::fromProtobuf(const 
Ref &Message) {
 return Location.takeError();
   Result.Location = *Location;
   Result.Kind = static_cast(Message.kind());
+  auto ContainerID = SymbolID::fromStr(Message.container());
+  if (ContainerID)
+Result.Container = *ContainerID;
   return Result;
 }
 
@@ -296,6 +299,7 @@ llvm::Expected Marshaller::toProtobuf(const 
clangd::Ref &From) {
   if (!Location)
 return Location.takeError();
   *Result.mutable_location() = *Location;
+  Result.set_container(From.Container.str());
   return Result;
 }
 
diff --git a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp 
b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
index a2b31698a059a9..85e79eae331bc1 100644
--- a/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
   Location.FileURI = testPathURI(
   "llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
   Ref.Location = Location;
+  Ref.Container = llvm::cantFail(SymbolID::fromStr("0001"));
 
   Marshaller ProtobufMarshaller(testPath("llvm-project/"),
 testPath("llvm-project/"));

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-01-02 Thread via cfe-commits

https://github.com/tdupes edited https://github.com/llvm/llvm-project/pull/71605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits