summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd')
-rw-r--r--clang-tools-extra/clangd/JSONRPCDispatcher.cpp33
-rw-r--r--clang-tools-extra/clangd/JSONRPCDispatcher.h11
-rw-r--r--clang-tools-extra/clangd/tool/ClangdMain.cpp24
3 files changed, 14 insertions, 54 deletions
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
index 979402c0390..6641aae6a2f 100644
--- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
+++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
@@ -37,14 +37,6 @@ void JSONOutput::log(const Twine &Message) {
Logs.flush();
}
-void JSONOutput::mirrorInput(const Twine &Message) {
- if (!InputMirror)
- return;
-
- *InputMirror << Message;
- InputMirror->flush();
-}
-
void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
Output.log("Method ignored.\n");
// Return that this method is unsupported.
@@ -155,14 +147,6 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
continue;
}
- Out.mirrorInput(Line);
- // Mirror '\n' that gets consumed by std::getline, but is not included in
- // the resulting Line.
- // Note that '\r' is part of Line, so we don't need to mirror it
- // separately.
- if (!In.eof())
- Out.mirrorInput("\n");
-
llvm::StringRef LineRef(Line);
// We allow YAML-style comments in headers. Technically this isn't part
@@ -179,8 +163,9 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
if (LineRef.consume_front("Content-Length: ")) {
if (ContentLength != 0) {
Out.log("Warning: Duplicate Content-Length header received. "
- "The previous value for this message (" +
- std::to_string(ContentLength) + ") was ignored.\n");
+ "The previous value for this message ("
+ + std::to_string(ContentLength)
+ + ") was ignored.\n");
}
llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
@@ -200,13 +185,15 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
// parser.
std::vector<char> JSON(ContentLength + 1, '\0');
In.read(JSON.data(), ContentLength);
- Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
// If the stream is aborted before we read ContentLength bytes, In
// will have eofbit and failbit set.
if (!In) {
- Out.log("Input was aborted. Read only " + std::to_string(In.gcount()) +
- " bytes of expected " + std::to_string(ContentLength) + ".\n");
+ Out.log("Input was aborted. Read only "
+ + std::to_string(In.gcount())
+ + " bytes of expected "
+ + std::to_string(ContentLength)
+ + ".\n");
break;
}
@@ -222,8 +209,8 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
if (IsDone)
break;
} else {
- Out.log("Warning: Missing Content-Length header, or message has zero "
- "length.\n");
+ Out.log( "Warning: Missing Content-Length header, or message has zero "
+ "length.\n" );
}
}
}
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.h b/clang-tools-extra/clangd/JSONRPCDispatcher.h
index a05aaeac8b7..ba6ff557c31 100644
--- a/clang-tools-extra/clangd/JSONRPCDispatcher.h
+++ b/clang-tools-extra/clangd/JSONRPCDispatcher.h
@@ -24,9 +24,8 @@ namespace clangd {
/// them.
class JSONOutput : public Logger {
public:
- JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs,
- llvm::raw_ostream *InputMirror = nullptr)
- : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {}
+ JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs)
+ : Outs(Outs), Logs(Logs) {}
/// Emit a JSONRPC message.
void writeMessage(const Twine &Message);
@@ -34,15 +33,9 @@ public:
/// Write to the logging stream.
void log(const Twine &Message) override;
- /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is
- /// null.
- /// Unlike other methods of JSONOutput, mirrorInput is not thread-safe.
- void mirrorInput(const Twine &Message);
-
private:
llvm::raw_ostream &Outs;
llvm::raw_ostream &Logs;
- llvm::raw_ostream *InputMirror;
std::mutex StreamMutex;
};
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index cd7d44b32c3..0634c94528e 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -9,12 +9,10 @@
#include "ClangdLSPServer.h"
#include "JSONRPCDispatcher.h"
-#include "Path.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
-#include "llvm/Support/raw_ostream.h"
#include <iostream>
#include <memory>
#include <string>
@@ -45,17 +43,11 @@ static llvm::cl::opt<bool> RunSynchronously(
llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
llvm::cl::init(false), llvm::cl::Hidden);
-static llvm::cl::opt<Path>
+static llvm::cl::opt<std::string>
ResourceDir("resource-dir",
llvm::cl::desc("Directory for system clang headers"),
llvm::cl::init(""), llvm::cl::Hidden);
-static llvm::cl::opt<Path> InputMirrorFile(
- "input-mirror-file",
- llvm::cl::desc(
- "Mirror all LSP input to the specified file. Useful for debugging."),
- llvm::cl::init(""), llvm::cl::Hidden);
-
int main(int argc, char *argv[]) {
llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
@@ -71,21 +63,9 @@ int main(int argc, char *argv[]) {
WorkerThreadsCount = 0;
/// Validate command line arguments.
- llvm::Optional<llvm::raw_fd_ostream> InputMirrorStream;
- if (!InputMirrorFile.empty()) {
- std::error_code EC;
- InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC, llvm::sys::fs::F_RW);
- if (EC) {
- InputMirrorStream.reset();
- llvm::errs() << "Error while opening an input mirror file: "
- << EC.message();
- }
- }
-
llvm::raw_ostream &Outs = llvm::outs();
llvm::raw_ostream &Logs = llvm::errs();
- JSONOutput Out(Outs, Logs,
- InputMirrorStream ? InputMirrorStream.getPointer() : nullptr);
+ JSONOutput Out(Outs, Logs);
// If --compile-commands-dir arg was invoked, check value and override default
// path.
OpenPOWER on IntegriCloud