From a7690f9606b8f7011aa0971d9f3351e1bb470513 Mon Sep 17 00:00:00 2001 From: mamshove Date: Thu, 27 Jun 2024 12:06:03 +0200 Subject: [PATCH] Include by value (result) modifier when hovering (#486) `BY VALUE` and `BY VALUE RESULT` are now present closes #485 --- .../amshove/natls/hover/HoverProvider.java | 9 ++ .../hovering/ExternalModuleHoverShould.java | 49 ++++++++++- .../natls/hovering/VariableHoverTests.java | 85 +++++++++++++++++++ 3 files changed, 139 insertions(+), 4 deletions(-) diff --git a/libs/natls/src/main/java/org/amshove/natls/hover/HoverProvider.java b/libs/natls/src/main/java/org/amshove/natls/hover/HoverProvider.java index facb50fe2..df3a09304 100644 --- a/libs/natls/src/main/java/org/amshove/natls/hover/HoverProvider.java +++ b/libs/natls/src/main/java/org/amshove/natls/hover/HoverProvider.java @@ -245,6 +245,15 @@ private VariableDeclarationFormat formatVariableDeclaration(INaturalModule modul } } + if (variable.findDescendantToken(SyntaxKind.VALUE) != null) + { + declaration += " BY VALUE"; + if (variable.findDescendantToken(SyntaxKind.RESULT) != null) + { + declaration += " RESULT"; + } + } + if (variable.findDescendantToken(SyntaxKind.OPTIONAL) != null) { declaration += " OPTIONAL"; diff --git a/libs/natls/src/test/java/org/amshove/natls/hovering/ExternalModuleHoverShould.java b/libs/natls/src/test/java/org/amshove/natls/hovering/ExternalModuleHoverShould.java index 2eef1ca36..fe45233f8 100644 --- a/libs/natls/src/test/java/org/amshove/natls/hovering/ExternalModuleHoverShould.java +++ b/libs/natls/src/test/java/org/amshove/natls/hovering/ExternalModuleHoverShould.java @@ -53,7 +53,7 @@ void hoverExternalSubroutines() DEFINE DATA LOCAL END-DEFINE - + PERFORM THE-E${}$XTERNAL-SUB 'AAA' END """, """ @@ -123,11 +123,11 @@ void hoverFunctions() DEFINE DATA LOCAL END-DEFINE - + IF F${}$UNC(<'A'>) IGNORE END-IF - + END """, """ **LIBONE.FUNC** @@ -146,7 +146,48 @@ void hoverFunctions() *Parameter:* ```natural - PARAMETER 1 P-PARAM (A10) + PARAMETER 1 P-PARAM (A10) BY VALUE + ```"""); + } + + @Test + void includeParameterWithAllModifiers() + { + createOrSaveFile("LIBONE", "FUNC.NS7", """ + DEFINE FUNCTION FUNC + RETURNS (L) + DEFINE DATA + PARAMETER + 1 P-PARAM (A) DYNAMIC BY VALUE RESULT OPTIONAL + END-DEFINE + FUNC := TRUE + END-FUNCTION + """); + + assertHover(""" + DEFINE DATA + LOCAL + END-DEFINE + + IF F${}$UNC(<'A'>) + IGNORE + END-IF + + END + """, """ + **LIBONE.FUNC** + + *Result:* + ```natural + RETURNS (L) + ``` + + + + + *Parameter:* + ```natural + PARAMETER 1 P-PARAM (A) DYNAMIC BY VALUE RESULT OPTIONAL ```"""); } diff --git a/libs/natls/src/test/java/org/amshove/natls/hovering/VariableHoverTests.java b/libs/natls/src/test/java/org/amshove/natls/hovering/VariableHoverTests.java index d61803b49..efd6c31d3 100644 --- a/libs/natls/src/test/java/org/amshove/natls/hovering/VariableHoverTests.java +++ b/libs/natls/src/test/java/org/amshove/natls/hovering/VariableHoverTests.java @@ -78,6 +78,91 @@ void dynamicAlphanumericArraysShouldBeFormatted() ); } + @Test + void byValueParameterShouldBeFormatted() + { + assertHover( + """ + DEFINE DATA + PARAMETER 1 #MY${}$PAR (A10) BY VALUE + END-DEFINE + END + """, + """ +```natural +PARAMETER 1 #MYPAR (A10) BY VALUE +```""" + ); + } + + @Test + void byValueResultParameterShouldBeFormatted() + { + assertHover( + """ + DEFINE DATA + PARAMETER 1 #MY${}$PAR (A10) BY VALUE RESULT + END-DEFINE + END + """, + """ +```natural +PARAMETER 1 #MYPAR (A10) BY VALUE RESULT +```""" + ); + } + + @Test + void dynamicByValueParameterShouldBeFormatted() + { + assertHover( + """ + DEFINE DATA + PARAMETER 1 #MY${}$PAR (A) DYNAMIC BY VALUE + END-DEFINE + END + """, + """ +```natural +PARAMETER 1 #MYPAR (A) DYNAMIC BY VALUE +```""" + ); + } + + @Test + void dynamicByValueResultParameterShouldBeFormatted() + { + assertHover( + """ + DEFINE DATA + PARAMETER 1 #MY${}$PAR (A) DYNAMIC BY VALUE RESULT + END-DEFINE + END + """, + """ +```natural +PARAMETER 1 #MYPAR (A) DYNAMIC BY VALUE RESULT +```""" + ); + } + + @Test + void dynamicByValueResultOptionalParameterShouldBeFormatted() + { + assertHover( + """ + DEFINE DATA + PARAMETER 1 #MY${}$PAR (A) DYNAMIC BY VALUE RESULT OPTIONAL + END-DEFINE + END + """, + """ +```natural +PARAMETER 1 #MYPAR (A) DYNAMIC BY VALUE RESULT OPTIONAL +```""" + ); + } + @Test void levelOneVariablesShouldBeHoveredCorrectlyEvenWhenHoveringTheReference() {