From 3239e84d16899ce19ac35c6f734b984af7a0d38f Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 18 May 2023 11:35:24 +0200 Subject: [PATCH 1/5] Using WarningsLibrary to query for warnings --- .../job/ProgramExecutionSupport.scala | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala index 0499ca397e22..c59b25fae4e8 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala @@ -20,7 +20,7 @@ import org.enso.interpreter.runtime.control.ThreadInterruptedException import org.enso.interpreter.runtime.error.{ DataflowError, PanicSentinel, - WithWarnings + WarningsLibrary } import org.enso.interpreter.service.error._ import org.enso.polyglot.LanguageInfo @@ -351,27 +351,32 @@ object ProgramExecutionSupport { VisualizationResult.findExceptionMessage(panic), ErrorResolver.getStackTrace(panic).flatMap(_.expressionId) ) - case withWarnings: WithWarnings => - val warningsCount = withWarnings.getWarningsCount - val warning = - if (warningsCount == 1) { - val warnings = withWarnings.getWarningsArray(null) - Option(ctx.executionService.toDisplayString(warnings(0).getValue)) - } else { - None - } - Api.ExpressionUpdate.Payload.Value( - Some( - Api.ExpressionUpdate.Payload.Value - .Warnings( - warningsCount, - warning, - withWarnings.isLimitReached() + case _ => + if (WarningsLibrary.getUncached().hasWarnings(value.getValue)) { + val warnings = + WarningsLibrary.getUncached().getWarnings(value.getValue, null) + val warningsCount = warnings.length + val warning = + if (warningsCount >= 1) { + Option( + ctx.executionService.toDisplayString(warnings(0).getValue) ) + } else { + None + } + Api.ExpressionUpdate.Payload.Value( + Some( + Api.ExpressionUpdate.Payload.Value + .Warnings( + warningsCount, + warning, + WarningsLibrary.getUncached().isLimitReached(value.getValue) + ) + ) ) - ) - case _ => - Api.ExpressionUpdate.Payload.Value() + } else { + Api.ExpressionUpdate.Payload.Value() + } } ctx.endpoint.sendToClient( Api.Response( From ba86adf784baf280b7cc901e24f76f6e457be8c2 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 18 May 2023 14:39:43 +0200 Subject: [PATCH 2/5] One warning is enough --- .../interpreter/instrument/job/ProgramExecutionSupport.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala index c59b25fae4e8..1e0319d1314b 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala @@ -357,7 +357,7 @@ object ProgramExecutionSupport { WarningsLibrary.getUncached().getWarnings(value.getValue, null) val warningsCount = warnings.length val warning = - if (warningsCount >= 1) { + if (warningsCount == 1) { Option( ctx.executionService.toDisplayString(warnings(0).getValue) ) From 36d114d2c43dae9c2f09afc712eb69d385d33fc9 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 19 May 2023 07:12:11 +0200 Subject: [PATCH 3/5] Scala doesn't need () to call Java accessor method --- .../instrument/job/ProgramExecutionSupport.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala index 1e0319d1314b..b3f47e6edf99 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala @@ -352,9 +352,9 @@ object ProgramExecutionSupport { ErrorResolver.getStackTrace(panic).flatMap(_.expressionId) ) case _ => - if (WarningsLibrary.getUncached().hasWarnings(value.getValue)) { + if (WarningsLibrary.getUncached.hasWarnings(value.getValue)) { val warnings = - WarningsLibrary.getUncached().getWarnings(value.getValue, null) + WarningsLibrary.getUncached.getWarnings(value.getValue, null) val warningsCount = warnings.length val warning = if (warningsCount == 1) { @@ -370,7 +370,7 @@ object ProgramExecutionSupport { .Warnings( warningsCount, warning, - WarningsLibrary.getUncached().isLimitReached(value.getValue) + WarningsLibrary.getUncached.isLimitReached(value.getValue) ) ) ) From 123f65e7938fd885e30a689e9d9b10b48425ee76 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 19 May 2023 07:30:06 +0200 Subject: [PATCH 4/5] Deliver warnings even for elements of a Vector --- .../test/instrument/RuntimeServerTest.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala index 55cd1500183b..c7f9947c8138 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala @@ -4552,10 +4552,19 @@ class RuntimeServerTest ) ) context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( - Api.Response(Api.BackgroundJobsStartedNotification()), Api.Response(requestId, Api.PushContextResponse(contextId)), - TestMessages.update(contextId, idMain, ConstantsGen.VECTOR), - context.executionComplete(contextId) + TestMessages.update( + contextId, + idMain, + ConstantsGen.VECTOR, + payload = Api.ExpressionUpdate.Payload.Value( + Some( + Api.ExpressionUpdate.Payload.Value.Warnings(1, Some("'y'"), false) + ) + ) + ), + context.executionComplete(contextId), + Api.Response(Api.BackgroundJobsStartedNotification()) ) } From 224ae5c4e1ea2a276cd4a1a1502cbdf2cd92f0e8 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 19 May 2023 14:19:12 +0200 Subject: [PATCH 5/5] Adjusting RuntimeVisualizationsTest --- .../instrument/RuntimeVisualizationsTest.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/runtime-with-polyglot/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala b/engine/runtime-with-polyglot/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala index a4b554577b98..891806ec775a 100644 --- a/engine/runtime-with-polyglot/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala +++ b/engine/runtime-with-polyglot/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala @@ -2967,10 +2967,19 @@ class RuntimeVisualizationsTest context.receiveNIgnorePendingExpressionUpdates( 4 ) should contain theSameElementsAs Seq( - Api.Response(Api.BackgroundJobsStartedNotification()), Api.Response(requestId, Api.PushContextResponse(contextId)), - TestMessages.update(contextId, idMain, ConstantsGen.VECTOR), - context.executionComplete(contextId) + TestMessages.update( + contextId, + idMain, + ConstantsGen.VECTOR, + payload = Api.ExpressionUpdate.Payload.Value( + Some( + Api.ExpressionUpdate.Payload.Value.Warnings(1, Some("'y'"), false) + ) + ) + ), + context.executionComplete(contextId), + Api.Response(Api.BackgroundJobsStartedNotification()) ) // attach visualisation