Search in sources :

Example 1 with ResolvingJavaTypeContext

use of com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext in project quarkus-ls by redhat-developer.

the class TemplateFileTextDocumentService method triggerValidationFor.

private void triggerValidationFor(QuteTextDocument document) {
    // 
    document.getModel().thenApply((template) -> {
        // The template is parsed, check if the document has changed since the
        // parsing
        template.checkCanceled();
        // Collect diagnostics
        ResolvingJavaTypeContext resolvingJavaTypeContext = new ResolvingJavaTypeContext(template);
        List<Diagnostic> diagnostics = getQuteLanguageService().doDiagnostics(template, getSharedSettings().getValidationSettings(template.getUri()), resolvingJavaTypeContext, () -> template.checkCanceled());
        // Diagnostics has been collected, before diagnostics publishing, check if the
        // document has changed since diagnostics collect.
        template.checkCanceled();
        // Publish diagnostics
        quteLanguageServer.getLanguageClient().publishDiagnostics(new PublishDiagnosticsParams(template.getUri(), diagnostics));
        if (!resolvingJavaTypeContext.isEmpty()) {
            // Some Java types was not loaded, wait for that all Java types are resolved to
            // retrigger the validation.
            CompletableFuture<Void> allFutures = CompletableFuture.allOf(resolvingJavaTypeContext.toArray(new CompletableFuture[resolvingJavaTypeContext.size()]));
            allFutures.thenAccept(Void -> {
                triggerValidationFor(document);
            });
        }
        return null;
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResolvingJavaTypeContext(com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 2 with ResolvingJavaTypeContext

use of com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext in project quarkus-ls by redhat-developer.

the class QuteAssert method testDiagnosticsFor.

public static void testDiagnosticsFor(String value, String fileUri, String templateId, String projectUri, String templateBaseDir, boolean filter, QuteValidationSettings validationSettings, Diagnostic... expected) {
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    template.setTemplateId(templateId);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    List<Diagnostic> actual = languageService.doDiagnostics(template, validationSettings, new ResolvingJavaTypeContext(template), () -> {
    });
    if (expected == null) {
        assertTrue(actual.isEmpty());
        return;
    }
    assertDiagnostics(actual, Arrays.asList(expected), filter);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) ResolvingJavaTypeContext(com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext) Diagnostic(org.eclipse.lsp4j.Diagnostic) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template)

Aggregations

ResolvingJavaTypeContext (com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 Template (com.redhat.qute.parser.template.Template)1 MockQuteProjectRegistry (com.redhat.qute.project.MockQuteProjectRegistry)1 QuteProjectRegistry (com.redhat.qute.project.QuteProjectRegistry)1 JavaDataModelCache (com.redhat.qute.project.datamodel.JavaDataModelCache)1 QuteLanguageService (com.redhat.qute.services.QuteLanguageService)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1