[clang-tools-extra] [clangd] Make the --skip-preamble-build option take an enum (PR #229515)
Tomáš Slanina via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 11:48:34 PDT 2026
https://github.com/itzexpoexpo created https://github.com/llvm/llvm-project/pull/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
>From 731b9f48c354ec901455e55412b4496a921504c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Slanina?= <itzexpoexpo at gmail.com>
Date: Tue, 6 Oct 2026 20:37:37 +0200
Subject: [PATCH] [clangd] Make the skip-preamble-build option take an enum
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
---
clang-tools-extra/clangd/ClangdServer.cpp | 11 ++++++++++-
clang-tools-extra/clangd/ClangdServer.h | 9 ++++++---
clang-tools-extra/clangd/tool/ClangdMain.cpp | 12 +++++++++---
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index d4d313b40d76b7d..3d3a851ef80e814 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -1220,7 +1220,16 @@ 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){
+ using enum SkipPreambleBuildPolicy;
+
+ case Never: return false;
+ case Modules: return HasRequiredModules();
+ case Always: return true;
+ }
+ }();
}
} // namespace clangd
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 264ab7437c248c3..f519e04cab5880b 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,9 @@ 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 = {};
/// Whether include fixer insertions for Objective-C code should use #import
/// instead of #include.
@@ -513,7 +516,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 9dffa3bef8caa2b..9437f8a86bc2a7b 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -518,12 +518,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::SkipPreambleBuildPolicy::Modules),
};
#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
More information about the cfe-commits
mailing list