[clangd] Move isDone from the JSONOutput to ShutdownHandler.

This is just as easy to check from main but prevents random code from
shutting down the server.

llvm-svn: 294760
This commit is contained in:
Benjamin Kramer 2017-02-10 17:25:38 +00:00
parent f1423e893d
commit e15fe37506
3 changed files with 10 additions and 11 deletions

View File

@ -30,8 +30,9 @@ int main(int argc, char *argv[]) {
JSONRPCDispatcher Dispatcher(llvm::make_unique<Handler>(Out));
Dispatcher.registerHandler("initialize",
llvm::make_unique<InitializeHandler>(Out));
Dispatcher.registerHandler("shutdown",
llvm::make_unique<ShutdownHandler>(Out));
auto ShutdownPtr = llvm::make_unique<ShutdownHandler>(Out);
auto *ShutdownHandler = ShutdownPtr.get();
Dispatcher.registerHandler("shutdown",std::move(ShutdownPtr));
Dispatcher.registerHandler(
"textDocument/didOpen",
llvm::make_unique<TextDocumentDidOpenHandler>(Out, Store));
@ -92,7 +93,7 @@ int main(int argc, char *argv[]) {
Logs << "JSON dispatch failed!\n";
// If we're done, exit the loop.
if (Out.isDone())
if (ShutdownHandler->isDone())
break;
}
}

View File

@ -31,17 +31,10 @@ public:
/// Get the logging stream.
llvm::raw_ostream &logs() { return Logs; }
/// Use this to indicate that the output stream should be closed and the
/// process should terminate.
void setDone() { Done = true; }
bool isDone() const { return Done; }
private:
llvm::raw_ostream &Outs;
llvm::raw_ostream &Logs;
bool Done = false;
std::mutex StreamMutex;
};

View File

@ -42,8 +42,13 @@ struct ShutdownHandler : Handler {
ShutdownHandler(JSONOutput &Output) : Handler(Output) {}
void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
Output.setDone();
IsDone = true;
}
bool isDone() const { return IsDone; }
private:
bool IsDone = false;
};
struct TextDocumentDidOpenHandler : Handler {