Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Описание у асинх методов и с аннотациями #2872

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public List<MethodSymbol> compute() {
public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
BSLParser.FuncDeclarationContext declaration = ctx.funcDeclaration();

var firstToken =
declaration.children.stream()
.filter(chld -> !(chld instanceof BSLParser.PreprocessorContext))
.findFirst().get();

Check warning

Code scanning / QDJVMC

Optional.get() is called without isPresent() check

'Optional.get()' without 'isPresent()' check

TerminalNode startNode = declaration.FUNCTION_KEYWORD();
TerminalNode stopNode = ctx.ENDFUNCTION_KEYWORD();

Expand All @@ -90,6 +95,7 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
}

MethodSymbol methodSymbol = createMethodSymbol(
Trees.getTokens(firstToken).get(0),
startNode,
stopNode,
declaration.subName().getStart(),
Expand All @@ -108,6 +114,11 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
BSLParser.ProcDeclarationContext declaration = ctx.procDeclaration();

var firstToken =
declaration.children.stream()
.filter(chld -> !(chld instanceof BSLParser.PreprocessorContext))
.findFirst().get();

Check warning

Code scanning / QDJVMC

Optional.get() is called without isPresent() check

'Optional.get()' without 'isPresent()' check

TerminalNode startNode = declaration.PROCEDURE_KEYWORD();
TerminalNode stopNode = ctx.ENDPROCEDURE_KEYWORD();

Expand All @@ -120,6 +131,7 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
}

MethodSymbol methodSymbol = createMethodSymbol(
Trees.getTokens(firstToken).get(0),
startNode,
stopNode,
declaration.subName().getStart(),
Expand Down Expand Up @@ -180,6 +192,7 @@ private static Optional<CompilerDirectiveKind> getCompilerDirective(
}

private MethodSymbol createMethodSymbol(
Token startToken,
TerminalNode startNode,
TerminalNode stopNode,
Token subName,
Expand All @@ -189,7 +202,7 @@ private MethodSymbol createMethodSymbol(
Optional<CompilerDirectiveKind> compilerDirective,
List<Annotation> annotations
) {
Optional<MethodDescription> description = createDescription(startNode.getSymbol());
Optional<MethodDescription> description = createDescription(startToken);
boolean deprecated = description
.map(MethodDescription::isDeprecated)
.orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.languageserver.utils;

import com.github._1c_syntax.bsl.parser.BSLLexer;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
import lombok.experimental.UtilityClass;
Expand Down Expand Up @@ -49,16 +50,16 @@
public final class Trees {

private static final Set<Integer> VALID_TOKEN_TYPES_FOR_COMMENTS_SEARCH = Set.of(
BSLParser.ANNOTATION_ATCLIENT_SYMBOL,
BSLParser.ANNOTATION_ATSERVERNOCONTEXT_SYMBOL,
BSLParser.ANNOTATION_ATCLIENTATSERVERNOCONTEXT_SYMBOL,
BSLParser.ANNOTATION_ATCLIENTATSERVER_SYMBOL,
BSLParser.ANNOTATION_ATSERVER_SYMBOL,
BSLParser.ANNOTATION_CUSTOM_SYMBOL,
BSLParser.ANNOTATION_UNKNOWN,
BSLParser.LINE_COMMENT,
BSLParser.WHITE_SPACE,
BSLParser.AMPERSAND
BSLLexer.ANNOTATION_ATCLIENT_SYMBOL,
BSLLexer.ANNOTATION_ATSERVERNOCONTEXT_SYMBOL,
BSLLexer.ANNOTATION_ATCLIENTATSERVERNOCONTEXT_SYMBOL,
BSLLexer.ANNOTATION_ATCLIENTATSERVER_SYMBOL,
BSLLexer.ANNOTATION_ATSERVER_SYMBOL,
BSLLexer.ANNOTATION_CUSTOM_SYMBOL,
BSLLexer.ANNOTATION_UNKNOWN,
BSLLexer.LINE_COMMENT,
BSLLexer.WHITE_SPACE,
BSLLexer.AMPERSAND
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void testAnnotation() {
// AROUND
methodSymbol = methods.get(22);
assertThat(methodSymbol.getName()).isEqualTo("Р_Вместо");
assertThat(methodSymbol.getDescription()).isNotEmpty();
assertThat(methodSymbol.getAnnotations().get(0).getName()).isEqualTo("Вместо");
assertThat(methodSymbol.getAnnotations().get(0).getKind()).isEqualTo(AnnotationKind.AROUND);
assertThat(methodSymbol.getAnnotations().get(0).getParameters().get(0).getValue()).isEqualTo("Вместо");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,47 @@ 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.size()).isEqualTo(18);

methodsWithDescription = methods.stream()
.map(MethodSymbol::getDescription)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());

assertThat(methodsWithDescription.size()).isEqualTo(13);
assertThat(methodsWithDescription.size()).isEqualTo(15);
}
}

@Test
void testMethod15() {
var method = methodsWithDescription.get(14);
assertThat(method.getPurposeDescription())
.isNotEmpty()
.isEqualTo("См. ОбщийМодуль.ОписаниеСсылкойАсинх");
assertThat(method.isDeprecated()).isFalse();
assertThat(method.getDeprecationInfo()).isEmpty();
assertThat(method.getExamples()).isEmpty();
assertThat(method.getCallOptions()).isEmpty();
assertThat(method.getParameters()).isEmpty();
assertThat(method.getReturnedValue()).isEmpty();
assertThat(method.getLink()).isNotEmpty();
}
@Test
void testMethod14() {
var method = methodsWithDescription.get(13);
assertThat(method.getPurposeDescription())
.isNotEmpty()
.isEqualTo("См. ОбщийМодуль.Метод()");
assertThat(method.isDeprecated()).isFalse();
assertThat(method.getDeprecationInfo()).isEmpty();
assertThat(method.getExamples()).isEmpty();
assertThat(method.getCallOptions()).isEmpty();
assertThat(method.getParameters()).isEmpty();
assertThat(method.getReturnedValue()).isEmpty();
assertThat(method.getLink()).isNotEmpty();
}

@Test
void testMethod13() {
var method = methodsWithDescription.get(12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
Процедура Р_После()
КонецПроцедуры

// Описание метода
&Вместо("Вместо")
Функция Р_Вместо()
КонецФункции
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/context/symbol/MethodDescription.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,15 @@
//
Функция BUG_1495(Ссылки, Знач Реквизиты, ВыбратьРазрешенные = Ложь) Экспорт
КонецФункции

// См. ОбщийМодуль.Метод()
&Перед("ОписаниеСсылкойВРасширении")
Функция ОписаниеСсылкойВРасширении(Параметр1, Знач Параметр2 = 3)
КонецФункции
Функция НаписанаБезПробела()
КонецФункции Процедура НаписанаВоднуСтроку() КонецПроцедуры

// См. ОбщийМодуль.ОписаниеСсылкойАсинх
&НаКлиенте
Асинх Функция ОписаниеСсылкойАсинх()
КонецФункции
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,19 @@

КонецФункции

// см. КакойтоМодуль.Метод
Функция ОписаниеСм() Экспорт

Возврат Неопределено;

КонецФункции

// см. КакойтоМодуль.Метод
&Перед("ОписаниеСмПеред")
Функция ОписаниеСмПеред() Экспорт

Возврат Неопределено;

КонецФункции

#КонецОбласти