From 5d1fd4ce4ddf4923fb46499e7679f1eb068987e9 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 1 Dec 2017 17:04:39 -0800 Subject: [PATCH] Remove a bunch of std::cerr in favor of LOG_S --- src/clang_translation_unit.cc | 3 +-- src/command_line.cc | 15 +++-------- src/file_consumer.cc | 7 ++--- src/indexer.cc | 49 +++-------------------------------- src/language_server_api.cc | 7 +++-- src/options.cc | 5 ++-- src/platform.cc | 12 ++++----- src/utils.cc | 9 +------ src/working_files.cc | 35 ++++++++----------------- 9 files changed, 35 insertions(+), 107 deletions(-) diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index b2fbec2a..4eb90582 100644 --- a/src/clang_translation_unit.cc +++ b/src/clang_translation_unit.cc @@ -73,8 +73,7 @@ void EmitDiagnostics(std::string path, output += "\n"; } - std::cerr << output; - std::cerr.flush(); + LOG_S(WARNING) << output; } } // namespace diff --git a/src/command_line.cc b/src/command_line.cc index 86559aee..4ffcd201 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1161,12 +1161,11 @@ bool IndexMain_DoCreateIndexUpdate(Config* config, PRINT_SECTION(index_make_delta); output << "\n total: " << FormatMicroseconds(total); output << " path: " << response->current_index->path; - output << std::endl; - std::cerr << output.rdbuf(); + LOG_S(INFO) << output.rdbuf(); #undef PRINT_SECTION if (response->is_interactive) - std::cerr << "Applying IndexUpdate" << std::endl << update.ToString() << std::endl; + LOG_S(INFO) << "Applying IndexUpdate" << std::endl << update.ToString(); #endif Index_OnIndexed reply(update, response->perf); @@ -1432,7 +1431,7 @@ bool QueryDbMainLoop(Config* config, rapidjson::StringBuffer output; Writer writer(output); Reflect(writer, request->params.initializationOptions); - std::cerr << output.GetString() << std::endl; + LOG_S(INFO) << "Init parameters: " << output.GetString(); if (request->params.rootUri) { std::string project_path = request->params.rootUri->GetPath(); @@ -1591,9 +1590,6 @@ bool QueryDbMainLoop(Config* config, time.Reset(); project->ForAllFilteredFiles( config, [&](int i, const Project::Entry& entry) { - // std::cerr << "[" << i << "/" << (project->entries.size() - 1) - // << "] Dispatching index request for file " << entry.filename - // << std::endl; bool is_interactive = working_files->GetFileByFilename(entry.filename) != nullptr; queue->index_request.Enqueue(Index_Request( @@ -3044,8 +3040,6 @@ void LaunchStdinLoop(Config* config, (*request_times)[message->method_id] = Timer(); - // std::cerr << "[stdin] Got message " << IpcIdToString(message->method_id) - // << std::endl; switch (message->method_id) { case IpcId::Initialized: { // TODO: don't send output until we get this notification @@ -3129,9 +3123,6 @@ void LaunchStdoutThread(std::unordered_map* request_times, } for (auto& message : messages) { - // std::cerr << "[stdout] Processing message " << - // IpcIdToString(message->method_id) << std::endl; - switch (message->method_id) { case IpcId::Cout: { auto msg = message->As(); diff --git a/src/file_consumer.cc b/src/file_consumer.cc index 31563652..937f19cf 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -5,6 +5,8 @@ #include "platform.h" #include "utils.h" +#include + bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) { return a.data[0] == b.data[0] && a.data[1] == b.data[1] && a.data[2] == b.data[2]; @@ -88,8 +90,7 @@ void FileConsumer::EmitError(CXFile file) const { std::string file_name = ToString(clang_getFileName(file)); // TODO: Investigate this more, why can we get an empty file name? if (!file_name.empty()) { - std::string error_message = "Could not get unique file id for " + - file_name + " when parsing " + parse_file_; - std::cerr << error_message << std::endl; + LOG_S(ERROR) << "Could not get unique file id for " << file_name + << " when parsing " << parse_file_; } } \ No newline at end of file diff --git a/src/indexer.cc b/src/indexer.cc index 39eaeeb2..b687856d 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -445,7 +445,6 @@ std::string IndexFile::ToString() { IndexType::IndexType(IndexTypeId id, const std::string& usr) : def(usr), id(id) { assert(usr.size() > 0); - // std::cerr << "Creating type with usr " << usr << std::endl; } void RemoveItem(std::vector& ranges, Range to_remove) { @@ -699,10 +698,6 @@ optional AddDeclTypeUsages( ClangCursor decl_cursor, const CXIdxContainerInfo* semantic_container, const CXIdxContainerInfo* lexical_container) { - // std::cerr << std::endl << "AddDeclUsages " << decl_cursor.get_spelling() << - // std::endl; - // Dump(decl_cursor); - // // The general AST format for definitions follows this pattern: // @@ -793,13 +788,9 @@ optional AddDeclTypeUsages( // Foo::Foo() {} // if (!decl_cursor.is_definition()) { - // TODO: I don't think this resolution ever works. ClangCursor def = decl_cursor.get_definition(); - if (def.get_kind() != CXCursor_FirstInvalid) { - std::cerr << "Successful resolution of decl usage to definition" - << std::endl; + if (def.get_kind() != CXCursor_FirstInvalid) decl_cursor = def; - } } process_last_type_ref = false; } @@ -872,8 +863,6 @@ ClangCursor::VisitResult AddDeclInitializerUsagesVisitor(ClangCursor cursor, break; Range loc = ResolveSpelling(cursor.cx_cursor); - // std::cerr << "Adding usage to id=" << ref_id.id << " usr=" << ref_usr - // << " at " << loc.ToString() << std::endl; IndexVarId ref_id = db->ToVarId(ref_usr); IndexVar* ref_def = db->Resolve(ref_id); UniqueAdd(ref_def->uses, loc); @@ -996,10 +985,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { NamespaceHelper* ns = ¶m->ns; - // std::cerr << "DECL kind=" << decl->entityInfo->kind << " at " << - // db->id_cache.Resolve(decl->cursor, false).ToPrettyString(&db->id_cache) << - // std::endl; - switch (decl->entityInfo->kind) { case CXIdxEntity_CXXNamespace: { ns->RegisterQualifiedName(decl->entityInfo->USR, decl->semanticContainer, @@ -1052,9 +1037,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { } UniqueAdd(var->uses, decl_loc_spelling); - // std::cerr << std::endl << "Visiting declaration" << std::endl; - // Dump(decl_cursor); - AddDeclInitializerUsages(db, decl_cursor); var = db->Resolve(var_id); @@ -1213,9 +1195,10 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // FIXME: this happens for destructors when there are multiple // parent classes. - if (num_overridden > 1) + if (num_overridden > 1) { std::cerr << "[indexer]: warning: multiple base overrides for " << func->def.detailed_name << std::endl; + } for (unsigned i = 0; i < num_overridden; ++i) { ClangCursor parent = overridden[i]; @@ -1376,14 +1359,6 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { clang_getCursorLocation(ref->referencedEntity->cursor))) return; - // assert(AreEqualLocations(ref->loc, ref->cursor)); - - // if (clang_Location_isInSystemHeader(clang_getCursorLocation(ref->cursor)) - // || - // clang_Location_isInSystemHeader( - // clang_getCursorLocation(ref->referencedEntity->cursor))) - // return; - // TODO: Use clang_getFileUniqueID CXFile file; clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, @@ -1393,22 +1368,6 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { if (!db) return; - // ref->cursor mainFile=0 - // ref->loc mainFile=1 - // ref->referencedEntity mainFile=1 - // - // Regardless, we need to do more advanced location processing to handle - // multiple output IndexFile instances. - // bool mainFile = - // clang_Location_isFromMainFile(clang_indexLoc_getCXSourceLocation(ref->loc)); - // Range loc_spelling = param->db->id_cache.ForceResolveSpelling(ref->cursor, - // false /*interesting*/); std::cerr << "mainFile: " << mainFile << ", loc: " - // << loc_spelling.ToString() << std::endl; - - // Don't index references that are not from the main file. - // if (!clang_Location_isFromMainFile(clang_getCursorLocation(ref->cursor))) - // return; - ClangCursor cursor(ref->cursor); switch (ref->referencedEntity->kind) { @@ -1659,7 +1618,6 @@ std::vector> ParseWithTu( CXFile cx_file = clang_getFile(tu->cx_tu, file.c_str()); param.primary_file = ConsumeFile(¶m, cx_file); - // std::cerr << "!! [START] Indexing " << file << std::endl; CXIndexAction index_action = clang_IndexAction_create(index->cx_index); // NOTE: libclang re-enables crash recovery whenever a new index is created. @@ -1681,7 +1639,6 @@ std::vector> ParseWithTu( } clang_IndexAction_dispose(index_action); - // std::cerr << "!! [END] Indexing " << file << std::endl; ClangCursor(clang_getTranslationUnitCursor(tu->cx_tu)) .VisitChildren(&VisitMacroDefinitionAndExpansions, ¶m); diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 710a5dd4..f93c835d 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -19,7 +19,7 @@ void Reflect(Reader& visitor, lsRequestId& id) { else if (visitor.IsString()) Reflect(visitor, id.id1); else - std::cerr << "Unable to deserialize id" << std::endl; + LOG_S(WARNING) << "Unable to deserialize id"; } MessageRegistry* MessageRegistry::instance_ = nullptr; @@ -161,7 +161,7 @@ std::unique_ptr MessageRegistry::ReadMessageFromStdin( std::unique_ptr MessageRegistry::Parse(Reader& visitor) { if (!visitor.HasMember("jsonrpc") || std::string(visitor["jsonrpc"].GetString()) != "2.0") { - std::cerr << "Bad or missing jsonrpc version" << std::endl; + LOG_S(FATAL) << "Bad or missing jsonrpc version"; exit(1); } @@ -170,7 +170,7 @@ std::unique_ptr MessageRegistry::Parse(Reader& visitor) { if (allocators.find(method) == allocators.end()) { LOG_S(ERROR) << "Unable to find registered handler for method \"" << method - << "\"" << std::endl; + << "\""; return nullptr; } @@ -233,7 +233,6 @@ void lsDocumentUri::SetPath(const std::string& path) { #else raw_uri = "file://" + raw_uri; #endif - // std::cerr << "Set uri to " << raw_uri << " from " << path; } std::string lsDocumentUri::GetPath() const { diff --git a/src/options.cc b/src/options.cc index 63f47deb..4d603f19 100644 --- a/src/options.cc +++ b/src/options.cc @@ -1,5 +1,7 @@ #include "options.h" +#include + #include std::unordered_map ParseOptions(int argc, @@ -13,8 +15,7 @@ std::unordered_map ParseOptions(int argc, if (arg[0] != '-') { if (previous_arg.size() == 0) { - std::cerr << "Invalid arguments; switches must start with -" - << std::endl; + LOG_S(FATAL) << "Invalid arguments; switches must start with -"; exit(1); } diff --git a/src/platform.cc b/src/platform.cc index bbb1feb7..1c5c475e 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -1,5 +1,8 @@ #include "platform.h" +#include +#include + #include #include #include @@ -7,8 +10,6 @@ #include #include -#include - namespace { // See http://stackoverflow.com/a/236803 @@ -73,16 +74,15 @@ void MakeDirectoryRecursive(std::string path) { } if (first_success == -1) { - std::cerr << "Failed to make any parent directory for " << path - << std::endl; + LOG_S(FATAL) << "Failed to make any parent directory for " << path; exit(1); } // Make all child directories. for (size_t i = first_success + 1; i <= components.size(); ++i) { if (TryMakeDirectory(prefix + Join(components, '/', i)) == false) { - std::cerr << "Failed making directory for " << path - << " even after creating parent directories" << std::endl; + LOG_S(FATAL) << "Failed making directory for " << path + << " even after creating parent directories"; exit(1); } } diff --git a/src/utils.cc b/src/utils.cc index 7bd98995..58dfb97f 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -240,15 +240,8 @@ std::vector ReadLines(std::string filename) { std::vector result; std::ifstream input(filename); - for (std::string line; SafeGetline(input, line);) { -#if false - LOG_S(INFO) << "!! got line |" << line << "|"; - for (char c : line) - std::cout << (int)c << ","; - std::cout << std::endl; -#endif + for (std::string line; SafeGetline(input, line);) result.push_back(line); - } return result; } diff --git a/src/working_files.cc b/src/working_files.cc index b23b0955..2f64555e 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -4,6 +4,7 @@ #include "position.h" #include +#include #include @@ -86,8 +87,8 @@ optional WorkingFile::GetBufferLineFromIndexLine(int index_line) const { // TODO: reenable this assert once we are using the real indexed file. // assert(index_line >= 1 && index_line <= index_lines.size()); if (index_line < 1 || index_line > index_lines.size()) { - std::cerr << "!! Bad index_line (got " << index_line << ", expected [1, " - << index_lines.size() << "])" << std::endl; + LOG_S(WARNING) << "Bad index_line (got " << index_line << ", expected [1, " + << index_lines.size() << "])"; return nullopt; } @@ -123,8 +124,8 @@ optional WorkingFile::GetIndexLineFromBufferLine(int buffer_line) const { // Note: |index_line| and |buffer_line| are 1-based. // assert(buffer_line >= 1 && buffer_line < all_buffer_lines.size()); if (buffer_line < 1 || buffer_line > all_buffer_lines.size()) { - std::cerr << "!! Bad buffer_line (got " << buffer_line << ", expected [1, " - << all_buffer_lines.size() << "])" << std::endl; + LOG_S(WARNING) << "Bad buffer_line (got " << buffer_line + << ", expected [1, " << all_buffer_lines.size() << "])"; return nullopt; } @@ -165,9 +166,8 @@ optional WorkingFile::GetBufferLineContentFromIndexLine( return nullopt; if (*buffer_line < 1 || *buffer_line >= all_buffer_lines.size()) { - std::cerr << "GetBufferLineContentFromIndexLine buffer line lookup not in " - "all_buffer_lines" - << std::endl; + LOG_S(WARNING) << "GetBufferLineContentFromIndexLine buffer line lookup not" + << " in all_buffer_lines"; return nullopt; } @@ -315,18 +315,15 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) { std::string filename = change.textDocument.uri.GetPath(); WorkingFile* file = GetFileByFilenameNoLock(filename); if (!file) { - std::cerr << "Could not change " << filename << " because it was not open" - << std::endl; + LOG_S(WARNING) << "Could not change " << filename + << " because it was not open"; return; } file->version = change.textDocument.version; - // std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - // std::cerr << "VERSION " << change.textDocument.version << std::endl; for (const Ipc_TextDocumentDidChange::lsTextDocumentContentChangeEvent& diff : change.contentChanges) { - // std::cerr << "|" << file->buffer_content << "|" << std::endl; // Per the spec replace everything if the rangeLength and range are not set. // See https://github.com/Microsoft/language-server-protocol/issues/9. if (diff.rangeLength == -1 && @@ -334,7 +331,6 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) { diff.range.end == lsPosition::kZeroPosition) { file->buffer_content = diff.text; file->OnBufferContentUpdated(); - // std::cerr << "-> Replacing entire content"; } else { int start_offset = GetOffsetForPosition(diff.range.start, file->buffer_content); @@ -344,21 +340,12 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) { if (length == -1) { length = end_offset - start_offset; } - // std::cerr << "-> Applying diff start=" << diff.range.start.ToString() - // << ", end=" << diff.range.end.ToString() << ", start_offset=" << - // start_offset << std::endl; file->buffer_content.replace( file->buffer_content.begin() + start_offset, file->buffer_content.begin() + start_offset + length, diff.text); file->OnBufferContentUpdated(); } - - // std::cerr << "|" << file->buffer_content << "|" << std::endl; } - // std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - - // std::cerr << std::endl << std::endl << "--------" << file->content << - // "--------" << std::endl << std::endl; } void WorkingFiles::OnClose(const Ipc_TextDocumentDidClose::Params& close) { @@ -373,8 +360,8 @@ void WorkingFiles::OnClose(const Ipc_TextDocumentDidClose::Params& close) { } } - std::cerr << "Could not close " << filename << " because it was not open" - << std::endl; + LOG_S(WARNING) << "Could not close " << filename + << " because it was not open"; } std::vector WorkingFiles::AsUnsavedFiles() {