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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations