Skip to content

Commit

Permalink
LanguageServer: provide a more detailed summary of VLOG() status print.
Browse files Browse the repository at this point in the history
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 ...
```
  • Loading branch information
hzeller committed Jan 28, 2024
1 parent 74ae2d7 commit 9f1067e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions verilog/tools/ls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 26 additions & 9 deletions verilog/tools/ls/symbol-table-handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include <string>
#include <vector>

#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"
Expand All @@ -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<absl::Status> &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<std::string, int> 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<int, absl::string_view> 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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions verilog/tools/ls/symbol-table-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <vector>

#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"
Expand Down

0 comments on commit 9f1067e

Please sign in to comment.