use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project bsl-language-server by 1c-syntax.
the class CodeActionProviderTest method testGetCodeActions.
@Test
void testGetCodeActions() {
// given
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(CanonicalSpellingKeywordsDiagnostic.class, configuration);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream().filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode)).peek(diagnostic -> diagnostic.setTags(null)).collect(Collectors.toList());
CodeActionParams params = new CodeActionParams();
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
CodeActionContext codeActionContext = new CodeActionContext();
codeActionContext.setDiagnostics(diagnostics);
params.setRange(new Range());
params.setTextDocument(textDocumentIdentifier);
params.setContext(codeActionContext);
// when
List<Either<Command, CodeAction>> codeActions = codeActionProvider.getCodeActions(params, documentContext);
// then
assertThat(codeActions).extracting(Either::getRight).hasSizeGreaterThanOrEqualTo(3).anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(0))).anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(1))).anyMatch(codeAction -> codeAction.getKind().equals(CodeActionKind.QuickFix)).allMatch(codeAction -> (codeAction.getDiagnostics().size() == 1) == toBoolean(codeAction.getIsPreferred()));
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo 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();
}
Aggregations