https://github.com/PortalPete created https://github.com/llvm/llvm-project/pull/76111
For example, the following message has the severity string "error: " twice. > "error: <EXPR>:3:1: error: cannot find 'bogus' in scope This method already appends the severity string in the beginning, but with this fix, it also removes a secondary instance, if applicable. Note that this change only removes the *first* redundant substring. I considered putting the removal logic in a loop, but I decided that if something is generating more than one redundant severity substring, then that's a problem the message's source should probably fix. rdar://114203423 >From dde9d02277fac978201fbd4cb0afc07bc6781185 Mon Sep 17 00:00:00 2001 From: Pete Lawrence <plawre...@apple.com> Date: Tue, 19 Dec 2023 19:25:36 -1000 Subject: [PATCH] [lldb] Remove redundant severity substring within a diagnostic message. For example, the following message has the severity string "error: " twice. > "error: <EXPR>:3:1: error: cannot find 'bogus' in scope This method already appends the severity string in the beginning, but with this fix, it also removes a secondary instance, if applicable. Note that this change only removes the *first* redundant substring. I considered putting the removal logic in a loop, but I decided that if something is generating more than one redundant severity substring, then that's a problem the message's source should probably fix. rdar://114203423 --- lldb/source/Expression/DiagnosticManager.cpp | 13 +++++++++++-- .../TestModulesCompileError.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lldb/source/Expression/DiagnosticManager.cpp b/lldb/source/Expression/DiagnosticManager.cpp index 08977066e3330a..d9452328e5a27f 100644 --- a/lldb/source/Expression/DiagnosticManager.cpp +++ b/lldb/source/Expression/DiagnosticManager.cpp @@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) { std::string ret; for (const auto &diagnostic : Diagnostics()) { - ret.append(StringForSeverity(diagnostic->GetSeverity())); - ret.append(std::string(diagnostic->GetMessage())); + std::string message(diagnostic->GetMessage()); + std::string searchable_message(diagnostic->GetMessage().lower()); + std::string severity(StringForSeverity(diagnostic->GetSeverity())); + + // Erase the (first) reduntant severity string in the message. + size_t position = searchable_message.find(severity); + if (position != std::string::npos) + message.erase(position, severity.length()); + + ret.append(severity); + ret.append(message); ret.push_back(separator); } diff --git a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py index 36e302be2525b5..620b6e44fc852a 100644 --- a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py +++ b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py @@ -21,7 +21,7 @@ def test(self): "expr @import LLDBTestModule", error=True, substrs=[ - "module.h:4:1: error: use of undeclared identifier 'syntax_error_for_lldb_to_find'", + "module.h:4:1: use of undeclared identifier 'syntax_error_for_lldb_to_find'", "syntax_error_for_lldb_to_find // comment that tests source printing", "could not build module 'LLDBTestModule'", ], _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits