"lit-test",
cat(Misc),
desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -log=verbose. "
+ "-enable-test-scheme -enable-config=0 -log=verbose. "
"Intended to simplify lit tests"),
init(false),
Hidden,
Hidden,
};
+opt<bool> EnableConfig{
+ "enable-config",
+ cat(Misc),
+ desc(
+ "Read user and project configuration from YAML files.\n"
+ "Project config is from a .clangd file in the project directory.\n"
+ "User config is from clangd/config.yaml in the following directories:\n"
+ "\tWindows: %USERPROFILE%\\AppData\\Local\n"
+ "\tMac OS: ~/Library/Preferences/\n"
+ "\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
+ "Configuration is documented at https://clangd.llvm.org/config.html"),
+ init(false),
+};
+
/// Supports a test URI scheme with relaxed constraints for lit tests.
/// The path in a test URI will be combined with a platform-specific fake
/// directory to form an absolute path. For example, test:///a.cpp is resolved
InputStyle = JSONStreamStyle::Delimited;
LogLevel = Logger::Verbose;
PrettyPrint = true;
+ // Disable config system by default to avoid external reads.
+ if (!EnableConfig.getNumOccurrences())
+ EnableConfig = false;
// Disable background index on lit tests by default to prevent disk writes.
if (!EnableBackgroundIndex.getNumOccurrences())
EnableBackgroundIndex = false;
CCOpts.RunParser = CodeCompletionParse;
RealThreadsafeFS TFS;
+ std::unique_ptr<config::Provider> Config;
+ if (EnableConfig) {
+ std::vector<std::unique_ptr<config::Provider>> ProviderStack;
+ ProviderStack.push_back(
+ config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
+ llvm::SmallString<256> UserConfig;
+ if (llvm::sys::path::user_config_directory(UserConfig)) {
+ llvm::sys::path::append(UserConfig, "clangd", "config.yaml");
+ vlog("User config file is {0}", UserConfig);
+ ProviderStack.push_back(config::Provider::fromYAMLFile(UserConfig, TFS));
+ } else {
+ elog("Couldn't determine user config file, not loading");
+ }
+ Config = config::Provider::combine(std::move(ProviderStack));
+ Opts.ConfigProvider = Config.get();
+ }
+
// Initialize and run ClangdLSPServer.
// Change stdin to binary to not lose \r\n on windows.
llvm::sys::ChangeStdinToBinary();