voertler created this revision.
voertler added reviewers: dgoldman, kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
voertler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
This patch allows it to set a default configuration as discussed in issue
https://github.com/clangd/clangd/issues/845 by adding a startup option
--default-config.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151315
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
@@ -317,7 +317,6 @@
RetiredFlag InlayHints("inlay-hints");
RetiredFlag FoldingRanges("folding-ranges");
-
opt LimitResults{
"limit-results",
cat(Features),
@@ -497,7 +496,8 @@
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"
+"User config is from clangd/config.yaml in the following directories
\n"
+"(unless specified with --default-config):\n"
"\tWindows: %USERPROFILE%\\AppData\\Local\n"
"\tMac OS: ~/Library/Preferences/\n"
"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
@@ -505,6 +505,15 @@
init(true),
};
+opt DefaultConfig{
+"default-config",
+cat(Misc),
+desc("Path to a default clangd configuration file. A clangd user and "
+ "project configuration has a higher priority (requires "
+ "--enable-config) "),
+init(""),
+};
+
opt UseDirtyHeaders{"use-dirty-headers", cat(Misc),
desc("Use files open in the editor when parsing "
"headers instead of reading from the disk"),
@@ -945,6 +954,21 @@
} else {
elog("Couldn't determine user config file, not loading");
}
+if (DefaultConfig.getNumOccurrences()) {
+ llvm::SmallString<256> DefaultConfigPath;
+ if (auto Error = llvm::sys::fs::real_path(
+ DefaultConfig, DefaultConfigPath, /*expand_tilde=*/true)) {
+elog("Couldn't determine default config file {0}: {1} , not loading",
+ DefaultConfig, Error.message());
+ } else {
+vlog("Default config file is {0}", DefaultConfigPath);
+// Give lowest priority to default config
+ProviderStack.insert(
+ProviderStack.begin(),
+config::Provider::fromYAMLFile(DefaultConfigPath, /*Directory=*/"",
+ TFS, /*Trusted=*/true));
+ }
+}
}
ProviderStack.push_back(std::make_unique());
std::vector ProviderPointers;
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -317,7 +317,6 @@
RetiredFlag InlayHints("inlay-hints");
RetiredFlag FoldingRanges("folding-ranges");
-
opt LimitResults{
"limit-results",
cat(Features),
@@ -497,7 +496,8 @@
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"
+"User config is from clangd/config.yaml in the following directories \n"
+"(unless specified with --default-config):\n"
"\tWindows: %USERPROFILE%\\AppData\\Local\n"
"\tMac OS: ~/Library/Preferences/\n"
"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
@@ -505,6 +505,15 @@
init(true),
};
+opt DefaultConfig{
+"default-config",
+cat(Misc),
+desc("Path to a default clangd configuration file. A clangd user and "
+ "project configuration has a higher priority (requires "
+ "--enable-config) "),
+init(""),
+};
+
opt UseDirtyHeaders{"use-dirty-headers", cat(Misc),
desc("Use files open in the editor when parsing "
"headers instead of reading from the disk"),
@@ -945,6 +954,21 @@
} else {
elog("Couldn't determine user config file, not loading");
}
+if (DefaultConfig.getNumOccurrences()) {
+ llvm::SmallString<256> DefaultConfigPath;
+ if (auto Error = llvm::sys::fs::real_path(
+ DefaultConfig, DefaultConfigPath, /*expand_tilde=*/true)) {
+elog("Couldn't determine default config file {0}: {1} , not loading",
+ DefaultConfig, Error.message());
+ } else {
+vlog("Default config file is {0}", DefaultConfigPath);
+// Give lowest priority to default config
+