From cf0d16fa0ce440f29825b4ab2bff94911d13cd5c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 27 May 2018 12:24:56 -0700 Subject: [PATCH] Replace loguru with a custom logger --- .gitmodules | 3 - CMakeLists.txt | 3 +- src/cache_manager.cc | 2 - src/clang_complete.cc | 20 +++--- src/clang_indexer.cc | 3 +- src/clang_translation_unit.cc | 3 +- src/file_consumer.cc | 7 +-- src/include_complete.cc | 6 +- src/log.cc | 62 +++++++++++++++++++ src/log.hh | 40 ++++++++++++ src/lsp.cc | 42 +------------ src/lsp.h | 8 --- src/main.cc | 34 ++++++---- src/message_handler.cc | 12 +--- src/messages/ccls_call_hierarchy.cc | 2 - src/messages/ccls_freshen_index.cc | 3 +- src/messages/exit.cc | 3 - src/messages/initialize.cc | 13 ++-- src/messages/text_document_completion.cc | 2 - src/messages/text_document_did_change.cc | 2 - src/messages/text_document_did_open.cc | 3 - src/messages/text_document_did_save.cc | 2 - .../workspace_did_change_configuration.cc | 3 - .../workspace_did_change_watched_files.cc | 2 - src/messages/workspace_symbol.cc | 7 --- src/{import_pipeline.cc => pipeline.cc} | 12 ++-- src/{import_pipeline.h => pipeline.hh} | 0 src/platform.h | 2 - src/platform_posix.cc | 10 --- src/project.cc | 2 +- src/query.cc | 1 - src/query_utils.cc | 4 +- src/serializer.cc | 5 +- src/test.cc | 1 - src/third_party_impl.cc | 3 - src/timer.cc | 2 +- src/type_printer.cc | 8 +-- src/utils.cc | 3 +- src/working_files.cc | 20 +----- third_party/loguru | 1 - 40 files changed, 174 insertions(+), 187 deletions(-) create mode 100644 src/log.cc create mode 100644 src/log.hh rename src/{import_pipeline.cc => pipeline.cc} (98%) rename src/{import_pipeline.h => pipeline.hh} (100%) delete mode 160000 third_party/loguru diff --git a/.gitmodules b/.gitmodules index f0c27341..fbe945c5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "third_party/doctest"] path = third_party/doctest url = https://github.com/onqtam/doctest -[submodule "third_party/loguru"] - path = third_party/loguru - url = https://github.com/emilk/loguru diff --git a/CMakeLists.txt b/CMakeLists.txt index 05aa3e0b..f3bdd59f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,14 +201,15 @@ target_sources(ccls PRIVATE src/filesystem.cc src/fuzzy_match.cc src/main.cc - src/import_pipeline.cc src/include_complete.cc src/method.cc src/language.cc src/lex_utils.cc + src/log.cc src/lsp.cc src/match.cc src/message_handler.cc + src/pipeline.cc src/platform_posix.cc src/platform_win.cc src/port.cc diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 79a159a4..c3e64788 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -5,8 +5,6 @@ #include "lsp.h" #include "platform.h" -#include - #include #include diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 6d344da0..e06c7647 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -1,14 +1,15 @@ #include "clang_complete.h" #include "clang_utils.h" +#include "filesystem.hh" +#include "log.hh" #include "platform.h" #include "timer.h" -#include "filesystem.hh" +#include +#include using namespace llvm; -#include - #include #include @@ -660,15 +661,15 @@ ClangCompleteManager::ClangCompleteManager(Project* project, preloaded_sessions_(kMaxPreloadedSessions), completion_sessions_(kMaxCompletionSessions) { std::thread([&]() { - SetThreadName("comp-query"); + set_thread_name("comp-query"); CompletionQueryMain(this); }).detach(); std::thread([&]() { - SetThreadName("comp-preload"); + set_thread_name("comp-preload"); CompletionPreloadMain(this); }).detach(); std::thread([&]() { - SetThreadName("diag-query"); + set_thread_name("diag-query"); DiagnosticQueryMain(this); }).detach(); } @@ -803,10 +804,11 @@ void ClangCompleteManager::FlushSession(const std::string& filename) { } void ClangCompleteManager::FlushAllSessions() { - std::lock_guard lock(sessions_lock_); + LOG_S(INFO) << "flush all clang complete sessions"; + std::lock_guard lock(sessions_lock_); - preloaded_sessions_.Clear(); - completion_sessions_.Clear(); + preloaded_sessions_.Clear(); + completion_sessions_.Clear(); } void CodeCompleteCache::WithLock(std::function action) { diff --git a/src/clang_indexer.cc b/src/clang_indexer.cc index 405d91b4..a9d66986 100644 --- a/src/clang_indexer.cc +++ b/src/clang_indexer.cc @@ -2,13 +2,12 @@ #include "clang_cursor.h" #include "clang_utils.h" +#include "log.hh" #include "platform.h" #include "serializer.h" #include "timer.h" #include "type_printer.h" -#include - #include #include #include diff --git a/src/clang_translation_unit.cc b/src/clang_translation_unit.cc index ffca1b0b..f9f9aaf4 100644 --- a/src/clang_translation_unit.cc +++ b/src/clang_translation_unit.cc @@ -1,11 +1,10 @@ #include "clang_translation_unit.h" #include "clang_utils.h" +#include "log.hh" #include "platform.h" #include "utils.h" -#include - namespace { void EmitDiagnostics(std::string path, diff --git a/src/file_consumer.cc b/src/file_consumer.cc index 5db6afca..218ec3bf 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -2,11 +2,10 @@ #include "clang_utils.h" #include "indexer.h" +#include "log.hh" #include "platform.h" #include "utils.h" -#include - namespace { std::optional GetFileContents( @@ -108,8 +107,8 @@ IndexFile* FileConsumer::TryConsumeFile( if (clang_getFileUniqueID(file, &file_id) != 0) { std::string file_name = FileName(file); if (!file_name.empty()) { - // LOG_S(ERROR) << "Could not get unique file id for " << file_name - // << " when parsing " << parse_file_; + LOG_S(ERROR) << "Could not get unique file id for " << file_name + << " when parsing " << parse_file_; } return nullptr; } diff --git a/src/include_complete.cc b/src/include_complete.cc index ea33fa33..1d1b74a1 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -6,6 +6,10 @@ #include "project.h" #include "timer.h" +#include +#include +using namespace llvm; + #include namespace { @@ -103,7 +107,7 @@ void IncludeComplete::Rescan() { is_scanning = true; std::thread([this]() { - SetThreadName("scan_includes"); + set_thread_name("scan_includes"); Timer timer; for (const std::string& dir : project_->quote_include_directories) diff --git a/src/log.cc b/src/log.cc new file mode 100644 index 00000000..573f9184 --- /dev/null +++ b/src/log.cc @@ -0,0 +1,62 @@ +#include "log.hh" + +#include +#include + +#include +#include +#include +#include +#include + +namespace ccls::log { +static std::mutex mtx; +FILE* file; +Verbosity verbosity; + +Message::Message(Verbosity verbosity, const char* file, int line) + : verbosity_(verbosity) { + using namespace llvm; + time_t tim = time(NULL); + struct tm t; + { + std::lock_guard lock(mtx); + t = *localtime(&tim); + } + char buf[16]; + snprintf(buf, sizeof buf, "%02d:%02d:%02d ", t.tm_hour, t.tm_min, t.tm_sec); + stream_ << buf; + { + SmallString<32> Name; + get_thread_name(Name); + stream_ << std::left << std::setw(13) << Name.c_str(); + } + { + const char* p = strrchr(file, '/'); + if (p) + file = p + 1; + stream_ << std::right << std::setw(15) << file << ':' << std::left + << std::setw(3) << line; + } + stream_ << ' '; + // clang-format off + switch (verbosity_) { + case Verbosity_FATAL: stream_ << 'F'; break; + case Verbosity_ERROR: stream_ << 'E'; break; + case Verbosity_WARNING: stream_ << 'W'; break; + case Verbosity_INFO: stream_ << 'I'; break; + default: stream_ << "V(" << int(verbosity_) << ')'; + } + // clang-format on + stream_ << ' '; +} + +Message::~Message() { + if (!file) return; + std::lock_guard lock(mtx); + stream_ << '\n'; + fputs(stream_.str().c_str(), file); + if (verbosity_ == Verbosity_FATAL) + abort(); +} +} diff --git a/src/log.hh b/src/log.hh new file mode 100644 index 00000000..caab8151 --- /dev/null +++ b/src/log.hh @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +namespace ccls::log { +extern FILE* file; + +struct Voidify { + void operator&(const std::ostream&) {} +}; + +enum Verbosity { + Verbosity_FATAL = -3, + Verbosity_ERROR = -2, + Verbosity_WARNING = -1, + Verbosity_INFO = 0, +}; +extern Verbosity verbosity; + +struct Message { + std::stringstream stream_; + int verbosity_; + + Message(Verbosity verbosity, const char* file, int line); + ~Message(); +}; +} + +#define LOG_IF(v, cond) \ + !(cond) ? void(0) \ + : ccls::log::Voidify() & \ + ccls::log::Message(v, __FILE__, __LINE__).stream_ +#define LOG_S(v) \ + LOG_IF(ccls::log::Verbosity_##v, \ + ccls::log::Verbosity_##v <= ccls::log::verbosity) +#define LOG_IF_S(v, cond) \ + LOG_IF(ccls::log::Verbosity_##v, \ + (cond) && ccls::log::Verbosity_##v <= ccls::log::verbosity) +#define CHECK_S(cond) LOG_IF(FATAL, !(cond)) << "check failed: " #cond " " diff --git a/src/lsp.cc b/src/lsp.cc index 9b11ac76..2968c399 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -1,10 +1,9 @@ #include "lsp.h" +#include "log.hh" #include "serializers/json.h" -#include #include -#include #include @@ -68,45 +67,6 @@ std::optional ReadJsonRpcContentFrom( return content; } -std::function()> MakeContentReader(std::string* content, - bool can_be_empty) { - return [content, can_be_empty]() -> std::optional { - if (!can_be_empty) - REQUIRE(!content->empty()); - if (content->empty()) - return std::nullopt; - char c = (*content)[0]; - content->erase(content->begin()); - return c; - }; -} - -TEST_SUITE("FindIncludeLine") { - TEST_CASE("ReadContentFromSource") { - auto parse_correct = [](std::string content) -> std::string { - auto reader = MakeContentReader(&content, false /*can_be_empty*/); - auto got = ReadJsonRpcContentFrom(reader); - REQUIRE(got); - return got.value(); - }; - - auto parse_incorrect = [](std::string content) -> std::optional { - auto reader = MakeContentReader(&content, true /*can_be_empty*/); - return ReadJsonRpcContentFrom(reader); - }; - - REQUIRE(parse_correct("Content-Length: 0\r\n\r\n") == ""); - REQUIRE(parse_correct("Content-Length: 1\r\n\r\na") == "a"); - REQUIRE(parse_correct("Content-Length: 4\r\n\r\nabcd") == "abcd"); - - REQUIRE(parse_incorrect("ggg") == std::optional()); - REQUIRE(parse_incorrect("Content-Length: 0\r\n") == - std::optional()); - REQUIRE(parse_incorrect("Content-Length: 5\r\n\r\nab") == - std::optional()); - } -} - std::optional ReadCharFromStdinBlocking() { // We do not use std::cin because it does not read bytes once stuck in // cin.bad(). We can call cin.clear() but C++ iostream has other annoyance diff --git a/src/lsp.h b/src/lsp.h index a72410b6..84fbf2e1 100644 --- a/src/lsp.h +++ b/src/lsp.h @@ -304,14 +304,6 @@ struct lsWorkspaceEdit { }; MAKE_REFLECT_STRUCT(lsWorkspaceEdit, documentChanges); -struct lsFormattingOptions { - // Size of a tab in spaces. - int tabSize; - // Prefer spaces over tabs. - bool insertSpaces; -}; -MAKE_REFLECT_STRUCT(lsFormattingOptions, tabSize, insertSpaces); - // MarkedString can be used to render human readable text. It is either a // markdown string or a code-block that provides a language and a code snippet. // The language identifier is sematically equal to the std::optional language diff --git a/src/main.cc b/src/main.cc index 503b1e12..fcfc66e9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,5 @@ -#include "import_pipeline.h" +#include "log.hh" +#include "pipeline.hh" #include "platform.h" #include "serializer.h" #include "serializers/json.h" @@ -7,12 +8,12 @@ #include #include +#include using namespace llvm; using namespace llvm::cl; #include #include -#include #include #include @@ -34,10 +35,15 @@ opt opt_log_file_append("log-file-append", desc("log"), value_desc( list opt_extra(Positional, ZeroOrMore, desc("extra")); +void CloseLog() { + fclose(ccls::log::file); +} + } // namespace int main(int argc, char** argv) { TraceMe(); + sys::PrintStackTraceOnErrorSignal(argv[0]); ParseCommandLineOptions(argc, argv, "C/C++/Objective-C language server\n\n" @@ -50,13 +56,6 @@ int main(int argc, char** argv) { return 0; } - loguru::g_stderr_verbosity = opt_verbose - 1; - loguru::g_preamble_date = false; - loguru::g_preamble_time = false; - loguru::g_preamble_verbose = false; - loguru::g_flush_interval_ms = 0; - loguru::init(argc, argv); - MultiQueueWaiter querydb_waiter, indexer_waiter, stdout_waiter; QueueManager::Init(&querydb_waiter, &indexer_waiter, &stdout_waiter); @@ -72,10 +71,19 @@ int main(int argc, char** argv) { bool language_server = true; - if (opt_log_file.size()) - loguru::add_file(opt_log_file.c_str(), loguru::Truncate, opt_verbose); - if (opt_log_file_append.size()) - loguru::add_file(opt_log_file_append.c_str(), loguru::Append, opt_verbose); + if (opt_log_file.size() || opt_log_file_append.size()) { + ccls::log::file = opt_log_file.size() + ? fopen(opt_log_file.c_str(), "wb") + : fopen(opt_log_file_append.c_str(), "ab"); + if (!ccls::log::file) { + fprintf( + stderr, "failed to open %s\n", + (opt_log_file.size() ? opt_log_file : opt_log_file_append).c_str()); + return 2; + } + setbuf(ccls::log::file, NULL); + atexit(CloseLog); + } if (opt_test_unit) { language_server = false; diff --git a/src/message_handler.cc b/src/message_handler.cc index cf17c013..a0014c21 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -1,12 +1,11 @@ #include "message_handler.h" #include "lex_utils.h" +#include "log.hh" #include "project.h" #include "query_utils.h" #include "queue_manager.h" -#include - #include MAKE_HASHABLE(SymbolIdx, t.usr, t.kind); @@ -156,14 +155,7 @@ bool FindFileOrFail(QueryDatabase* db, if (indexing) LOG_S(INFO) << "\"" << absolute_path << "\" is being indexed."; else - LOG_S(INFO) << "Unable to find file \"" << absolute_path << "\""; - /* - LOG_S(INFO) << "Files (size=" << db->usr_to_file.size() << "): " - << StringJoinMap(db->usr_to_file, - [](const std::pair& entry) { - return entry.first.path; - }); - */ + LOG_S(INFO) << "unable to find file \"" << absolute_path << "\""; if (id) { Out_Error out; diff --git a/src/messages/ccls_call_hierarchy.cc b/src/messages/ccls_call_hierarchy.cc index c15e1122..08c94515 100644 --- a/src/messages/ccls_call_hierarchy.cc +++ b/src/messages/ccls_call_hierarchy.cc @@ -2,8 +2,6 @@ #include "query_utils.h" #include "queue_manager.h" -#include - #include namespace { diff --git a/src/messages/ccls_freshen_index.cc b/src/messages/ccls_freshen_index.cc index f9e047fa..bf36450f 100644 --- a/src/messages/ccls_freshen_index.cc +++ b/src/messages/ccls_freshen_index.cc @@ -1,14 +1,13 @@ #include "cache_manager.h" -#include "import_pipeline.h" #include "match.h" #include "message_handler.h" +#include "pipeline.hh" #include "platform.h" #include "project.h" #include "queue_manager.h" #include "timer.h" #include "working_files.h" -#include #include #include diff --git a/src/messages/exit.cc b/src/messages/exit.cc index 2722dca5..edf0c4ff 100644 --- a/src/messages/exit.cc +++ b/src/messages/exit.cc @@ -1,7 +1,5 @@ #include "message_handler.h" -#include - namespace { struct In_Exit : public NotificationInMessage { MethodType GetMethodType() const override { return kMethodType_Exit; } @@ -13,7 +11,6 @@ struct Handler_Exit : MessageHandler { MethodType GetMethodType() const override { return kMethodType_Exit; } void Run(std::unique_ptr request) override { - LOG_S(INFO) << "Exiting; got exit message"; exit(0); } }; diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index fc4bc4d9..d15ba2e2 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -1,8 +1,10 @@ #include "cache_manager.h" #include "diagnostics_engine.h" -#include "import_pipeline.h" +#include "filesystem.hh" #include "include_complete.h" +#include "log.hh" #include "message_handler.h" +#include "pipeline.hh" #include "platform.h" #include "project.h" #include "queue_manager.h" @@ -10,11 +12,10 @@ #include "timer.h" #include "working_files.h" -#include "filesystem.hh" +#include +#include using namespace llvm; -#include - #include #include #include @@ -508,12 +509,12 @@ struct Handler_Initialize : BaseMessageHandler { if (g_config->index.threads == 0) g_config->index.threads = std::thread::hardware_concurrency(); - LOG_S(INFO) << "Starting " << g_config->index.threads << " indexers"; + LOG_S(INFO) << "start " << g_config->index.threads << " indexers"; for (int i = 0; i < g_config->index.threads; i++) { std::thread([=]() { g_thread_id = i + 1; std::string name = "indexer" + std::to_string(i); - SetThreadName(name.c_str()); + set_thread_name(name.c_str()); Indexer_Main(diag_engine, vfs, project, working_files, waiter); }).detach(); } diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index a0820549..1f536a40 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -8,8 +8,6 @@ #include "lex_utils.h" -#include - #include namespace { diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index b09b1829..8072cb95 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -5,8 +5,6 @@ #include "working_files.h" #include "queue_manager.h" -#include - namespace { MethodType kMethodType = "textDocument/didChange"; diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index a91afb1c..12c79bdb 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -7,8 +7,6 @@ #include "timer.h" #include "working_files.h" -#include - namespace { MethodType kMethodType = "textDocument/didOpen"; @@ -69,7 +67,6 @@ struct Handler_TextDocumentDidOpen true /* priority */); clang_complete->FlushSession(entry.filename); - LOG_S(INFO) << "Flushed clang complete sessions for " << entry.filename; } } }; diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index 3e5a9011..50835f01 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -4,8 +4,6 @@ #include "project.h" #include "queue_manager.h" -#include - namespace { MethodType kMethodType = "textDocument/didSave"; diff --git a/src/messages/workspace_did_change_configuration.cc b/src/messages/workspace_did_change_configuration.cc index afe578ca..ab33009b 100644 --- a/src/messages/workspace_did_change_configuration.cc +++ b/src/messages/workspace_did_change_configuration.cc @@ -6,8 +6,6 @@ #include "timer.h" #include "working_files.h" -#include - namespace { MethodType kMethodType = "workspace/didChangeConfiguration"; @@ -38,7 +36,6 @@ struct Handler_WorkspaceDidChangeConfiguration "[perf] Dispatched workspace/didChangeConfiguration index requests"); clang_complete->FlushAllSessions(); - LOG_S(INFO) << "Flushed all clang complete sessions"; } }; REGISTER_MESSAGE_HANDLER(Handler_WorkspaceDidChangeConfiguration); diff --git a/src/messages/workspace_did_change_watched_files.cc b/src/messages/workspace_did_change_watched_files.cc index e15e9e21..3140a929 100644 --- a/src/messages/workspace_did_change_watched_files.cc +++ b/src/messages/workspace_did_change_watched_files.cc @@ -5,8 +5,6 @@ #include "queue_manager.h" #include "working_files.h" -#include - namespace { MethodType kMethodType = "workspace/didChangeWatchedFiles"; diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 910cfdab..77df7fea 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -4,8 +4,6 @@ #include "query_utils.h" #include "queue_manager.h" -#include - #include #include #include @@ -70,9 +68,6 @@ struct Handler_WorkspaceSymbol : BaseMessageHandler { Out_WorkspaceSymbol out; out.id = request->id; - LOG_S(INFO) << "[querydb] Considering " << db->symbols.size() - << " candidates for query " << request->params.query; - std::string query = request->params.query; // {symbol info, matching detailed_name or short_name, index} @@ -129,8 +124,6 @@ struct Handler_WorkspaceSymbol : BaseMessageHandler { out.result.push_back(std::get<0>(entry)); } - LOG_S(INFO) << "[querydb] Found " << out.result.size() - << " results for query " << query; QueueManager::WriteStdout(kMethodType, out); } }; diff --git a/src/import_pipeline.cc b/src/pipeline.cc similarity index 98% rename from src/import_pipeline.cc rename to src/pipeline.cc index 5ed8ebd8..b552448f 100644 --- a/src/import_pipeline.cc +++ b/src/pipeline.cc @@ -1,10 +1,11 @@ -#include "import_pipeline.h" +#include "pipeline.hh" #include "cache_manager.h" #include "clang_complete.h" #include "config.h" #include "diagnostics_engine.h" #include "include_complete.h" +#include "log.hh" #include "lsp.h" #include "message_handler.h" #include "platform.h" @@ -13,8 +14,9 @@ #include "queue_manager.h" #include "timer.h" -#include -#include +#include +#include +using namespace llvm; #include #include @@ -275,7 +277,7 @@ void QueryDb_OnIndexed(QueueManager* queue, void LaunchStdinLoop(std::unordered_map* request_times) { std::thread([request_times]() { - SetThreadName("stdin"); + set_thread_name("stdin"); auto* queue = QueueManager::instance(); while (true) { std::unique_ptr message; @@ -316,7 +318,7 @@ void LaunchStdinLoop(std::unordered_map* request_times) { void LaunchStdoutThread(std::unordered_map* request_times, MultiQueueWaiter* waiter) { std::thread([=]() { - SetThreadName("stdout"); + set_thread_name("stdout"); auto* queue = QueueManager::instance(); while (true) { diff --git a/src/import_pipeline.h b/src/pipeline.hh similarity index 100% rename from src/import_pipeline.h rename to src/pipeline.hh diff --git a/src/platform.h b/src/platform.h index 775486a0..7d73549a 100644 --- a/src/platform.h +++ b/src/platform.h @@ -8,8 +8,6 @@ std::string NormalizePath(const std::string& path); -void SetThreadName(const char* name); - // Free any unused memory and return it to the system. void FreeUnusedMemory(); diff --git a/src/platform_posix.cc b/src/platform_posix.cc index d1d6c9e0..10bad8d4 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -1,13 +1,8 @@ -#include -#include - #if defined(__unix__) || defined(__APPLE__) #include "platform.h" #include "utils.h" -#include - #include #include #include @@ -160,8 +155,3 @@ std::string GetExternalCommandOutput(const std::vector& command, } #endif - -void SetThreadName(const char* name) { - loguru::set_thread_name(name); - llvm::set_thread_name(name); -} diff --git a/src/project.cc b/src/project.cc index 3ca211d4..44682d98 100644 --- a/src/project.cc +++ b/src/project.cc @@ -4,6 +4,7 @@ #include "clang_utils.h" #include "filesystem.hh" #include "language.h" +#include "log.hh" #include "match.h" #include "platform.h" #include "queue_manager.h" @@ -25,7 +26,6 @@ using namespace llvm::opt; #include #include #include -#include #if defined(__unix__) || defined(__APPLE__) #include diff --git a/src/query.cc b/src/query.cc index 59edfe03..256d5fa3 100644 --- a/src/query.cc +++ b/src/query.cc @@ -5,7 +5,6 @@ #include "serializers/json.h" #include -#include #include #include diff --git a/src/query_utils.cc b/src/query_utils.cc index c0bdac2e..9f801ced 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -2,9 +2,7 @@ #include "queue_manager.h" -#include - -#include +#include #include namespace { diff --git a/src/serializer.cc b/src/serializer.cc index 734c147a..72090c6e 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -1,13 +1,12 @@ #include "serializer.h" #include "filesystem.hh" +#include "log.hh" #include "serializers/binary.h" #include "serializers/json.h" #include "indexer.h" -#include - #include using namespace llvm; @@ -414,7 +413,7 @@ std::unique_ptr Deserialize( file = std::make_unique(path, file_content); Reflect(reader, *file); } catch (std::invalid_argument& e) { - LOG_S(INFO) << "Failed to deserialize '" << path + LOG_S(INFO) << "failed to deserialize '" << path << "': " << e.what(); return nullptr; } diff --git a/src/test.cc b/src/test.cc index 6cd4b2f7..00dec826 100644 --- a/src/test.cc +++ b/src/test.cc @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/src/third_party_impl.cc b/src/third_party_impl.cc index 231ab76c..572a07d3 100644 --- a/src/third_party_impl.cc +++ b/src/third_party_impl.cc @@ -1,5 +1,2 @@ #define DOCTEST_CONFIG_IMPLEMENT #include - -#define LOGURU_IMPLEMENTATION 1 -#include diff --git a/src/timer.cc b/src/timer.cc index 96ec658c..022ca22e 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -1,6 +1,6 @@ #include "timer.h" -#include +#include "log.hh" Timer::Timer() { Reset(); diff --git a/src/type_printer.cc b/src/type_printer.cc index 06346d47..eac5ad41 100644 --- a/src/type_printer.cc +++ b/src/type_printer.cc @@ -1,7 +1,5 @@ #include "type_printer.h" -#include - namespace { int GetNameInsertingPosition(const std::string& type_desc, @@ -82,12 +80,8 @@ std::tuple GetFunctionSignature( std::string type_desc_with_names(type_desc.begin(), type_desc.begin() + i); type_desc_with_names.append(func_name); for (auto& arg : args) { - if (arg.first < 0) { - LOG_S(ERROR) - << "When adding argument names to '" << type_desc - << "', failed to detect positions to insert argument names"; + if (arg.first < 0) break; - } if (arg.second.empty()) continue; // TODO Use inside-out syntax. Note, clang/lib/AST/TypePrinter.cpp does diff --git a/src/utils.cc b/src/utils.cc index 57a5319f..cc448476 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -2,11 +2,10 @@ #include "filesystem.hh" using namespace llvm; +#include "log.hh" #include "platform.h" -#include #include -#include #include #include diff --git a/src/working_files.cc b/src/working_files.cc index 5e293464..cfefda8a 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -1,10 +1,10 @@ #include "working_files.h" #include "lex_utils.h" +#include "log.hh" #include "position.h" #include -#include #include #include @@ -320,23 +320,9 @@ void WorkingFile::ComputeLineMapping() { std::optional WorkingFile::GetBufferPosFromIndexPos(int line, int* column, bool is_end) { - // The implementation is simple but works pretty well for most cases. We - // lookup the line contents in the indexed file contents, and try to find the - // most similar line in the current buffer file. - // - // Previously, this was implemented by tracking edits and by running myers - // diff algorithm. They were complex implementations that did not work as - // well. - - // Note: |index_line| and |buffer_line| are 1-based. - - // TODO: reenable this assert once we are using the real indexed file. - // assert(index_line >= 1 && index_line <= index_lines.size()); if (line < 0 || line >= (int)index_lines.size()) { - loguru::Text stack = loguru::stacktrace(); - LOG_S(WARNING) << "Bad index_line (got " << line << ", expected [0, " - << index_lines.size() << ")) in " << filename - << stack.c_str(); + LOG_S(WARNING) << "bad index_line (got " << line << ", expected [0, " + << index_lines.size() << ")) in " << filename; return std::nullopt; } diff --git a/third_party/loguru b/third_party/loguru deleted file mode 160000 index 6bf94c5f..00000000 --- a/third_party/loguru +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6bf94c5f2bec437e871402d0a27e8a3094b261d5