[clang-tools-extra] r308486 - [clangd] Allow specifying -resource-dir

Krasimir Georgiev via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 19 08:43:35 PDT 2017


Author: krasimir
Date: Wed Jul 19 08:43:35 2017
New Revision: 308486

URL: http://llvm.org/viewvc/llvm-project?rev=308486&view=rev
Log:
[clangd] Allow specifying -resource-dir

Summary: This patch allows clangd to specify its -resource-dir.

Reviewers: bkramer, klimek

Reviewed By: bkramer

Subscribers: cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D35617

Modified:
    clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
    clang-tools-extra/trunk/clangd/ClangdLSPServer.h
    clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=308486&r1=308485&r2=308486&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jul 19 08:43:35 2017
@@ -216,9 +216,10 @@ void ClangdLSPServer::LSPProtocolCallbac
       R"(,"result":[)" + Locations + R"(]})");
 }
 
-ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, bool RunSynchronously)
+ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+                                 llvm::Optional<StringRef> ResourceDir)
     : Out(Out), DiagConsumer(*this),
-      Server(CDB, DiagConsumer, FSProvider, RunSynchronously) {}
+      Server(CDB, DiagConsumer, FSProvider, RunSynchronously, ResourceDir) {}
 
 void ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=308486&r1=308485&r2=308486&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Jul 19 08:43:35 2017
@@ -15,6 +15,7 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/Optional.h"
 
 namespace clang {
 namespace clangd {
@@ -25,7 +26,8 @@ class JSONOutput;
 /// dispatch and ClangdServer together.
 class ClangdLSPServer {
 public:
-  ClangdLSPServer(JSONOutput &Out, bool RunSynchronously);
+ ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+                 llvm::Optional<StringRef> ResourceDir);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be
   /// opened in binary mode. Output will be written using Out variable passed to

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=308486&r1=308485&r2=308486&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Jul 19 08:43:35 2017
@@ -25,6 +25,11 @@ static llvm::cl::opt<bool>
                      llvm::cl::desc("parse on main thread"),
                      llvm::cl::init(false), llvm::cl::Hidden);
 
+static llvm::cl::opt<std::string>
+    ResourceDir("resource-dir",
+                llvm::cl::desc("directory for system clang headers"),
+                llvm::cl::init(""), llvm::cl::Hidden);
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
@@ -35,6 +40,9 @@ int main(int argc, char *argv[]) {
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();
 
-  ClangdLSPServer LSPServer(Out, RunSynchronously);
+  llvm::Optional<StringRef> ResourceDirRef = None;
+  if (!ResourceDir.empty())
+    ResourceDirRef = ResourceDir;
+  ClangdLSPServer LSPServer(Out, RunSynchronously, ResourceDirRef);
   LSPServer.run(std::cin);
 }




More information about the cfe-commits mailing list