Search in sources :

Example 96 with DocumentContext

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

the class SmokyTest method testIAllDiagnostics.

@SneakyThrows
@Test
void testIAllDiagnostics() {
    // прочитаем все файлы ресурсов
    var srcDir = "./src/test/resources/";
    var fixtures = FileUtils.listFiles(new File(srcDir), new String[] { "bsl", "os" }, true);
    // получим все возможные коды диагностик и положим в мапу "включенным"
    Map<String, Either<Boolean, Map<String, Object>>> diagnostics = diagnosticInfos.stream().map(DiagnosticInfo::getCode).collect(Collectors.toMap(diagnosticCode -> diagnosticCode.getStringValue(), diagnosticCode -> Either.forLeft(true), (a, b) -> b));
    // создадим новый конфиг, в котором включим все диагностики
    configuration.getDiagnosticsOptions().setParameters(diagnostics);
    // для каждой фикстуры расчитаем диагностики
    // если упадет, запомним файл и текст ошибки
    Map<File, Exception> diagnosticErrors = new HashMap<>();
    fixtures.forEach(filePath -> {
        try {
            var documentContext = TestUtils.getDocumentContextFromFile(filePath.toString());
            documentContext.getDiagnostics();
        } catch (Exception e) {
            diagnosticErrors.put(filePath, e);
        }
    });
    assertThat(diagnosticErrors).isEmpty();
}
Also used : DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) BSLLSPLauncher(com.github._1c_syntax.bsl.languageserver.BSLLSPLauncher) SneakyThrows(lombok.SneakyThrows) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) FileUtils(org.apache.commons.io.FileUtils) Diagnostic(org.eclipse.lsp4j.Diagnostic) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Paths(java.nio.file.Paths) Map(java.util.Map) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) CleanupContextBeforeClassAndAfterEachTestMethod(com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) HashMap(java.util.HashMap) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 97 with DocumentContext

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

the class TimeoutsInExternalResourcesDiagnosticTest method testCompatibilityMode837.

@SneakyThrows
@Test
void testCompatibilityMode837() {
    // 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_7"), StandardCharsets.UTF_8);
    Path testFile = Paths.get("./src/test/resources/diagnostics/TimeoutsInExternalResourcesDiagnostic837.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_7.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 98 with DocumentContext

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

the class FormatProviderTest method testFormat.

@Test
void testFormat() throws IOException {
    // given
    DocumentFormattingParams params = new DocumentFormattingParams();
    params.setTextDocument(getTextDocumentIdentifier());
    params.setOptions(new FormattingOptions(4, true));
    String fileContent = FileUtils.readFileToString(getTestFile(), StandardCharsets.UTF_8);
    String formattedFileContent = FileUtils.readFileToString(getFormattedTestFile(), StandardCharsets.UTF_8);
    DocumentContext documentContext = TestUtils.getDocumentContext(URI.create(params.getTextDocument().getUri()), fileContent);
    // when
    List<TextEdit> textEdits = formatProvider.getFormatting(params, documentContext);
    // then
    assertThat(textEdits).hasSize(1);
    TextEdit textEdit = textEdits.get(0);
    assertThat(textEdit.getNewText()).isEqualTo(formattedFileContent);
}
Also used : FormattingOptions(org.eclipse.lsp4j.FormattingOptions) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 99 with DocumentContext

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

the class HoverProviderTest method testEmptyHover.

@Test
void testEmptyHover() {
    // given
    HoverParams params = new HoverParams();
    params.setPosition(new Position(0, 0));
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    // when
    Optional<Hover> optionalHover = hoverProvider.getHover(documentContext, params);
    // then
    assertThat(optionalHover).isNotPresent();
}
Also used : HoverParams(org.eclipse.lsp4j.HoverParams) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 100 with DocumentContext

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

the class ReferencesProviderTest method testEmptyReferences.

@Test
void testEmptyReferences() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    var params = new ReferenceParams();
    params.setPosition(new Position(1, 0));
    // when
    var references = referencesProvider.getReferences(documentContext, params);
    // then
    assertThat(references).isEmpty();
}
Also used : ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) 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