Search in sources :

Example 76 with DocumentContext

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

the class CommonModuleAssignDiagnosticTest method test.

@SneakyThrows
@Test
void test() {
    Path path = Absolute.path(PATH_TO_METADATA);
    initServerContext(path);
    Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
    DocumentContext documentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
    List<Diagnostic> diagnostics = diagnosticInstance.getDiagnostics(documentContext);
    assertThat(diagnostics).hasSize(1);
    assertThat(diagnostics, true).hasRange(3, 0, 3, 17);
}
Also used : Path(java.nio.file.Path) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 77 with DocumentContext

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

the class CommonModuleNameClientDiagnosticTest method getDocumentContextFromFile.

@SneakyThrows
void getDocumentContextFromFile() {
    Path path = Absolute.path(PATH_TO_METADATA);
    Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
    initServerContext(path);
    var configuration = context.getConfiguration();
    documentContext = spy(TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context));
    module = spy((MDCommonModule) configuration.getModulesByObject().get(documentContext.getUri()));
}
Also used : Path(java.nio.file.Path) MDCommonModule(com.github._1c_syntax.mdclasses.mdo.MDCommonModule) SneakyThrows(lombok.SneakyThrows)

Example 78 with DocumentContext

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

the class CanonicalSpellingKeywordsDiagnosticTest method testQuickFix.

@Test
void testQuickFix() {
    final DocumentContext documentContext = getDocumentContext();
    List<Diagnostic> diagnostics = getDiagnostics();
    final Diagnostic firstDiagnostic = diagnostics.get(0);
    List<CodeAction> quickFixes = getQuickFixes(firstDiagnostic);
    assertThat(quickFixes).hasSize(1);
    final CodeAction quickFix = quickFixes.get(0);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(firstDiagnostic);
    assertThat(quickFix).in(documentContext).hasChanges(1);
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 79 with DocumentContext

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

the class DiagnosticsTest method testCompatibilityMode.

@Test
void testCompatibilityMode() {
    // given
    documentContext = spy(TestUtils.getDocumentContext(""));
    var serverContext = spy(context);
    var bslConfiguration = spy(serverContext.getConfiguration());
    doReturn(serverContext).when(documentContext).getServerContext();
    doReturn(bslConfiguration).when(serverContext).getConfiguration();
    configuration.getDiagnosticsOptions().setMode(Mode.ON);
    // when-then pairs
    doReturn(new CompatibilityMode(3, 10)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
    doReturn(new CompatibilityMode(3, 6)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
    doReturn(new CompatibilityMode(2, 16)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).noneMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
}
Also used : CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 80 with DocumentContext

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

the class EmptyRegionDiagnosticTest method testQuickFix.

@Test
void testQuickFix() {
    final DocumentContext documentContext = getDocumentContext();
    List<Diagnostic> diagnostics = getDiagnostics();
    final Diagnostic externalRegionDiagnostic = diagnostics.get(2);
    final Diagnostic internalRegionDiagnostic = diagnostics.get(1);
    List<CodeAction> quickFixes = getQuickFixes(externalRegionDiagnostic);
    assertThat(quickFixes).hasSize(1);
    final CodeAction quickFix = quickFixes.get(0);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(externalRegionDiagnostic);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(internalRegionDiagnostic);
    assertThat(quickFix).in(documentContext).hasChanges(1).hasNewText("");
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

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