forked from OSchip/llvm-project
[clangd] Synchronize logs access.
I don't think that this is necessary for correctness, but makes tsan much more useful. llvm-svn: 295194
This commit is contained in:
parent
3858b7d6e9
commit
e14bd4246d
|
@ -150,7 +150,7 @@ ASTManager::getOrCreateCompilationDatabaseForFile(StringRef Uri) {
|
|||
|
||||
std::string Error;
|
||||
I = tooling::CompilationDatabase::autoDetectFromSource(Uri, Error);
|
||||
Output.logs() << "Failed to load compilation database: " << Error << '\n';
|
||||
Output.log("Failed to load compilation database: " + Twine(Error) + "\n");
|
||||
return I.get();
|
||||
}
|
||||
|
||||
|
|
|
@ -88,12 +88,11 @@ int main(int argc, char *argv[]) {
|
|||
if (Len > 0) {
|
||||
llvm::StringRef JSONRef(JSON.data(), Len);
|
||||
// Log the message.
|
||||
Logs << "<-- " << JSONRef << '\n';
|
||||
Logs.flush();
|
||||
Out.log("<-- " + JSONRef + "\n");
|
||||
|
||||
// Finally, execute the action for this JSON message.
|
||||
if (!Dispatcher.call(JSONRef))
|
||||
Logs << "JSON dispatch failed!\n";
|
||||
Out.log("JSON dispatch failed!\n");
|
||||
|
||||
// If we're done, exit the loop.
|
||||
if (ShutdownHandler->isDone())
|
||||
|
|
|
@ -29,8 +29,14 @@ void JSONOutput::writeMessage(const Twine &Message) {
|
|||
Outs.flush();
|
||||
}
|
||||
|
||||
void JSONOutput::log(const Twine &Message) {
|
||||
std::lock_guard<std::mutex> Guard(StreamMutex);
|
||||
Logs << Message;
|
||||
Logs.flush();
|
||||
}
|
||||
|
||||
void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
|
||||
Output.logs() << "Method ignored.\n";
|
||||
Output.log("Method ignored.\n");
|
||||
// Return that this method is unsupported.
|
||||
writeMessage(
|
||||
R"({"jsonrpc":"2.0","id":)" + ID +
|
||||
|
@ -38,7 +44,7 @@ void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
|
|||
}
|
||||
|
||||
void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
|
||||
Output.logs() << "Notification ignored.\n";
|
||||
Output.log("Notification ignored.\n");
|
||||
}
|
||||
|
||||
void JSONRPCDispatcher::registerHandler(StringRef Method,
|
||||
|
|
|
@ -28,8 +28,8 @@ public:
|
|||
/// Emit a JSONRPC message.
|
||||
void writeMessage(const Twine &Message);
|
||||
|
||||
/// Get the logging stream.
|
||||
llvm::raw_ostream &logs() { return Logs; }
|
||||
/// Write to the logging stream.
|
||||
void log(const Twine &Message);
|
||||
|
||||
private:
|
||||
llvm::raw_ostream &Outs;
|
||||
|
|
|
@ -17,7 +17,7 @@ void TextDocumentDidOpenHandler::handleNotification(
|
|||
llvm::yaml::MappingNode *Params) {
|
||||
auto DOTDP = DidOpenTextDocumentParams::parse(Params);
|
||||
if (!DOTDP) {
|
||||
Output.logs() << "Failed to decode DidOpenTextDocumentParams!\n";
|
||||
Output.log("Failed to decode DidOpenTextDocumentParams!\n");
|
||||
return;
|
||||
}
|
||||
Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
|
||||
|
@ -27,7 +27,7 @@ void TextDocumentDidChangeHandler::handleNotification(
|
|||
llvm::yaml::MappingNode *Params) {
|
||||
auto DCTDP = DidChangeTextDocumentParams::parse(Params);
|
||||
if (!DCTDP || DCTDP->contentChanges.size() != 1) {
|
||||
Output.logs() << "Failed to decode DidChangeTextDocumentParams!\n";
|
||||
Output.log("Failed to decode DidChangeTextDocumentParams!\n");
|
||||
return;
|
||||
}
|
||||
// We only support full syncing right now.
|
||||
|
@ -91,7 +91,7 @@ void TextDocumentRangeFormattingHandler::handleMethod(
|
|||
llvm::yaml::MappingNode *Params, StringRef ID) {
|
||||
auto DRFP = DocumentRangeFormattingParams::parse(Params);
|
||||
if (!DRFP) {
|
||||
Output.logs() << "Failed to decode DocumentRangeFormattingParams!\n";
|
||||
Output.log("Failed to decode DocumentRangeFormattingParams!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void TextDocumentFormattingHandler::handleMethod(
|
|||
llvm::yaml::MappingNode *Params, StringRef ID) {
|
||||
auto DFP = DocumentFormattingParams::parse(Params);
|
||||
if (!DFP) {
|
||||
Output.logs() << "Failed to decode DocumentFormattingParams!\n";
|
||||
Output.log("Failed to decode DocumentFormattingParams!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue