Skip to content

Commit 29128ba

Browse files
authored
Merge pull request #3359 from 1c-syntax/fix/method-description-annotations
Исправление поиска начала метода при наличии аннотаций
2 parents 810c04a + 63afb24 commit 29128ba

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/MethodSymbolComputer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,20 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
8989
return ctx;
9090
}
9191

92+
if (!declaration.annotation().isEmpty()) {
93+
startNode = declaration.annotation().get(0).AMPERSAND();
94+
}
95+
9296
MethodSymbol methodSymbol = createMethodSymbol(
9397
startNode,
9498
stopNode,
99+
declaration.FUNCTION_KEYWORD().getSymbol(),
95100
declaration.subName().getStart(),
96101
declaration.paramList(),
97102
true,
98103
declaration.EXPORT_KEYWORD() != null,
99104
getCompilerDirective(declaration.compilerDirective()),
100-
getAnnotations(declaration.annotation()));
105+
createAnnotations(declaration.annotation()));
101106

102107
methods.add(methodSymbol);
103108

@@ -119,15 +124,20 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
119124
return ctx;
120125
}
121126

127+
if (!declaration.annotation().isEmpty()) {
128+
startNode = declaration.annotation().get(0).AMPERSAND();
129+
}
130+
122131
MethodSymbol methodSymbol = createMethodSymbol(
123132
startNode,
124133
stopNode,
134+
declaration.PROCEDURE_KEYWORD().getSymbol(),
125135
declaration.subName().getStart(),
126136
declaration.paramList(),
127137
false,
128138
declaration.EXPORT_KEYWORD() != null,
129139
getCompilerDirective(declaration.compilerDirective()),
130-
getAnnotations(declaration.annotation())
140+
createAnnotations(declaration.annotation())
131141
);
132142

133143
methods.add(methodSymbol);
@@ -182,14 +192,16 @@ private static Optional<CompilerDirectiveKind> getCompilerDirective(
182192
private MethodSymbol createMethodSymbol(
183193
TerminalNode startNode,
184194
TerminalNode stopNode,
195+
Token startOfMethod,
185196
Token subName,
186197
BSLParser.ParamListContext paramList,
187198
boolean function,
188199
boolean export,
189200
Optional<CompilerDirectiveKind> compilerDirective,
190201
List<Annotation> annotations
191202
) {
192-
Optional<MethodDescription> description = createDescription(startNode.getSymbol());
203+
Optional<MethodDescription> description = createDescription(startOfMethod)
204+
.or(() -> createDescription(startNode.getSymbol()));
193205
boolean deprecated = description
194206
.map(MethodDescription::isDeprecated)
195207
.orElse(false);
@@ -236,7 +248,7 @@ private static List<ParameterDefinition> createParameters(
236248
.range(getParameterRange(param))
237249
.description(getParameterDescription(parameterName, description))
238250
.build();
239-
}).collect(Collectors.toList());
251+
}).toList();
240252
}
241253

242254
private static ParameterDefinition.DefaultValue getDefaultValue(BSLParser.ParamContext param) {
@@ -310,10 +322,10 @@ private static Optional<ParameterDescription> getParameterDescription(
310322

311323
}
312324

313-
private static List<Annotation> getAnnotations(List<? extends BSLParser.AnnotationContext> annotationContext) {
314-
return annotationContext.stream()
325+
private static List<Annotation> createAnnotations(List<? extends BSLParser.AnnotationContext> annotationContexts) {
326+
return annotationContexts.stream()
315327
.map(MethodSymbolComputer::createAnnotation)
316-
.collect(Collectors.toList());
328+
.toList();
317329
}
318330

319331
private static Annotation createAnnotation(BSLParser.AnnotationContext annotation) {
@@ -334,7 +346,7 @@ private static List<AnnotationParameterDefinition> getAnnotationParameter(
334346

335347
return annotationParamsContext.annotationParam().stream()
336348
.map(MethodSymbolComputer::getAnnotationParam)
337-
.collect(Collectors.toList());
349+
.toList();
338350
}
339351

340352
private static AnnotationParameterDefinition getAnnotationParam(BSLParser.AnnotationParamContext o) {

src/test/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/description/MethodDescriptionTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.util.List;
3131
import java.util.Optional;
32-
import java.util.stream.Collectors;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
3534

@@ -44,18 +43,30 @@ void prepare() {
4443
var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/MethodDescription.bsl");
4544
var methods = documentContext.getSymbolTree().getMethods();
4645

47-
assertThat(methods.size()).isEqualTo(14);
46+
assertThat(methods).hasSize(16);
4847

4948
methodsWithDescription = methods.stream()
5049
.map(MethodSymbol::getDescription)
5150
.filter(Optional::isPresent)
5251
.map(Optional::get)
53-
.collect(Collectors.toList());
52+
.toList();
5453

55-
assertThat(methodsWithDescription.size()).isEqualTo(13);
54+
assertThat(methodsWithDescription.size()).isEqualTo(15);
5655
}
5756
}
5857

58+
@Test
59+
void testMethodWithAnnotationBeforeDescription() {
60+
var method = methodsWithDescription.get(14);
61+
assertThat(method.getDescription()).isEqualTo("// Описание процедуры");
62+
}
63+
64+
@Test
65+
void testMethodWithAnnotation() {
66+
var method = methodsWithDescription.get(13);
67+
assertThat(method.getDescription()).isEqualTo("// Описание процедуры");
68+
}
69+
5970
@Test
6071
void testMethod13() {
6172
var method = methodsWithDescription.get(12);
@@ -431,4 +442,4 @@ void testMethod1() {
431442
assertThat(method.getReturnedValue()).isEmpty();
432443
assertThat(method.getLink()).isEmpty();
433444
}
434-
}
445+
}

src/test/resources/context/symbol/MethodDescription.bsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@
143143
//
144144
Функция BUG_1495(Ссылки, Знач Реквизиты, ВыбратьРазрешенные = Ложь) Экспорт
145145
КонецФункции
146+
147+
// Описание процедуры
148+
&Аннотация("Параметр")
149+
Процедура ПроцедураСАннотацией()
150+
КонецПроцедуры
151+
152+
&Аннотация("Параметр")
153+
// Описание процедуры
154+
Процедура ПроцедураСАннотациейПередОписанием()
155+
КонецПроцедуры

0 commit comments

Comments
 (0)