Remove a bunch of std::cerr in favor of LOG_S

This commit is contained in:
Jacob Dufault 2017-12-01 17:04:39 -08:00
parent cf5f465e9e
commit 5d1fd4ce4d
9 changed files with 35 additions and 107 deletions

View File

@ -73,8 +73,7 @@ void EmitDiagnostics(std::string path,
output += "\n"; output += "\n";
} }
std::cerr << output; LOG_S(WARNING) << output;
std::cerr.flush();
} }
} // namespace } // namespace

View File

@ -1161,12 +1161,11 @@ bool IndexMain_DoCreateIndexUpdate(Config* config,
PRINT_SECTION(index_make_delta); PRINT_SECTION(index_make_delta);
output << "\n total: " << FormatMicroseconds(total); output << "\n total: " << FormatMicroseconds(total);
output << " path: " << response->current_index->path; output << " path: " << response->current_index->path;
output << std::endl; LOG_S(INFO) << output.rdbuf();
std::cerr << output.rdbuf();
#undef PRINT_SECTION #undef PRINT_SECTION
if (response->is_interactive) if (response->is_interactive)
std::cerr << "Applying IndexUpdate" << std::endl << update.ToString() << std::endl; LOG_S(INFO) << "Applying IndexUpdate" << std::endl << update.ToString();
#endif #endif
Index_OnIndexed reply(update, response->perf); Index_OnIndexed reply(update, response->perf);
@ -1432,7 +1431,7 @@ bool QueryDbMainLoop(Config* config,
rapidjson::StringBuffer output; rapidjson::StringBuffer output;
Writer writer(output); Writer writer(output);
Reflect(writer, request->params.initializationOptions); Reflect(writer, request->params.initializationOptions);
std::cerr << output.GetString() << std::endl; LOG_S(INFO) << "Init parameters: " << output.GetString();
if (request->params.rootUri) { if (request->params.rootUri) {
std::string project_path = request->params.rootUri->GetPath(); std::string project_path = request->params.rootUri->GetPath();
@ -1591,9 +1590,6 @@ bool QueryDbMainLoop(Config* config,
time.Reset(); time.Reset();
project->ForAllFilteredFiles( project->ForAllFilteredFiles(
config, [&](int i, const Project::Entry& entry) { 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 = bool is_interactive =
working_files->GetFileByFilename(entry.filename) != nullptr; working_files->GetFileByFilename(entry.filename) != nullptr;
queue->index_request.Enqueue(Index_Request( queue->index_request.Enqueue(Index_Request(
@ -3044,8 +3040,6 @@ void LaunchStdinLoop(Config* config,
(*request_times)[message->method_id] = Timer(); (*request_times)[message->method_id] = Timer();
// std::cerr << "[stdin] Got message " << IpcIdToString(message->method_id)
// << std::endl;
switch (message->method_id) { switch (message->method_id) {
case IpcId::Initialized: { case IpcId::Initialized: {
// TODO: don't send output until we get this notification // TODO: don't send output until we get this notification
@ -3129,9 +3123,6 @@ void LaunchStdoutThread(std::unordered_map<IpcId, Timer>* request_times,
} }
for (auto& message : messages) { for (auto& message : messages) {
// std::cerr << "[stdout] Processing message " <<
// IpcIdToString(message->method_id) << std::endl;
switch (message->method_id) { switch (message->method_id) {
case IpcId::Cout: { case IpcId::Cout: {
auto msg = message->As<Ipc_Cout>(); auto msg = message->As<Ipc_Cout>();

View File

@ -5,6 +5,8 @@
#include "platform.h" #include "platform.h"
#include "utils.h" #include "utils.h"
#include <loguru.hpp>
bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) { bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) {
return a.data[0] == b.data[0] && a.data[1] == b.data[1] && return a.data[0] == b.data[0] && a.data[1] == b.data[1] &&
a.data[2] == b.data[2]; a.data[2] == b.data[2];
@ -88,8 +90,7 @@ void FileConsumer::EmitError(CXFile file) const {
std::string file_name = ToString(clang_getFileName(file)); std::string file_name = ToString(clang_getFileName(file));
// TODO: Investigate this more, why can we get an empty file name? // TODO: Investigate this more, why can we get an empty file name?
if (!file_name.empty()) { if (!file_name.empty()) {
std::string error_message = "Could not get unique file id for " + LOG_S(ERROR) << "Could not get unique file id for " << file_name
file_name + " when parsing " + parse_file_; << " when parsing " << parse_file_;
std::cerr << error_message << std::endl;
} }
} }

View File

@ -445,7 +445,6 @@ std::string IndexFile::ToString() {
IndexType::IndexType(IndexTypeId id, const std::string& usr) IndexType::IndexType(IndexTypeId id, const std::string& usr)
: def(usr), id(id) { : def(usr), id(id) {
assert(usr.size() > 0); assert(usr.size() > 0);
// std::cerr << "Creating type with usr " << usr << std::endl;
} }
void RemoveItem(std::vector<Range>& ranges, Range to_remove) { void RemoveItem(std::vector<Range>& ranges, Range to_remove) {
@ -699,10 +698,6 @@ optional<IndexTypeId> AddDeclTypeUsages(
ClangCursor decl_cursor, ClangCursor decl_cursor,
const CXIdxContainerInfo* semantic_container, const CXIdxContainerInfo* semantic_container,
const CXIdxContainerInfo* lexical_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: // The general AST format for definitions follows this pattern:
// //
@ -793,13 +788,9 @@ optional<IndexTypeId> AddDeclTypeUsages(
// Foo::Foo() {} // Foo::Foo() {}
// //
if (!decl_cursor.is_definition()) { if (!decl_cursor.is_definition()) {
// TODO: I don't think this resolution ever works.
ClangCursor def = decl_cursor.get_definition(); ClangCursor def = decl_cursor.get_definition();
if (def.get_kind() != CXCursor_FirstInvalid) { if (def.get_kind() != CXCursor_FirstInvalid)
std::cerr << "Successful resolution of decl usage to definition"
<< std::endl;
decl_cursor = def; decl_cursor = def;
}
} }
process_last_type_ref = false; process_last_type_ref = false;
} }
@ -872,8 +863,6 @@ ClangCursor::VisitResult AddDeclInitializerUsagesVisitor(ClangCursor cursor,
break; break;
Range loc = ResolveSpelling(cursor.cx_cursor); 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); IndexVarId ref_id = db->ToVarId(ref_usr);
IndexVar* ref_def = db->Resolve(ref_id); IndexVar* ref_def = db->Resolve(ref_id);
UniqueAdd(ref_def->uses, loc); UniqueAdd(ref_def->uses, loc);
@ -996,10 +985,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
NamespaceHelper* ns = &param->ns; NamespaceHelper* ns = &param->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) { switch (decl->entityInfo->kind) {
case CXIdxEntity_CXXNamespace: { case CXIdxEntity_CXXNamespace: {
ns->RegisterQualifiedName(decl->entityInfo->USR, decl->semanticContainer, 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); UniqueAdd(var->uses, decl_loc_spelling);
// std::cerr << std::endl << "Visiting declaration" << std::endl;
// Dump(decl_cursor);
AddDeclInitializerUsages(db, decl_cursor); AddDeclInitializerUsages(db, decl_cursor);
var = db->Resolve(var_id); 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 // FIXME: this happens for destructors when there are multiple
// parent classes. // parent classes.
if (num_overridden > 1) if (num_overridden > 1) {
std::cerr << "[indexer]: warning: multiple base overrides for " std::cerr << "[indexer]: warning: multiple base overrides for "
<< func->def.detailed_name << std::endl; << func->def.detailed_name << std::endl;
}
for (unsigned i = 0; i < num_overridden; ++i) { for (unsigned i = 0; i < num_overridden; ++i) {
ClangCursor parent = overridden[i]; ClangCursor parent = overridden[i];
@ -1376,14 +1359,6 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
clang_getCursorLocation(ref->referencedEntity->cursor))) clang_getCursorLocation(ref->referencedEntity->cursor)))
return; 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 // TODO: Use clang_getFileUniqueID
CXFile file; CXFile file;
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file,
@ -1393,22 +1368,6 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
if (!db) if (!db)
return; 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); ClangCursor cursor(ref->cursor);
switch (ref->referencedEntity->kind) { switch (ref->referencedEntity->kind) {
@ -1659,7 +1618,6 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
CXFile cx_file = clang_getFile(tu->cx_tu, file.c_str()); CXFile cx_file = clang_getFile(tu->cx_tu, file.c_str());
param.primary_file = ConsumeFile(&param, cx_file); param.primary_file = ConsumeFile(&param, cx_file);
// std::cerr << "!! [START] Indexing " << file << std::endl;
CXIndexAction index_action = clang_IndexAction_create(index->cx_index); CXIndexAction index_action = clang_IndexAction_create(index->cx_index);
// NOTE: libclang re-enables crash recovery whenever a new index is created. // NOTE: libclang re-enables crash recovery whenever a new index is created.
@ -1681,7 +1639,6 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
} }
clang_IndexAction_dispose(index_action); clang_IndexAction_dispose(index_action);
// std::cerr << "!! [END] Indexing " << file << std::endl;
ClangCursor(clang_getTranslationUnitCursor(tu->cx_tu)) ClangCursor(clang_getTranslationUnitCursor(tu->cx_tu))
.VisitChildren(&VisitMacroDefinitionAndExpansions, &param); .VisitChildren(&VisitMacroDefinitionAndExpansions, &param);

View File

@ -19,7 +19,7 @@ void Reflect(Reader& visitor, lsRequestId& id) {
else if (visitor.IsString()) else if (visitor.IsString())
Reflect(visitor, id.id1); Reflect(visitor, id.id1);
else else
std::cerr << "Unable to deserialize id" << std::endl; LOG_S(WARNING) << "Unable to deserialize id";
} }
MessageRegistry* MessageRegistry::instance_ = nullptr; MessageRegistry* MessageRegistry::instance_ = nullptr;
@ -161,7 +161,7 @@ std::unique_ptr<BaseIpcMessage> MessageRegistry::ReadMessageFromStdin(
std::unique_ptr<BaseIpcMessage> MessageRegistry::Parse(Reader& visitor) { std::unique_ptr<BaseIpcMessage> MessageRegistry::Parse(Reader& visitor) {
if (!visitor.HasMember("jsonrpc") || if (!visitor.HasMember("jsonrpc") ||
std::string(visitor["jsonrpc"].GetString()) != "2.0") { 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); exit(1);
} }
@ -170,7 +170,7 @@ std::unique_ptr<BaseIpcMessage> MessageRegistry::Parse(Reader& visitor) {
if (allocators.find(method) == allocators.end()) { if (allocators.find(method) == allocators.end()) {
LOG_S(ERROR) << "Unable to find registered handler for method \"" << method LOG_S(ERROR) << "Unable to find registered handler for method \"" << method
<< "\"" << std::endl; << "\"";
return nullptr; return nullptr;
} }
@ -233,7 +233,6 @@ void lsDocumentUri::SetPath(const std::string& path) {
#else #else
raw_uri = "file://" + raw_uri; raw_uri = "file://" + raw_uri;
#endif #endif
// std::cerr << "Set uri to " << raw_uri << " from " << path;
} }
std::string lsDocumentUri::GetPath() const { std::string lsDocumentUri::GetPath() const {

View File

@ -1,5 +1,7 @@
#include "options.h" #include "options.h"
#include <loguru.hpp>
#include <iostream> #include <iostream>
std::unordered_map<std::string, std::string> ParseOptions(int argc, std::unordered_map<std::string, std::string> ParseOptions(int argc,
@ -13,8 +15,7 @@ std::unordered_map<std::string, std::string> ParseOptions(int argc,
if (arg[0] != '-') { if (arg[0] != '-') {
if (previous_arg.size() == 0) { if (previous_arg.size() == 0) {
std::cerr << "Invalid arguments; switches must start with -" LOG_S(FATAL) << "Invalid arguments; switches must start with -";
<< std::endl;
exit(1); exit(1);
} }

View File

@ -1,5 +1,8 @@
#include "platform.h" #include "platform.h"
#include <doctest/doctest.h>
#include <loguru.hpp>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <sstream> #include <sstream>
@ -7,8 +10,6 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <doctest/doctest.h>
namespace { namespace {
// See http://stackoverflow.com/a/236803 // See http://stackoverflow.com/a/236803
@ -73,16 +74,15 @@ void MakeDirectoryRecursive(std::string path) {
} }
if (first_success == -1) { if (first_success == -1) {
std::cerr << "Failed to make any parent directory for " << path LOG_S(FATAL) << "Failed to make any parent directory for " << path;
<< std::endl;
exit(1); exit(1);
} }
// Make all child directories. // Make all child directories.
for (size_t i = first_success + 1; i <= components.size(); ++i) { for (size_t i = first_success + 1; i <= components.size(); ++i) {
if (TryMakeDirectory(prefix + Join(components, '/', i)) == false) { if (TryMakeDirectory(prefix + Join(components, '/', i)) == false) {
std::cerr << "Failed making directory for " << path LOG_S(FATAL) << "Failed making directory for " << path
<< " even after creating parent directories" << std::endl; << " even after creating parent directories";
exit(1); exit(1);
} }
} }

View File

@ -240,15 +240,8 @@ std::vector<std::string> ReadLines(std::string filename) {
std::vector<std::string> result; std::vector<std::string> result;
std::ifstream input(filename); std::ifstream input(filename);
for (std::string line; SafeGetline(input, line);) { 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
result.push_back(line); result.push_back(line);
}
return result; return result;
} }

View File

@ -4,6 +4,7 @@
#include "position.h" #include "position.h"
#include <doctest/doctest.h> #include <doctest/doctest.h>
#include <loguru.hpp>
#include <climits> #include <climits>
@ -86,8 +87,8 @@ optional<int> WorkingFile::GetBufferLineFromIndexLine(int index_line) const {
// TODO: reenable this assert once we are using the real indexed file. // TODO: reenable this assert once we are using the real indexed file.
// assert(index_line >= 1 && index_line <= index_lines.size()); // assert(index_line >= 1 && index_line <= index_lines.size());
if (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, " LOG_S(WARNING) << "Bad index_line (got " << index_line << ", expected [1, "
<< index_lines.size() << "])" << std::endl; << index_lines.size() << "])";
return nullopt; return nullopt;
} }
@ -123,8 +124,8 @@ optional<int> WorkingFile::GetIndexLineFromBufferLine(int buffer_line) const {
// Note: |index_line| and |buffer_line| are 1-based. // Note: |index_line| and |buffer_line| are 1-based.
// assert(buffer_line >= 1 && buffer_line < all_buffer_lines.size()); // assert(buffer_line >= 1 && buffer_line < all_buffer_lines.size());
if (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, " LOG_S(WARNING) << "Bad buffer_line (got " << buffer_line
<< all_buffer_lines.size() << "])" << std::endl; << ", expected [1, " << all_buffer_lines.size() << "])";
return nullopt; return nullopt;
} }
@ -165,9 +166,8 @@ optional<std::string> WorkingFile::GetBufferLineContentFromIndexLine(
return nullopt; return nullopt;
if (*buffer_line < 1 || *buffer_line >= all_buffer_lines.size()) { if (*buffer_line < 1 || *buffer_line >= all_buffer_lines.size()) {
std::cerr << "GetBufferLineContentFromIndexLine buffer line lookup not in " LOG_S(WARNING) << "GetBufferLineContentFromIndexLine buffer line lookup not"
"all_buffer_lines" << " in all_buffer_lines";
<< std::endl;
return nullopt; return nullopt;
} }
@ -315,18 +315,15 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) {
std::string filename = change.textDocument.uri.GetPath(); std::string filename = change.textDocument.uri.GetPath();
WorkingFile* file = GetFileByFilenameNoLock(filename); WorkingFile* file = GetFileByFilenameNoLock(filename);
if (!file) { if (!file) {
std::cerr << "Could not change " << filename << " because it was not open" LOG_S(WARNING) << "Could not change " << filename
<< std::endl; << " because it was not open";
return; return;
} }
file->version = change.textDocument.version; file->version = change.textDocument.version;
// std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
// std::cerr << "VERSION " << change.textDocument.version << std::endl;
for (const Ipc_TextDocumentDidChange::lsTextDocumentContentChangeEvent& diff : for (const Ipc_TextDocumentDidChange::lsTextDocumentContentChangeEvent& diff :
change.contentChanges) { change.contentChanges) {
// std::cerr << "|" << file->buffer_content << "|" << std::endl;
// Per the spec replace everything if the rangeLength and range are not set. // Per the spec replace everything if the rangeLength and range are not set.
// See https://github.com/Microsoft/language-server-protocol/issues/9. // See https://github.com/Microsoft/language-server-protocol/issues/9.
if (diff.rangeLength == -1 && if (diff.rangeLength == -1 &&
@ -334,7 +331,6 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) {
diff.range.end == lsPosition::kZeroPosition) { diff.range.end == lsPosition::kZeroPosition) {
file->buffer_content = diff.text; file->buffer_content = diff.text;
file->OnBufferContentUpdated(); file->OnBufferContentUpdated();
// std::cerr << "-> Replacing entire content";
} else { } else {
int start_offset = int start_offset =
GetOffsetForPosition(diff.range.start, file->buffer_content); GetOffsetForPosition(diff.range.start, file->buffer_content);
@ -344,21 +340,12 @@ void WorkingFiles::OnChange(const Ipc_TextDocumentDidChange::Params& change) {
if (length == -1) { if (length == -1) {
length = end_offset - start_offset; 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.replace(
file->buffer_content.begin() + start_offset, file->buffer_content.begin() + start_offset,
file->buffer_content.begin() + start_offset + length, diff.text); file->buffer_content.begin() + start_offset + length, diff.text);
file->OnBufferContentUpdated(); 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) { 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" LOG_S(WARNING) << "Could not close " << filename
<< std::endl; << " because it was not open";
} }
std::vector<CXUnsavedFile> WorkingFiles::AsUnsavedFiles() { std::vector<CXUnsavedFile> WorkingFiles::AsUnsavedFiles() {