diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -491,8 +491,9 @@ "enable-config", cat(Misc), desc( - "Read user and project configuration from YAML files.\n" + "Read user/workspace/project configuration from YAML files.\n" "Project config is from a .clangd file in the project directory.\n" + "Workspace config is specified by the --workspace-config option.\n" "User config is from clangd/config.yaml in the following directories:\n" "\tWindows: %USERPROFILE%\\AppData\\Local\n" "\tMac OS: ~/Library/Preferences/\n" @@ -501,6 +502,13 @@ init(true), }; +opt WorkspaceConfig{ + "workspace-config", + cat(Misc), + desc("Path to a workspace configuration file."), + init(""), +}; + opt UseDirtyHeaders{"use-dirty-headers", cat(Misc), desc("Use files open in the editor when parsing " "headers instead of reading from the disk"), @@ -923,6 +931,15 @@ if (EnableConfig) { ProviderStack.push_back( config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS)); + if (!WorkspaceConfig.empty() && llvm::sys::fs::exists(WorkspaceConfig)) { + llvm::SmallString<256> AbsWorkspaceConfigPath = + StringRef{WorkspaceConfig.getValue()}; + llvm::sys::fs::make_absolute("", AbsWorkspaceConfigPath); + ProviderStack.push_back(config::Provider::fromYAMLFile( + AbsWorkspaceConfigPath, /*Directory=*/"", TFS, /*Trusted=*/true)); + } else { + elog("Couldn't find workspace config file, not loading"); + } llvm::SmallString<256> UserConfig; if (llvm::sys::path::user_config_directory(UserConfig)) { llvm::sys::path::append(UserConfig, "clangd", "config.yaml");