[PATCH] D136033: Add an option to specify a workspece-level config file

Qingyuan Zheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 15 22:06:24 PDT 2022


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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136033.468052.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221016/6eec66e5/attachment.bin>


More information about the cfe-commits mailing list