[clangd] Split CC and refs limit and increase refs limit to 1000
authorKirill Bobyrev <kbobyrev@google.com>
Wed, 5 May 2021 21:39:37 +0000 (23:39 +0200)
committerKirill Bobyrev <kbobyrev@google.com>
Wed, 5 May 2021 21:39:48 +0000 (23:39 +0200)
Related discussion: https://github.com/clangd/clangd/discussions/761

Reviewed By: kadircet

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

clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/tool/ClangdMain.cpp

index 77fc948..913c5c3 100644 (file)
@@ -1264,7 +1264,7 @@ void ClangdLSPServer::onChangeConfiguration(
 void ClangdLSPServer::onReference(const ReferenceParams &Params,
                                   Callback<std::vector<Location>> Reply) {
   Server->findReferences(
-      Params.textDocument.uri.file(), Params.position, Opts.CodeComplete.Limit,
+      Params.textDocument.uri.file(), Params.position, Opts.ReferencesLimit,
       [Reply = std::move(Reply),
        IncludeDecl(Params.context.includeDeclaration)](
           llvm::Expected<ReferencesResult> Refs) mutable {
index 3f5cc9a..8c43d18 100644 (file)
@@ -65,6 +65,9 @@ public:
 
     /// Enable preview of InlayHints feature.
     bool InlayHints = false;
+
+    /// Limit the number of references returned (0 means no limit).
+    size_t ReferencesLimit = 0;
   };
 
   ClangdLSPServer(Transport &Transp, const ThreadsafeFS &TFS,
index 07fec2f..f0aa89b 100644 (file)
@@ -292,6 +292,14 @@ opt<int> LimitResults{
     init(100),
 };
 
+opt<int> ReferencesLimit{
+    "limit-references",
+    cat(Features),
+    desc("Limit the number of references returned by clangd. "
+         "0 means no limit (default=1000)"),
+    init(1000),
+};
+
 list<std::string> TweakList{
     "tweaks",
     cat(Features),
@@ -821,6 +829,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
   }
 #endif
   Opts.BackgroundIndex = EnableBackgroundIndex;
+  Opts.ReferencesLimit = ReferencesLimit;
   auto PAI = createProjectAwareIndex(loadExternalIndex, Sync);
   if (StaticIdx) {
     IdxStack.emplace_back(std::move(StaticIdx));