use of com.github._1c_syntax.bsl.languageserver.diagnostics.QuickFixProvider in project bsl-language-server by 1c-syntax.
the class QuickFixSupplierTest method testGetQuickFixClass.
@Test
void testGetQuickFixClass() {
Optional<Class<? extends QuickFixProvider>> quickFixClass = quickFixSupplier.getQuickFixClass(new DiagnosticCode("NON_EXISTING"));
assertThat(quickFixClass).isEmpty();
quickFixClass = quickFixSupplier.getQuickFixClass(new DiagnosticCode("CommitTransactionOutsideTryCatch"));
assertThat(quickFixClass).isEmpty();
quickFixClass = quickFixSupplier.getQuickFixClass(new DiagnosticCode("CommentedCode"));
assertThat(quickFixClass).hasValue(CommentedCodeDiagnostic.class);
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.QuickFixProvider in project bsl-language-server by 1c-syntax.
the class QuickFixCodeActionSupplier method getCodeActionsByDiagnostic.
private List<CodeAction> getCodeActionsByDiagnostic(Diagnostic diagnostic, CodeActionParams params, DocumentContext documentContext) {
Optional<Class<? extends QuickFixProvider>> quickFixClass = quickFixSupplier.getQuickFixClass(diagnostic.getCode());
if (quickFixClass.isEmpty()) {
return Collections.emptyList();
}
Class<? extends QuickFixProvider> quickFixProviderClass = quickFixClass.get();
QuickFixProvider quickFixInstance = quickFixSupplier.getQuickFixInstance(quickFixProviderClass);
return quickFixInstance.getQuickFixes(Collections.singletonList(diagnostic), params, documentContext);
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.QuickFixProvider in project bsl-language-server by 1c-syntax.
the class FixAllCodeActionSupplier method getFixAllCodeAction.
private List<CodeAction> getFixAllCodeAction(Either<String, Integer> diagnosticCode, CodeActionParams params, DocumentContext documentContext) {
Optional<Class<? extends QuickFixProvider>> quickFixClass = quickFixSupplier.getQuickFixClass(diagnosticCode);
if (quickFixClass.isEmpty()) {
return Collections.emptyList();
}
List<Diagnostic> suitableDiagnostics = documentContext.getComputedDiagnostics().stream().filter(diagnostic -> diagnosticCode.equals(diagnostic.getCode())).collect(Collectors.toList());
// if incomingDiagnostics list has size = 1 - it will be displayed as regular quick fix
if (suitableDiagnostics.size() < ADD_FIX_ALL_DIAGNOSTICS_THRESHOLD) {
return Collections.emptyList();
}
CodeActionContext fixAllContext = new CodeActionContext();
fixAllContext.setDiagnostics(suitableDiagnostics);
fixAllContext.setOnly(Collections.singletonList(CodeActionKind.QuickFix));
CodeActionParams fixAllParams = new CodeActionParams();
fixAllParams.setTextDocument(params.getTextDocument());
fixAllParams.setRange(params.getRange());
fixAllParams.setContext(fixAllContext);
Class<? extends QuickFixProvider> quickFixProviderClass = quickFixClass.get();
QuickFixProvider quickFixInstance = quickFixSupplier.getQuickFixInstance(quickFixProviderClass);
return quickFixInstance.getQuickFixes(suitableDiagnostics, fixAllParams, documentContext);
}
Aggregations