[PATCH] D65153: [clangd] Also accept flags from CLANGD_FLAGS variable.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 25 00:56:09 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL366991: [clangd] Also accept flags from CLANGD_FLAGS variable. (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65153?vs=211307&id=211681#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65153/new/

https://reviews.llvm.org/D65153

Files:
  clang-tools-extra/trunk/clangd/index/Serialization.cpp
  clang-tools-extra/trunk/clangd/test/log.test
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp
@@ -690,7 +690,7 @@
   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 @@
       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;
     }
   }
Index: clang-tools-extra/trunk/clangd/test/log.test
===================================================================
--- clang-tools-extra/trunk/clangd/test/log.test
+++ clang-tools-extra/trunk/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
+
Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/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 @@
   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 @@
   }
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65153.211681.patch
Type: text/x-patch
Size: 3452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190725/734fe944/attachment.bin>


More information about the cfe-commits mailing list