diff options
author | Sam McCall <sam.mccall@gmail.com> | 2019-07-25 07:54:48 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2019-07-25 07:54:48 +0000 |
commit | 8faffec4e22191ad3d2a78b50f73d1010f666b60 (patch) | |
tree | 5baf6c7c7ffbe2217194c6bbea54211c0a3aca1a | |
parent | 5c8af5380660d772030ead44f02785a691789609 (diff) | |
download | bcm5719-llvm-8faffec4e22191ad3d2a78b50f73d1010f666b60.tar.gz bcm5719-llvm-8faffec4e22191ad3d2a78b50f73d1010f666b60.zip |
[clangd] Also accept flags from CLANGD_FLAGS variable.
This simplifies various workflows, particularly in debugging/development.
e.g. editors will tend to propagate flags, so you can run
`env CLANGD_FLAGS=-input-mirror-file=/tmp/mirror vim foo.cc` rather than
change the configuration in a persistent way.
(This also gives us a generic lever when we don't know how to customize
the flags in some particular LSP client).
While here, add a test for this and other startup logging, and fix a
couple of direct writes to errs() that should have been logs.
Differential Revision: https://reviews.llvm.org/D65153
llvm-svn: 366991
-rw-r--r-- | clang-tools-extra/clangd/index/Serialization.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/clangd/test/log.test | 9 | ||||
-rw-r--r-- | clang-tools-extra/clangd/tool/ClangdMain.cpp | 23 |
3 files changed, 26 insertions, 10 deletions
diff --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp index 188a5cc1862..90520fdc2ce 100644 --- a/clang-tools-extra/clangd/index/Serialization.cpp +++ b/clang-tools-extra/clangd/index/Serialization.cpp @@ -690,7 +690,7 @@ std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename, trace::Span OverallTracer("LoadIndex"); auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename); if (!Buffer) { - llvm::errs() << "Can't open " << SymbolFilename << "\n"; + elog("Can't open {0}", SymbolFilename); return nullptr; } @@ -707,7 +707,7 @@ std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename, if (I->Relations) Relations = std::move(*I->Relations); } else { - llvm::errs() << "Bad Index: " << llvm::toString(I.takeError()) << "\n"; + elog("Bad Index: {0}", I.takeError()); return nullptr; } } diff --git a/clang-tools-extra/clangd/test/log.test b/clang-tools-extra/clangd/test/log.test new file mode 100644 index 00000000000..7f17f072fd8 --- /dev/null +++ b/clang-tools-extra/clangd/test/log.test @@ -0,0 +1,9 @@ +# RUN: not env CLANGD_FLAGS=-index-file=no-such-index clangd -lit-test </dev/null 2>&1 >/dev/null | FileCheck %s +CHECK: I[{{.*}}] clangd version {{.*}} +CHECK: Working directory: {{.*}} +CHECK: argv[0]: clangd +CHECK: argv[1]: -lit-test +CHECK: CLANGD_FLAGS: -index-file=no-such-index +CHECK: E[{{.*}}] Can't open no-such-index +CHECK: Starting LSP over stdin/stdout + diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index 0f9fad83de5..74809e499ce 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" @@ -433,15 +434,19 @@ int main(int argc, char *argv[]) { llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) { OS << clang::getClangToolFullVersion("clangd") << "\n"; }); + const char *FlagsEnvVar = "CLANGD_FLAGS"; + const char *Overview = + R"(clangd is a language server that provides IDE-like features to editors. + +It should be used via an editor plugin rather than invoked directly. For more information, see: + https://clang.llvm.org/extra/clangd/ + https://microsoft.github.io/language-server-protocol/ + +clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable. +)"; llvm::cl::HideUnrelatedOptions(ClangdCategories); - llvm::cl::ParseCommandLineOptions( - argc, argv, - "clangd is a language server that provides IDE-like features to editors. " - "\n\nIt should be used via an editor plugin rather than invoked " - "directly. " - "For more information, see:" - "\n\thttps://clang.llvm.org/extra/clangd.html" - "\n\thttps://microsoft.github.io/language-server-protocol/"); + llvm::cl::ParseCommandLineOptions(argc, argv, Overview, + /*Errs=*/nullptr, FlagsEnvVar); if (Test) { Sync = true; InputStyle = JSONStreamStyle::Delimited; @@ -526,6 +531,8 @@ int main(int argc, char *argv[]) { } for (int I = 0; I < argc; ++I) log("argv[{0}]: {1}", I, argv[I]); + if (auto EnvFlags = llvm::sys::Process::GetEnv(FlagsEnvVar)) + log("{0}: {1}", FlagsEnvVar, *EnvFlags); // If --compile-commands-dir arg was invoked, check value and override default // path. |