Search in sources :

Example 26 with DocumentContext

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

the class ReferenceIndexFillerTest method testRebuildClearReferences.

@Test
void testRebuildClearReferences() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/ReferenceIndexFillerTest.bsl");
    MethodSymbol methodSymbol = documentContext.getSymbolTree().getMethodSymbol("Локальная").orElseThrow();
    // when
    referenceIndexFiller.fill(documentContext);
    List<Reference> referencesTo = referenceIndex.getReferencesTo(methodSymbol);
    // then
    assertThat(referencesTo).hasSize(1);
    // when
    // recalculate
    referenceIndexFiller.fill(documentContext);
    referencesTo = referenceIndex.getReferencesTo(methodSymbol);
    // then
    assertThat(referencesTo).hasSize(1);
}
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 27 with DocumentContext

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

the class TimeoutsInExternalResourcesDiagnosticTest method testCompatibilityMode836.

@SneakyThrows
@Test
void testCompatibilityMode836() {
    // when
    FileUtils.writeStringToFile(Paths.get(tempDir.toAbsolutePath().toString(), "Configuration.xml").toFile(), FileUtils.readFileToString(CONFIGURATION_FILE_PATH, StandardCharsets.UTF_8).replace("Version8_3_10", "Version8_3_6"), StandardCharsets.UTF_8);
    Path testFile = Paths.get("./src/test/resources/diagnostics/TimeoutsInExternalResourcesDiagnostic836.bsl").toAbsolutePath();
    initServerContext(tempDir.toAbsolutePath());
    DocumentContext newDocumentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
    List<Diagnostic> diagnostics = getDiagnostics(newDocumentContext);
    // then
    assertThat(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode()).isNotNull();
    assertThat(CompatibilityMode.compareTo(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode(), DiagnosticCompatibilityMode.COMPATIBILITY_MODE_8_3_6.getCompatibilityMode())).isZero();
    assertThat(diagnostics).hasSize(9);
    // check ranges
    assertThat(diagnostics, true).hasRange(3, 20, 3, 75).hasRange(5, 20, 5, 92).hasRange(9, 18, 9, 72).hasRange(13, 16, 13, 80).hasRange(21, 21, 21, 65).hasRange(34, 14, 34, 43).hasRange(71, 26, 71, 114).hasRange(78, 10, 78, 39).hasRange(80, 47, 80, 76);
}
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 28 with DocumentContext

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

the class TimeoutsInExternalResourcesDiagnosticTest method testCompatibilityMode8310.

@SneakyThrows
@Test
void testCompatibilityMode8310() {
    // when
    Path testFile = Paths.get("./src/test/resources/diagnostics/TimeoutsInExternalResourcesDiagnostic.bsl").toAbsolutePath();
    initServerContext(Paths.get("./src/test/resources/metadata").toAbsolutePath());
    DocumentContext newDocumentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
    List<Diagnostic> diagnostics = getDiagnostics(newDocumentContext);
    // then
    assertThat(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode()).isNotNull();
    assertThat(CompatibilityMode.compareTo(newDocumentContext.getServerContext().getConfiguration().getCompatibilityMode(), DiagnosticCompatibilityMode.COMPATIBILITY_MODE_8_3_10.getCompatibilityMode())).isZero();
    assertThat(diagnostics).hasSize(9);
    // check ranges
    assertThat(diagnostics, true).hasRange(3, 20, 3, 75).hasRange(5, 20, 5, 92).hasRange(9, 18, 9, 72).hasRange(13, 16, 13, 80).hasRange(21, 21, 21, 65).hasRange(34, 14, 34, 43).hasRange(71, 26, 71, 114).hasRange(78, 10, 78, 39).hasRange(80, 47, 80, 76);
}
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 29 with DocumentContext

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

the class UsingModalWindowsDiagnosticTest method testUseWithForce.

@Test
void testUseWithForce() {
    DocumentContext documentContext = getDocumentContextWithUseFlag(UseMode.USE);
    Map<String, Object> configuration = diagnosticInstance.getInfo().getDefaultConfiguration();
    configuration.put("forceModalityMode", true);
    diagnosticInstance.configure(configuration);
    List<Diagnostic> diagnostics = getDiagnostics(documentContext);
    assertDiagnosticList(diagnostics);
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 30 with DocumentContext

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

the class UsingThisFormDiagnosticTest method runQuickFixTest.

@Test
void runQuickFixTest() {
    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).hasNewText(THIS_OBJECT);
}
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