From 9f1067e2b0d1068d5ec5b19b5e93d4054fe6ae1e Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sun, 28 Jan 2024 11:00:13 -0800 Subject: [PATCH] LanguageServer: provide a more detailed summary of VLOG() status print. If there are a bunch of issues (and for big or badly filelist configured projects, there can be 10s of thousands), provide a summary of what messages were encountered. Looks something like ``` 1234 x NOT FOUND: Unable to reso... 233 x NOT FOUND: No member symb... 42 x ALREADY_EXISTS: foo/bar/b... 3 x INVALID_ARGUMENT: Syntax ... ``` --- verilog/tools/ls/BUILD | 3 ++ verilog/tools/ls/symbol-table-handler.cc | 35 ++++++++++++++++++------ verilog/tools/ls/symbol-table-handler.h | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/verilog/tools/ls/BUILD b/verilog/tools/ls/BUILD index 9498fd529..6b586b82e 100644 --- a/verilog/tools/ls/BUILD +++ b/verilog/tools/ls/BUILD @@ -125,12 +125,15 @@ cc_library( "//common/lsp:lsp-protocol", "//common/strings:line-column-map", "//common/util:file-util", + "//common/util:iterator-adaptors", "//common/util:range", "//verilog/analysis:symbol-table", "//verilog/analysis:verilog-filelist", "//verilog/analysis:verilog-project", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_absl//absl/types:optional", diff --git a/verilog/tools/ls/symbol-table-handler.cc b/verilog/tools/ls/symbol-table-handler.cc index ca6eb83a3..2706926b2 100644 --- a/verilog/tools/ls/symbol-table-handler.cc +++ b/verilog/tools/ls/symbol-table-handler.cc @@ -21,12 +21,14 @@ #include #include +#include "absl/container/flat_hash_map.h" #include "absl/flags/flag.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "common/lsp/lsp-file-utils.h" #include "common/strings/line_column_map.h" #include "common/util/file_util.h" +#include "common/util/iterator_adaptors.h" #include "common/util/range.h" #include "verilog/analysis/verilog_filelist.h" #include "verilog/tools/ls/lsp-conversion.h" @@ -42,16 +44,31 @@ namespace verilog { // If vlog(2), output all non-ok messages, with vlog(1) just the first few, // else: none static void LogFullIfVLog(const std::vector &statuses) { - if (VLOG_IS_ON(1)) { - int report_count = 0; - for (const auto &s : statuses) { - if (s.ok()) continue; + if (!VLOG_IS_ON(1)) return; + + constexpr int kMaxEmitNoisyMessagesDirectly = 5; + int report_count = 0; + absl::flat_hash_map status_counts; + for (const auto &s : statuses) { + if (s.ok()) continue; + if (++report_count <= kMaxEmitNoisyMessagesDirectly || VLOG_IS_ON(2)) { LOG(INFO) << s; - if (++report_count > 5 && !VLOG_IS_ON(2)) { - LOG(WARNING) << "skipped remaining messages; switch VLOG(2) on for " - << statuses.size() << " statuses"; - break; // only more noisy on request. - } + } else { + const std::string partial_msg(s.ToString().substr(0, 25)); + ++status_counts[partial_msg]; + } + } + + if (!status_counts.empty()) { + LOG(WARNING) << "skipped remaining; switch VLOG(2) on for all " + << statuses.size() << " statuses."; + LOG(INFO) << "Here a summary"; + std::map sort_by_count; + for (const auto &stat : status_counts) { + sort_by_count.emplace(stat.second, stat.first); + } + for (const auto &stat : verible::reversed_view(sort_by_count)) { + LOG(INFO) << absl::StrFormat("%6d x %s...", stat.first, stat.second); } } } diff --git a/verilog/tools/ls/symbol-table-handler.h b/verilog/tools/ls/symbol-table-handler.h index c7f205e43..89318e76e 100644 --- a/verilog/tools/ls/symbol-table-handler.h +++ b/verilog/tools/ls/symbol-table-handler.h @@ -23,6 +23,7 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "common/lsp/lsp-protocol.h"