diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -65,6 +65,9 @@ /// 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, diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1264,7 +1264,7 @@ void ClangdLSPServer::onReference(const ReferenceParams &Params, Callback> 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 Refs) mutable { diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -292,6 +292,14 @@ init(100), }; +opt ReferencesLimit{ + "limit-references", + cat(Features), + desc("Limit the number of references returned by clangd. " + "0 means no limit (default=1000)"), + init(1000), +}; + list TweakList{ "tweaks", cat(Features), @@ -821,6 +829,7 @@ } #endif Opts.BackgroundIndex = EnableBackgroundIndex; + Opts.ReferencesLimit = ReferencesLimit; auto PAI = createProjectAwareIndex(loadExternalIndex, Sync); if (StaticIdx) { IdxStack.emplace_back(std::move(StaticIdx));