summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/tool/ClangdMain.cpp
blob: 199c298b21c3758f91dc650cc5a5fd8d85bd193e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===--- ClangdMain.cpp - clangd server loop ------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ClangdLSPServer.h"
#include "JSONRPCDispatcher.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"

#include <iostream>
#include <memory>
#include <string>

using namespace clang;
using namespace clang::clangd;

static llvm::cl::opt<bool>
    RunSynchronously("run-synchronously",
                     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");

  llvm::raw_ostream &Outs = llvm::outs();
  llvm::raw_ostream &Logs = llvm::errs();
  JSONOutput Out(Outs, Logs);

  // Change stdin to binary to not lose \r\n on windows.
  llvm::sys::ChangeStdinToBinary();

  llvm::Optional<StringRef> ResourceDirRef = None;
  if (!ResourceDir.empty())
    ResourceDirRef = ResourceDir;
  ClangdLSPServer LSPServer(Out, RunSynchronously, ResourceDirRef);
  LSPServer.run(std::cin);
}
OpenPOWER on IntegriCloud