[clang-tools-extra] [clangd] Make the --skip-preamble-build option take an enum (PR #229515)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 11:49:18 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Tomáš Slanina (itzexpoexpo)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/229515.diff
3 Files Affected:
- (modified) clang-tools-extra/clangd/ClangdServer.cpp (+10-1)
- (modified) clang-tools-extra/clangd/ClangdServer.h (+6-3)
- (modified) clang-tools-extra/clangd/tool/ClangdMain.cpp (+9-3)
``````````diff
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index d4d313b40d76b7..3d3a851ef80e81 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 264ab7437c248c..f519e04cab5880 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 9dffa3bef8caa2..9437f8a86bc2a7 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/229515
More information about the cfe-commits
mailing list