From 26d15d7e9a245340e0546f5e1b666a4de9e907b4 Mon Sep 17 00:00:00 2001 From: Boulanger Date: Thu, 2 May 2024 14:57:29 +0200 Subject: [PATCH] Avoid creating a secondary message of higher importance When having multiple messages at the same location we are aggregating them into a primary and secondaries. In some cases, the primary message can be a warning and one of the secondary will be an error unrelated to the warning. In this case, create a new primary message for visibility purpose. Add a test. For eng/ide/gnatstudio#266 --- .../src/gps-kernel-messages-tools_output.adb | 6 ++++ .../obsolescent.gpr | 8 +++++ .../src/foo.adb | 6 ++++ .../src/pack.adb | 26 ++++++++++++++++ .../src/pack.ads | 8 +++++ .../test.py | 31 +++++++++++++++++++ .../test.yaml | 1 + 7 files changed, 86 insertions(+) create mode 100644 testsuite/tests/gs.266.message_secondary_with_higher_importance/obsolescent.gpr create mode 100644 testsuite/tests/gs.266.message_secondary_with_higher_importance/src/foo.adb create mode 100644 testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.adb create mode 100644 testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.ads create mode 100755 testsuite/tests/gs.266.message_secondary_with_higher_importance/test.py create mode 100644 testsuite/tests/gs.266.message_secondary_with_higher_importance/test.yaml diff --git a/kernel/src/gps-kernel-messages-tools_output.adb b/kernel/src/gps-kernel-messages-tools_output.adb index 01dae73c6f..96db5c2f78 100644 --- a/kernel/src/gps-kernel-messages-tools_output.adb +++ b/kernel/src/gps-kernel-messages-tools_output.adb @@ -218,6 +218,12 @@ package body GPS.Kernel.Messages.Tools_Output is GPS.Kernel.Messages.Legacy.Get_Message_At (Container, Category, File, Line, Column); + if Primary /= null and then Primary.Get_Importance < Importance then + -- The previous message in the same line is of lower Importance: + -- Create a new Primary message for higher visibility. + Primary := null; + end if; + if Primary = null then Primary := Message_Access diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/obsolescent.gpr b/testsuite/tests/gs.266.message_secondary_with_higher_importance/obsolescent.gpr new file mode 100644 index 0000000000..c8cbf5f0fe --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/obsolescent.gpr @@ -0,0 +1,8 @@ +project Obsolescent is + + for Source_Dirs use ("src"); + + package Builder is + for Default_Switches ("Ada") use ("-gnatwj", "-f"); + end Builder; +end Obsolescent; diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/foo.adb b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/foo.adb new file mode 100644 index 0000000000..ed3d735e5e --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/foo.adb @@ -0,0 +1,6 @@ +with Pack; + +procedure Foo is +begin + Pack.Obs (1, 2, 3); +end Foo; diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.adb b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.adb new file mode 100644 index 0000000000..b8e3370948 --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.adb @@ -0,0 +1,26 @@ +with Ada.Text_IO; + +package body Pack is + + --------- + -- Obs -- + --------- + + procedure Obs (I, J, K, L : Integer) is + pragma Unreferenced (L); + begin + Real (I, J, K); + end Obs; + + ---------- + -- Real -- + ---------- + + procedure Real (I, J, K : Integer) is + begin + if I = J and then K = I + J then + Ada.Text_IO.Put_Line ("Hello World"); + end if; + end Real; + +end Pack; diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.ads b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.ads new file mode 100644 index 0000000000..936008ef24 --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/src/pack.ads @@ -0,0 +1,8 @@ +package Pack is + + procedure Obs (I, J, K, L : Integer); + pragma Obsolescent (Obs, "Use Real"); + + procedure Real (I, J, K : Integer); + +end Pack; diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.py b/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.py new file mode 100755 index 0000000000..61ebce682a --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.py @@ -0,0 +1,31 @@ +""" +Verify that when multiple messages are located in the same location, +the highest message will be a primary. +""" +import GPS +from gs_utils.internal.utils import * + +EXPECTED = ['Builder results (2 items in 1 file)', + ['foo.adb (2 items)', + ['5:8 warning: call to obsolescent procedure' + + ' "Obs" declared at pack.ads:3 [enabled by default]', + [' warning: call to obsolescent procedure' + + ' "Obs" declared at ' + + 'pack.ads:3 [enabled by default]', + ' warning: Use Real [enabled by default]'], + '5:8 error: missing argument for parameter' + + ' "L" in call to "Obs"' + + ' declared at pack.ads:3', + [' error: missing argument for parameter "' + + 'L" in call to "Obs" declared at' + + ' pack.ads:3']]]] + + +@run_test_driver +def driver(): + GPS.BuildTarget("Build All").execute(force=True) + yield wait_tasks() + + gps_assert(dump_locations_tree(), + EXPECTED, + "Missing error for first renaming") diff --git a/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.yaml b/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.yaml new file mode 100644 index 0000000000..e92660f9e3 --- /dev/null +++ b/testsuite/tests/gs.266.message_secondary_with_higher_importance/test.yaml @@ -0,0 +1 @@ +title: 'gs.266.message_secondary_with_higher_importance'