From 9faef4b29b993ff33adf8af415db3414b8824a20 Mon Sep 17 00:00:00 2001 From: Nikita Fedkin Date: Sun, 3 Nov 2024 00:19:26 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B0=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D1=87=D0=B8=D0=B8=20=D0=B0=D0=BD=D0=BD=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../context/computer/MethodSymbolComputer.java | 8 ++++++++ .../symbol/description/MethodDescriptionTest.java | 12 +++++++++--- .../resources/context/symbol/MethodDescription.bsl | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java index 0fd1d55c87e..ea4b58c43f4 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java @@ -89,6 +89,10 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) { return ctx; } + if (!declaration.annotation().isEmpty()) { + startNode = declaration.annotation().get(0).AMPERSAND(); + } + MethodSymbol methodSymbol = createMethodSymbol( startNode, stopNode, @@ -119,6 +123,10 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) { return ctx; } + if (!declaration.annotation().isEmpty()) { + startNode = declaration.annotation().get(0).AMPERSAND(); + } + MethodSymbol methodSymbol = createMethodSymbol( startNode, stopNode, diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java index 339f8f752af..6865eca7aae 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java @@ -44,18 +44,24 @@ void prepare() { var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/MethodDescription.bsl"); var methods = documentContext.getSymbolTree().getMethods(); - assertThat(methods.size()).isEqualTo(14); + assertThat(methods).hasSize(15); methodsWithDescription = methods.stream() .map(MethodSymbol::getDescription) .filter(Optional::isPresent) .map(Optional::get) - .collect(Collectors.toList()); + .toList(); - assertThat(methodsWithDescription.size()).isEqualTo(13); + assertThat(methodsWithDescription.size()).isEqualTo(14); } } + @Test + void testMethodWithAnnotation() { + var method = methodsWithDescription.get(13); + assertThat(method.getDescription()).isEqualTo("// Описание процедуры"); + } + @Test void testMethod13() { var method = methodsWithDescription.get(12); diff --git a/src/test/resources/context/symbol/MethodDescription.bsl b/src/test/resources/context/symbol/MethodDescription.bsl index 1abed2994d4..0fa49e789be 100644 --- a/src/test/resources/context/symbol/MethodDescription.bsl +++ b/src/test/resources/context/symbol/MethodDescription.bsl @@ -143,3 +143,8 @@ // Функция BUG_1495(Ссылки, Знач Реквизиты, ВыбратьРазрешенные = Ложь) Экспорт КонецФункции + +// Описание процедуры +&Аннотация("Параметр") +Процедура ПроцедураСАннотацией() +КонецПроцедуры From 5f9406c7e9506bd09b562f26afa2de3e432728d0 Mon Sep 17 00:00:00 2001 From: Nikita Fedkin Date: Sun, 3 Nov 2024 10:05:50 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/context/symbol/MethodDescription.bsl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/resources/context/symbol/MethodDescription.bsl b/src/test/resources/context/symbol/MethodDescription.bsl index 0fa49e789be..c66e7ccdd08 100644 --- a/src/test/resources/context/symbol/MethodDescription.bsl +++ b/src/test/resources/context/symbol/MethodDescription.bsl @@ -148,3 +148,8 @@ &Аннотация("Параметр") Процедура ПроцедураСАннотацией() КонецПроцедуры + +&Аннотация("Параметр") +// Описание процедуры +Процедура ПроцедураСАннотациейПередОписанием() +КонецПроцедуры From 50a8179abdc08b4ef413a6ae2dd437255a851d5e Mon Sep 17 00:00:00 2001 From: Nikita Fedkin Date: Sun, 3 Nov 2024 10:07:01 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=D0=95=D1=89=D1=91=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../symbol/description/MethodDescriptionTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java index 6865eca7aae..5e2d3162c00 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java @@ -44,7 +44,7 @@ void prepare() { var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/MethodDescription.bsl"); var methods = documentContext.getSymbolTree().getMethods(); - assertThat(methods).hasSize(15); + assertThat(methods).hasSize(16); methodsWithDescription = methods.stream() .map(MethodSymbol::getDescription) @@ -52,10 +52,16 @@ void prepare() { .map(Optional::get) .toList(); - assertThat(methodsWithDescription.size()).isEqualTo(14); + assertThat(methodsWithDescription.size()).isEqualTo(15); } } + @Test + void testMethodWithAnnotationBeforeDescription() { + var method = methodsWithDescription.get(14); + assertThat(method.getDescription()).isEqualTo("// Описание процедуры"); + } + @Test void testMethodWithAnnotation() { var method = methodsWithDescription.get(13); @@ -437,4 +443,4 @@ void testMethod1() { assertThat(method.getReturnedValue()).isEmpty(); assertThat(method.getLink()).isEmpty(); } -} \ No newline at end of file +} From 2911dacc5a3d1d5532195e621a6d9504a7a73c06 Mon Sep 17 00:00:00 2001 From: Nikita Fedkin Date: Sun, 3 Nov 2024 23:11:51 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D0=B4=D1=83=20=D0=B0=D0=BD=D0=BD=D0=BE=D1=82=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../computer/MethodSymbolComputer.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java index ea4b58c43f4..2c30f600d5f 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java @@ -96,12 +96,13 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) { MethodSymbol methodSymbol = createMethodSymbol( startNode, stopNode, + declaration.FUNCTION_KEYWORD().getSymbol(), declaration.subName().getStart(), declaration.paramList(), true, declaration.EXPORT_KEYWORD() != null, getCompilerDirective(declaration.compilerDirective()), - getAnnotations(declaration.annotation())); + createAnnotations(declaration.annotation())); methods.add(methodSymbol); @@ -130,12 +131,13 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) { MethodSymbol methodSymbol = createMethodSymbol( startNode, stopNode, + declaration.PROCEDURE_KEYWORD().getSymbol(), declaration.subName().getStart(), declaration.paramList(), false, declaration.EXPORT_KEYWORD() != null, getCompilerDirective(declaration.compilerDirective()), - getAnnotations(declaration.annotation()) + createAnnotations(declaration.annotation()) ); methods.add(methodSymbol); @@ -190,6 +192,7 @@ private static Optional getCompilerDirective( private MethodSymbol createMethodSymbol( TerminalNode startNode, TerminalNode stopNode, + Token startOfMethod, Token subName, BSLParser.ParamListContext paramList, boolean function, @@ -197,7 +200,8 @@ private MethodSymbol createMethodSymbol( Optional compilerDirective, List annotations ) { - Optional description = createDescription(startNode.getSymbol()); + Optional description = createDescription(startOfMethod) + .or(() -> createDescription(startNode.getSymbol())); boolean deprecated = description .map(MethodDescription::isDeprecated) .orElse(false); @@ -244,7 +248,7 @@ private static List createParameters( .range(getParameterRange(param)) .description(getParameterDescription(parameterName, description)) .build(); - }).collect(Collectors.toList()); + }).toList(); } private static ParameterDefinition.DefaultValue getDefaultValue(BSLParser.ParamContext param) { @@ -318,10 +322,10 @@ private static Optional getParameterDescription( } - private static List getAnnotations(List annotationContext) { - return annotationContext.stream() + private static List createAnnotations(List annotationContexts) { + return annotationContexts.stream() .map(MethodSymbolComputer::createAnnotation) - .collect(Collectors.toList()); + .toList(); } private static Annotation createAnnotation(BSLParser.AnnotationContext annotation) { @@ -342,7 +346,7 @@ private static List getAnnotationParameter( return annotationParamsContext.annotationParam().stream() .map(MethodSymbolComputer::getAnnotationParam) - .collect(Collectors.toList()); + .toList(); } private static AnnotationParameterDefinition getAnnotationParam(BSLParser.AnnotationParamContext o) { From 63afb2428aeb09e4e3e84038d8f7f4d2da384cab Mon Sep 17 00:00:00 2001 From: Nikita Fedkin Date: Sun, 3 Nov 2024 23:19:18 +0100 Subject: [PATCH 5/5] Fix QF --- .../context/symbol/description/MethodDescriptionTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java index 5e2d3162c00..12c15e3d7e4 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat;