Author: Tomáš Slanina Date: 2026-10-25T18:14:52+08:00 New Revision: 4493a8a4132df15da3e985cdf285f6fbf5dce645
URL: https://github.com/llvm/llvm-project/commit/4493a8a4132df15da3e985cdf285f6fbf5dce645 DIFF: https://github.com/llvm/llvm-project/commit/4493a8a4132df15da3e985cdf285f6fbf5dce645.diff LOG: [clangd] Make the --skip-preamble-build option take an enum (#229515) Add a new value `never` allowing the preamble skipping to be force-disabled, in addition to `modules` and `always`. The default is `modules`, equivalent to the old behavior. Closes #212403 Added: Modified: clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/tool/ClangdMain.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 3d05b57fcad8ee..8535823abc5203 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -1221,7 +1221,17 @@ void ClangdServer::adjustParseInputs(ParseInputs &Inputs, PathRef File) const { : Context::current().clone()); return ModulesManager->hasRequiredModules(File); }; - Inputs.Opts.SkipPreambleBuild = SkipPreambleBuild || HasRequiredModules(); + + Inputs.Opts.SkipPreambleBuild = [&]() { + switch (SkipPreambleBuild) { + case SkipPreambleBuildPolicy::Never: + return false; + case SkipPreambleBuildPolicy::Modules: + return HasRequiredModules(); + case SkipPreambleBuildPolicy::Always: + return true; + } + }(); } } // namespace clangd diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index 264ab7437c248c..ce3e66e4eb2866 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -98,6 +98,8 @@ class ClangdServer { createConfiguredContextProvider(const config::Provider *Provider, ClangdServer::Callbacks *); + enum class SkipPreambleBuildPolicy { Never, Modules, Always }; + struct Options { /// To process requests asynchronously, ClangdServer spawns worker threads. /// If this is zero, no threads are spawned. All work is done on the calling @@ -191,8 +193,10 @@ class ClangdServer { // If true, parse emplace-like functions in the preamble. bool PreambleParseForwardingFunctions = true; - // If true, skip preamble build. - bool SkipPreambleBuild = false; + // If Always, discard preamble during update + // If Modules, only discard when modules are required + SkipPreambleBuildPolicy SkipPreambleBuild = + SkipPreambleBuildPolicy::Modules; /// Whether include fixer insertions for Objective-C code should use #import /// instead of #include. @@ -513,7 +517,7 @@ class ClangdServer { bool PreambleParseForwardingFunctions = true; - bool SkipPreambleBuild = false; + SkipPreambleBuildPolicy SkipPreambleBuild = {}; bool ImportInsertions = false; diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index 25c987d9c29341..451495e1dbf1f1 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -519,12 +519,18 @@ opt<bool> PreambleParseForwardingFunctions{ init(ParseOptions().PreambleParseForwardingFunctions), }; -opt<bool> SkipPreambleBuild{ +opt<ClangdServer::SkipPreambleBuildPolicy> SkipPreambleBuild{ "skip-preamble-build", cat(Misc), - desc("If ture, skip preamble build"), + desc("Skip building the preamble"), Hidden, - init(ParseOptions().SkipPreambleBuild), + values(clEnumValN(ClangdServer::SkipPreambleBuildPolicy::Never, "never", + "never skip"), + clEnumValN(ClangdServer::SkipPreambleBuildPolicy::Modules, "modules", + "only if module use is encountered (default)"), + clEnumValN(ClangdServer::SkipPreambleBuildPolicy::Always, "always", + "always skip")), + init(ClangdServer::Options().SkipPreambleBuild), }; #if defined(__GLIBC__) && CLANGD_MALLOC_TRIM _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
