forked from OSchip/llvm-project
[clangd] Enable reading config from files behind a flag
Reviewers: kadircet, hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83233
This commit is contained in:
parent
24b62f28c5
commit
69c22edb7d
|
@ -320,7 +320,7 @@ opt<bool> Test{
|
|||
"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,
|
||||
|
@ -427,6 +427,20 @@ opt<bool> AsyncPreamble{
|
|||
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
|
||||
|
@ -510,6 +524,9 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
|
|||
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;
|
||||
|
@ -677,6 +694,23 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue