Search in sources :

Example 16 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method checkFilePathForAllProblems.

private boolean checkFilePathForAllProblems(Path path, Boolean quick) {
    ICompilationUnit mainUnit = getCompilationUnit(path);
    if (mainUnit == null) {
        return false;
    }
    CompilerProject project = (CompilerProject) mainUnit.getProject();
    Collection<ICompilerProblem> fatalProblems = project.getFatalProblems();
    if (fatalProblems == null || fatalProblems.size() == 0) {
        fatalProblems = project.getProblems();
    }
    if (fatalProblems != null && fatalProblems.size() > 0) {
        URI uri = path.toUri();
        PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
        publish.setDiagnostics(new ArrayList<>());
        publish.setUri(uri.toString());
        codeProblemTracker.trackFileWithProblems(uri);
        for (ICompilerProblem problem : fatalProblems) {
            addCompilerProblem(problem, publish);
        }
        codeProblemTracker.cleanUpStaleProblems();
        if (languageClient != null) {
            languageClient.publishDiagnostics(publish);
        }
        return true;
    }
    IASNode ast = null;
    try {
        ast = mainUnit.getSyntaxTreeRequest().get().getAST();
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        return false;
    }
    if (ast == null) {
        return false;
    }
    Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
    try {
        if (quick) {
            PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(mainUnit);
            URI uri = Paths.get(mainUnit.getAbsoluteFilename()).toUri();
            files.put(uri, params);
        } else {
            boolean continueCheckingForErrors = true;
            while (continueCheckingForErrors) {
                try {
                    for (ICompilationUnit unit : compilationUnits) {
                        if (unit == null || unit instanceof SWCCompilationUnit) {
                            //compiled compilation units won't have problems
                            continue;
                        }
                        PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(unit);
                        URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
                        files.put(uri, params);
                    }
                    continueCheckingForErrors = false;
                } catch (ConcurrentModificationException e) {
                //when we finished building one of the compilation
                //units, more were added to the collection, so we need
                //to start over because we can't iterate over a modified
                //collection.
                }
            }
            //only clean up stale errors on a full check
            codeProblemTracker.cleanUpStaleProblems();
        }
    } catch (Exception e) {
        System.err.println("Exception during build: " + e);
        e.printStackTrace();
        return false;
    }
    if (languageClient != null) {
        files.values().forEach(languageClient::publishDiagnostics);
    }
    return true;
}
Also used : ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) ConcurrentModificationException(java.util.ConcurrentModificationException) HashMap(java.util.HashMap) CompilerProject(org.apache.flex.compiler.internal.projects.CompilerProject) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) SWCCompilationUnit(org.apache.flex.compiler.internal.units.SWCCompilationUnit) IASNode(org.apache.flex.compiler.tree.as.IASNode) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Example 17 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method checkCompilationUnitForAllProblems.

private PublishDiagnosticsParams checkCompilationUnitForAllProblems(ICompilationUnit unit) {
    URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
    PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
    publish.setDiagnostics(new ArrayList<>());
    publish.setUri(uri.toString());
    codeProblemTracker.trackFileWithProblems(uri);
    ArrayList<ICompilerProblem> problems = new ArrayList<>();
    try {
        unit.waitForBuildFinish(problems, ITarget.TargetType.SWF);
        for (ICompilerProblem problem : problems) {
            addCompilerProblem(problem, publish);
        }
    } catch (Exception e) {
        System.err.println("Exception during waitForBuildFinish(): " + e);
        e.printStackTrace();
        Diagnostic diagnostic = createDiagnosticWithoutRange();
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("A fatal error occurred while checking a file for problems: " + unit.getAbsoluteFilename());
        publish.getDiagnostics().add(diagnostic);
    }
    return publish;
}
Also used : ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 18 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project sonarlint-core by SonarSource.

the class SonarLintLanguageServer method newPublishDiagnostics.

private static PublishDiagnosticsParams newPublishDiagnostics(URI newUri) {
    PublishDiagnosticsParams p = new PublishDiagnosticsParams();
    p.setDiagnostics(new ArrayList<>());
    p.setUri(newUri.toString());
    return p;
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Example 19 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.

the class DocumentLifeCycleHandlerTest method assertNewProblemReported.

private void assertNewProblemReported(ExpectedProblemReport... expectedReports) {
    List<PublishDiagnosticsParams> diags = getClientRequests("publishDiagnostics");
    assertEquals(expectedReports.length, diags.size());
    for (int i = 0; i < expectedReports.length; i++) {
        PublishDiagnosticsParams diag = diags.get(i);
        ExpectedProblemReport expected = expectedReports[i];
        assertEquals(JDTUtils.toURI(expected.cu), diag.getUri());
        if (expected.problemCount != diag.getDiagnostics().size()) {
            String message = "";
            for (Diagnostic d : diag.getDiagnostics()) {
                message += d.getMessage() + ", ";
            }
            assertEquals(message, expected.problemCount, diag.getDiagnostics().size());
        }
    }
    diags.clear();
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 20 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.

the class DocumentLifeCycleHandlerTest method testDidOpenStandaloneFileWithSyntaxError.

@Test
public void testDidOpenStandaloneFileWithSyntaxError() throws Exception {
    IJavaProject javaProject = newDefaultProject();
    IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
    IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
    // @formatter:off
    String standaloneFileContent = "package java;\n" + "public class Foo extends UnknownType {\n" + "	public void method1(){\n" + "		super.whatever()\n" + "	}\n" + "}";
    // @formatter:on
    ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
    openDocument(cu1, cu1.getSource(), 1);
    List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
    assertEquals(1, diagnosticReports.size());
    PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
    assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 1, diagParam.getDiagnostics().size());
    Diagnostic d = diagParam.getDiagnostics().get(0);
    assertEquals("Syntax error, insert \";\" to complete BlockStatements", d.getMessage());
    assertRange(3, 17, 18, d.getRange());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Diagnostic(org.eclipse.lsp4j.Diagnostic) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)22 Diagnostic (org.eclipse.lsp4j.Diagnostic)8 URI (java.net.URI)7 ArrayList (java.util.ArrayList)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 HashMap (java.util.HashMap)4 ICompilerProblem (org.apache.flex.compiler.problems.ICompilerProblem)4 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ConcurrentModificationException (java.util.ConcurrentModificationException)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)3 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 Workspace (org.apache.flex.compiler.internal.workspaces.Workspace)2 IWorkspace (org.apache.flex.compiler.workspaces.IWorkspace)2