From 1ac37f7c183e218927fdbbed28cbbd28e047a028 Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 20 Nov 2024 17:48:07 +0100 Subject: [PATCH] [cbh] Do not show empty error highlighting messages when compiler highlighting is on #SCL-22848 fixed - We still show messages not associated with any source file at position 1:1 in all source files (when opened). This will be addressed separately. --- .../highlighting/CompilerMessages.scala | 3 ++- .../highlighting/CompilerMessagesTest.scala | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scala/compiler-integration/src/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessages.scala b/scala/compiler-integration/src/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessages.scala index b691f168771..1e5b2de205f 100644 --- a/scala/compiler-integration/src/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessages.scala +++ b/scala/compiler-integration/src/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessages.scala @@ -14,7 +14,8 @@ private object CompilerMessages { case bspMessageTemplate(_, position) => position case line => line } - trimmedMessage.stripSuffix(suffix).trim + val noSuffix = trimmedMessage.stripSuffix(suffix).trim + if (noSuffix.isBlank) trimmedMessage else noSuffix } def isUnusedImport(description: String): Boolean = diff --git a/scala/compiler-integration/test/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessagesTest.scala b/scala/compiler-integration/test/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessagesTest.scala index 172cac4158f..de496f6c115 100644 --- a/scala/compiler-integration/test/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessagesTest.scala +++ b/scala/compiler-integration/test/org/jetbrains/plugins/scala/compiler/highlighting/CompilerMessagesTest.scala @@ -20,4 +20,27 @@ class CompilerMessagesTest { val actual = CompilerMessages.description(originalMessage) assertEquals(expected, actual) } + + @Test + def deprecationWarningsMessage(): Unit = { + val originalMessage = "there were 4 deprecation warnings; re-run with -deprecation for details\n\n" + val expected = "there were 4 deprecation warnings; re-run with -deprecation for details" + val actual = CompilerMessages.description(originalMessage) + assertEquals(expected, actual) + } + + @Test + def oneLineMessage(): Unit = { + val originalMessage = "This is a one line error message" + val actual = CompilerMessages.description(originalMessage) + assertEquals(originalMessage, actual) + } + + @Test + def blankAfterProcessing(): Unit = { + val originalMessage = "\n\nSome message \n " + val expected = "Some message" + val actual = CompilerMessages.description(originalMessage) + assertEquals(expected, actual) + } }