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..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 @@ -89,15 +89,20 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) { return ctx; } + if (!declaration.annotation().isEmpty()) { + startNode = declaration.annotation().get(0).AMPERSAND(); + } + 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); @@ -119,15 +124,20 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) { return ctx; } + if (!declaration.annotation().isEmpty()) { + startNode = declaration.annotation().get(0).AMPERSAND(); + } + 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); @@ -182,6 +192,7 @@ private static Optional getCompilerDirective( private MethodSymbol createMethodSymbol( TerminalNode startNode, TerminalNode stopNode, + Token startOfMethod, Token subName, BSLParser.ParamListContext paramList, boolean function, @@ -189,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); @@ -236,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) { @@ -310,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) { @@ -334,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) { 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..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; @@ -44,18 +43,30 @@ 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(16); 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(15); } } + @Test + void testMethodWithAnnotationBeforeDescription() { + var method = methodsWithDescription.get(14); + assertThat(method.getDescription()).isEqualTo("// Описание процедуры"); + } + + @Test + void testMethodWithAnnotation() { + var method = methodsWithDescription.get(13); + assertThat(method.getDescription()).isEqualTo("// Описание процедуры"); + } + @Test void testMethod13() { var method = methodsWithDescription.get(12); @@ -431,4 +442,4 @@ void testMethod1() { assertThat(method.getReturnedValue()).isEmpty(); assertThat(method.getLink()).isEmpty(); } -} \ No newline at end of file +} diff --git a/src/test/resources/context/symbol/MethodDescription.bsl b/src/test/resources/context/symbol/MethodDescription.bsl index 1abed2994d4..c66e7ccdd08 100644 --- a/src/test/resources/context/symbol/MethodDescription.bsl +++ b/src/test/resources/context/symbol/MethodDescription.bsl @@ -143,3 +143,13 @@ // Функция BUG_1495(Ссылки, Знач Реквизиты, ВыбратьРазрешенные = Ложь) Экспорт КонецФункции + +// Описание процедуры +&Аннотация("Параметр") +Процедура ПроцедураСАннотацией() +КонецПроцедуры + +&Аннотация("Параметр") +// Описание процедуры +Процедура ПроцедураСАннотациейПередОписанием() +КонецПроцедуры