2017-04-13 01:13:08 +08:00
|
|
|
//===--- ClangdMain.cpp - clangd server loop ------------------------------===//
|
2017-02-07 18:28:20 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "ClangdLSPServer.h"
|
2017-05-16 22:40:30 +08:00
|
|
|
#include "JSONRPCDispatcher.h"
|
2017-03-02 00:16:29 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2017-02-07 18:28:20 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2017-02-07 20:40:59 +08:00
|
|
|
#include "llvm/Support/Program.h"
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
#include <iostream>
|
2017-05-16 17:38:59 +08:00
|
|
|
#include <memory>
|
2017-02-07 18:28:20 +08:00
|
|
|
#include <string>
|
2017-05-16 17:38:59 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2017-02-07 18:28:20 +08:00
|
|
|
using namespace clang::clangd;
|
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
RunSynchronously("run-synchronously",
|
|
|
|
llvm::cl::desc("parse on main thread"),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
|
|
|
|
2017-07-19 23:43:35 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
ResourceDir("resource-dir",
|
|
|
|
llvm::cl::desc("directory for system clang headers"),
|
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2017-03-02 00:16:29 +08:00
|
|
|
llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
|
2017-05-16 22:40:30 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
llvm::raw_ostream &Outs = llvm::outs();
|
|
|
|
llvm::raw_ostream &Logs = llvm::errs();
|
2017-02-10 22:08:40 +08:00
|
|
|
JSONOutput Out(Outs, Logs);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-02-07 20:40:59 +08:00
|
|
|
// Change stdin to binary to not lose \r\n on windows.
|
|
|
|
llvm::sys::ChangeStdinToBinary();
|
|
|
|
|
2017-07-19 23:43:35 +08:00
|
|
|
llvm::Optional<StringRef> ResourceDirRef = None;
|
|
|
|
if (!ResourceDir.empty())
|
|
|
|
ResourceDirRef = ResourceDir;
|
|
|
|
ClangdLSPServer LSPServer(Out, RunSynchronously, ResourceDirRef);
|
2017-05-16 22:40:30 +08:00
|
|
|
LSPServer.run(std::cin);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|