daiyousei-qz created this revision. daiyousei-qz added reviewers: nridge, kadircet. Herald added a subscriber: arphaman. Herald added a project: All. daiyousei-qz requested review of this revision. Herald added subscribers: cfe-commits, ilya-biryukov. Herald added a project: clang-tools-extra.
Add an option "--workspace-config=<path>" to specify a workspace config file, which stands between the in-tree .clangd and the global user config file and offers per-workspace customization. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D136033 Files: clang-tools-extra/clangd/tool/ClangdMain.cpp Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ 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<std::string> WorkspaceConfig{ + "workspace-config", + cat(Misc), + desc("Path to a workspace configuration file."), + init(""), +}; + opt<bool> 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");
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ 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<std::string> WorkspaceConfig{ + "workspace-config", + cat(Misc), + desc("Path to a workspace configuration file."), + init(""), +}; + opt<bool> 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");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits