Search in sources :

Example 66 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class DiagnosticIgnoranceComputerTest method testDiagnosticIgnorance.

@Test
void testDiagnosticIgnorance() {
    // given
    String filePath = "./src/test/resources/context/computer/DiagnosticIgnoranceComputerTest.bsl";
    final DocumentContext documentContext = getDocumentContextFromFile(filePath);
    List<Diagnostic> ignoredDiagnostics = new ArrayList<>();
    ignoredDiagnostics.add(createDiagnostic("SpaceAtStartComment", 4));
    ignoredDiagnostics.add(createDiagnostic("SemicolonPresence", 5));
    ignoredDiagnostics.add(createDiagnostic("RandomDiagnostic", 6));
    ignoredDiagnostics.add(createDiagnostic("SemicolonPresence", 13));
    ignoredDiagnostics.add(createDiagnostic("SpaceAtStartComment", 20));
    ignoredDiagnostics.add(createDiagnostic("SemicolonPresence", 21));
    ignoredDiagnostics.add(createDiagnostic("SemicolonPresence", 27));
    List<Diagnostic> notIgnoredDiagnostics = new ArrayList<>();
    notIgnoredDiagnostics.add(createDiagnostic("SpaceAtStartComment", 12));
    notIgnoredDiagnostics.add(createDiagnostic("RandomDiagnostic", 20));
    notIgnoredDiagnostics.add(createDiagnostic("SemicolonPresence", 29));
    // when
    Computer<DiagnosticIgnoranceComputer.Data> diagnosticIgnoranceComputer = new DiagnosticIgnoranceComputer(documentContext);
    DiagnosticIgnoranceComputer.Data data = diagnosticIgnoranceComputer.compute();
    // then
    assertThat(ignoredDiagnostics).allMatch(data::diagnosticShouldBeIgnored);
    assertThat(notIgnoredDiagnostics).noneMatch(data::diagnosticShouldBeIgnored);
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 67 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class MethodSymbolComputerTest method testParseError.

@Test
void testParseError() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/MethodSymbolComputerTestParseError.bsl");
    List<MethodSymbol> methods = documentContext.getSymbolTree().getMethods();
    assertThat(methods.get(0).getName()).isEqualTo("Выполнить");
    assertThat(methods.get(0).getSubNameRange()).isEqualTo(Ranges.create(0, 10, 0, 19));
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 68 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class MethodSymbolComputerTest method testAnnotation.

@Test
void testAnnotation() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/MethodSymbolComputerTest.bsl");
    List<MethodSymbol> methods = documentContext.getSymbolTree().getMethods();
    // CUSTOM
    MethodSymbol methodSymbol = methods.get(19);
    assertThat(methodSymbol.getName()).isEqualTo("Метод20");
    assertThat(methodSymbol.getCompilerDirectiveKind()).isEmpty();
    assertThat(methodSymbol.getAnnotations()).hasSize(1);
    assertThat(methodSymbol.getAnnotations().get(0).getKind()).isEqualTo(AnnotationKind.CUSTOM);
    var parameters = methodSymbol.getAnnotations().get(0).getParameters();
    assertThat(parameters).hasSize(3);
    assertThat(parameters.get(0).getName()).isEqualTo("ДажеСПараметром");
    assertThat(parameters.get(0).isOptional()).isTrue();
    assertThat(parameters.get(0).getValue()).isEqualTo("Да");
    assertThat(parameters.get(1).getName()).isEqualTo("СПараметромБезЗначения");
    assertThat(parameters.get(1).isOptional()).isFalse();
    assertThat(parameters.get(1).getValue()).isEmpty();
    assertThat(parameters.get(2).getName()).isEmpty();
    assertThat(parameters.get(2).isOptional()).isTrue();
    assertThat(parameters.get(2).getValue()).isEqualTo("Значение без параметра");
    // BEFORE
    methodSymbol = methods.get(20);
    assertThat(methodSymbol.getName()).isEqualTo("Р_Перед");
    assertThat(methodSymbol.getAnnotations().get(0).getName()).isEqualTo("Перед");
    assertThat(methodSymbol.getAnnotations().get(0).getKind()).isEqualTo(AnnotationKind.BEFORE);
    assertThat(methodSymbol.getAnnotations().get(0).getParameters().get(0).getValue()).isEqualTo("Перед");
    // AFTER
    methodSymbol = methods.get(21);
    assertThat(methodSymbol.getName()).isEqualTo("Р_После");
    assertThat(methodSymbol.getAnnotations().get(0).getName()).isEqualTo("После");
    assertThat(methodSymbol.getAnnotations().get(0).getKind()).isEqualTo(AnnotationKind.AFTER);
    assertThat(methodSymbol.getAnnotations().get(0).getParameters().get(0).getValue()).isEqualTo("После");
    // AROUND
    methodSymbol = methods.get(22);
    assertThat(methodSymbol.getName()).isEqualTo("Р_Вместо");
    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("Вместо");
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 69 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class MethodSymbolComputerTest method testDeprecated.

@Test
void testDeprecated() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/MethodSymbolComputerTest.bsl");
    List<MethodSymbol> methods = documentContext.getSymbolTree().getMethods();
    MethodSymbol methodSymbol = methods.get(2);
    assertThat(methodSymbol.isDeprecated()).isFalse();
    methodSymbol = methods.get(3);
    assertThat(methodSymbol.isDeprecated()).isTrue();
    assertThat(methodSymbol.getDescription().orElseThrow().getDeprecationInfo()).isEmpty();
    methodSymbol = methods.get(4);
    assertThat(methodSymbol.isDeprecated()).isTrue();
    assertThat(methodSymbol.getDescription().orElseThrow().getDeprecationInfo()).isNotEmpty();
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 70 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class MethodSymbolComputerTest method testMethodSymbolComputer.

@Test
void testMethodSymbolComputer() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/computer/MethodSymbolComputerTest.bsl");
    List<MethodSymbol> methods = documentContext.getSymbolTree().getMethods();
    assertThat(methods.size()).isEqualTo(24);
    assertThat(methods.get(0).getName()).isEqualTo("Один");
    assertThat(methods.get(0).getDescription()).isNotPresent();
    assertThat(methods.get(0).getRange()).isEqualTo(Ranges.create(1, 0, 3, 14));
    assertThat(methods.get(0).getSubNameRange()).isEqualTo(Ranges.create(1, 10, 1, 14));
    assertThat(methods.get(1).getDescription()).isNotEmpty();
    assertThat(methods.get(1).getRegion().orElse(null).getName()).isEqualTo("ИмяОбласти");
    assertThat(methods.get(1).getDescription().orElse(null).getDescription()).isNotEmpty();
    var methodSymbol = methods.get(5);
    assertThat(methodSymbol.getName()).isEqualTo("Метод6");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_CLIENT);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(6);
    assertThat(methodSymbol.getName()).isEqualTo("Метод7");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_SERVER_NO_CONTEXT);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(7);
    assertThat(methodSymbol.getName()).isEqualTo("Метод8");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_CLIENT);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(8);
    assertThat(methodSymbol.getName()).isEqualTo("Метод9");
    assertThat(methodSymbol.getCompilerDirectiveKind()).isEmpty();
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(9);
    assertThat(methodSymbol.getName()).isEqualTo("Метод10");
    assertThat(methodSymbol.getCompilerDirectiveKind()).isEmpty();
    var annotations = methodSymbol.getAnnotations();
    assertThat(annotations).hasSize(1);
    assertThat(annotations.get(0).getKind()).isEqualTo(AnnotationKind.AFTER);
    assertThat(annotations.get(0).getName()).isEqualTo("После");
    assertThat(annotations.get(0).getParameters()).isEmpty();
    methodSymbol = methods.get(10);
    assertThat(methodSymbol.getName()).isEqualTo("Метод11");
    checkCompilerDirective_for_AtClient_AndAnnotation_After(methodSymbol);
    methodSymbol = methods.get(11);
    assertThat(methodSymbol.getName()).isEqualTo("Метод12");
    checkCompilerDirective_for_AtClient_AndAnnotation_After(methodSymbol);
    methodSymbol = methods.get(12);
    assertThat(methodSymbol.getName()).isEqualTo("Метод13");
    checkCompilerDirective_for_AtClient_AndAnnotation_After(methodSymbol);
    methodSymbol = methods.get(13);
    assertThat(methodSymbol.getName()).isEqualTo("Метод14");
    assertThat(methodSymbol.getCompilerDirectiveKind()).isEmpty();
    annotations = methodSymbol.getAnnotations();
    assertThat(annotations).hasSize(2);
    assertThat(annotations.get(0).getKind()).isEqualTo(AnnotationKind.CUSTOM);
    assertThat(annotations.get(1).getKind()).isEqualTo(AnnotationKind.CUSTOM);
    methodSymbol = methods.get(14);
    assertThat(methodSymbol.getName()).isEqualTo("Метод15");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_SERVER_NO_CONTEXT);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(15);
    assertThat(methodSymbol.getName()).isEqualTo("Метод16");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_SERVER_NO_CONTEXT);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(16);
    assertThat(methodSymbol.getName()).isEqualTo("Метод17");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_CLIENT_AT_SERVER);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(17);
    assertThat(methodSymbol.getName()).isEqualTo("Метод18");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_CLIENT_AT_SERVER);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
    methodSymbol = methods.get(18);
    assertThat(methodSymbol.getName()).isEqualTo("Метод19");
    assertThat(methodSymbol.getCompilerDirectiveKind().orElse(null)).isEqualTo(CompilerDirectiveKind.AT_CLIENT_AT_SERVER);
    assertThat(methodSymbol.getAnnotations()).isEmpty();
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)86 Test (org.junit.jupiter.api.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)57 Diagnostic (org.eclipse.lsp4j.Diagnostic)36 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)21 SneakyThrows (lombok.SneakyThrows)17 Path (java.nio.file.Path)16 CodeAction (org.eclipse.lsp4j.CodeAction)16 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Collectors (java.util.stream.Collectors)14 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)12 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)12 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)11 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)10 MDCommonModule (com.github._1c_syntax.mdclasses.mdo.MDCommonModule)10