forked from OSchip/llvm-project
[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:
parent
f1423e893d
commit
e15fe37506
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue