Search in sources :

Example 31 with Diagnostic

use of org.eclipse.lsp4j.Diagnostic in project sts4 by spring-projects.

the class ConcourseEditorTest method violatedPropertyConstraintsAreWarnings.

@Test
public void violatedPropertyConstraintsAreWarnings() throws Exception {
    Editor editor;
    editor = harness.newEditor("jobs:\n" + "- name: blah");
    Diagnostic problem = editor.assertProblems("-^ name: blah|'plan' is required").get(0);
    assertEquals(DiagnosticSeverity.Warning, problem.getSeverity());
    editor = harness.newEditor("jobs:\n" + "- name: do-stuff\n" + "  plan:\n" + "  - task: foo");
    problem = editor.assertProblems("-^ task: foo|One of [config, file] is required").get(0);
    assertEquals(DiagnosticSeverity.Warning, problem.getSeverity());
    editor = harness.newEditor("jobs:\n" + "- name: do-stuff\n" + "  plan:\n" + "  - task: foo\n" + "    config: {}\n" + "    file: path/to/file");
    {
        List<Diagnostic> problems = editor.assertProblems("config|One of [image_resource, rootfs_uri, image]", "config|Only one of [config, file]", "config|[platform, run] are required", "file|Only one of [config, file]");
        // All of the problems in this example are property contraint violations! So all should be warnings.
        for (Diagnostic diagnostic : problems) {
            assertEquals(DiagnosticSeverity.Warning, diagnostic.getSeverity());
        }
    }
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Test(org.junit.Test)

Example 32 with Diagnostic

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

the class ActionScriptTextDocumentService method checkFilePathForSyntaxProblems.

private void checkFilePathForSyntaxProblems(Path path) {
    URI uri = path.toUri();
    PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
    ArrayList<Diagnostic> diagnostics = new ArrayList<>();
    publish.setDiagnostics(diagnostics);
    publish.setUri(uri.toString());
    codeProblemTracker.trackFileWithProblems(uri);
    ASParser parser = null;
    Reader reader = getReaderForPath(path);
    if (reader != null) {
        StreamingASTokenizer tokenizer = StreamingASTokenizer.createForRepairingASTokenizer(reader, uri.toString(), null);
        ASToken[] tokens = tokenizer.getTokens(reader);
        if (tokenizer.hasTokenizationProblems()) {
            for (ICompilerProblem problem : tokenizer.getTokenizationProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
        RepairingTokenBuffer buffer = new RepairingTokenBuffer(tokens);
        Workspace workspace = new Workspace();
        workspace.endRequest();
        parser = new ASParser(workspace, buffer);
        FileNode node = new FileNode(workspace);
        try {
            parser.file(node);
        } catch (Exception e) {
            parser = null;
            System.err.println("Failed to parse file (" + path.toString() + "): " + e);
            e.printStackTrace();
        }
        //if an error occurred above, parser will be null
        if (parser != null) {
            for (ICompilerProblem problem : parser.getSyntaxProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
    }
    Diagnostic diagnostic = createDiagnosticWithoutRange();
    diagnostic.setSeverity(DiagnosticSeverity.Information);
    if (reader == null) {
        //the file does not exist
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("File not found: " + path.toAbsolutePath().toString() + ". Error checking disabled.");
    } else if (parser == null) {
        //something terrible happened, and this is the best we can do
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("A fatal error occurred while checking for simple syntax problems.");
    } else if (currentProjectOptions == null) {
        //something went wrong while attempting to load and parse the
        //project configuration.
        diagnostic.setMessage("Failed to load project configuration options. Error checking disabled, except for simple syntax problems.");
    } else {
        //we loaded and parsed the project configuration, so something went
        //wrong while checking for errors.
        diagnostic.setMessage("A fatal error occurred while checking for errors. Error checking disabled, except for simple syntax problems.");
    }
    diagnostics.add(diagnostic);
    codeProblemTracker.cleanUpStaleProblems();
    if (languageClient != null) {
        languageClient.publishDiagnostics(publish);
    }
}
Also used : StreamingASTokenizer(org.apache.flex.compiler.internal.parsing.as.StreamingASTokenizer) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ASToken(org.apache.flex.compiler.internal.parsing.as.ASToken) RepairingTokenBuffer(org.apache.flex.compiler.internal.parsing.as.RepairingTokenBuffer) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ASParser(org.apache.flex.compiler.internal.parsing.as.ASParser) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) FileNode(org.apache.flex.compiler.internal.tree.as.FileNode) IFileNode(org.apache.flex.compiler.tree.as.IFileNode) Workspace(org.apache.flex.compiler.internal.workspaces.Workspace) IWorkspace(org.apache.flex.compiler.workspaces.IWorkspace)

Example 33 with Diagnostic

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

the class ActionScriptTextDocumentService method codeAction.

/**
     * Can be used to "quick fix" an error or warning.
     */
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
    List<? extends Diagnostic> diagnostics = params.getContext().getDiagnostics();
    TextDocumentIdentifier textDocument = params.getTextDocument();
    Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
    if (path == null || !sourceByPath.containsKey(path)) {
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
    ArrayList<Command> commands = new ArrayList<>();
    for (Diagnostic diagnostic : diagnostics) {
        //I don't know why this can be null
        String code = diagnostic.getCode();
        if (code == null) {
            continue;
        }
        switch(code) {
            case //AccessUndefinedPropertyProblem
            "1120":
                {
                    //see if there's anything we can import
                    createCodeActionsForImport(diagnostic, commands);
                    break;
                }
            case //UnknownTypeProblem
            "1046":
                {
                    //see if there's anything we can import
                    createCodeActionsForImport(diagnostic, commands);
                    break;
                }
            case //InaccessiblePropertyReferenceProblem
            "1178":
                {
                    //see if there's anything we can import
                    createCodeActionsForImport(diagnostic, commands);
                    break;
                }
            case //CallUndefinedMethodProblem
            "1180":
                {
                    //see if there's anything we can import
                    createCodeActionsForImport(diagnostic, commands);
                    break;
                }
        }
    }
    return CompletableFuture.completedFuture(commands);
}
Also used : Path(java.nio.file.Path) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Command(org.eclipse.lsp4j.Command) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 34 with Diagnostic

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

the class ActionScriptTextDocumentService method createDiagnosticWithoutRange.

private Diagnostic createDiagnosticWithoutRange() {
    Diagnostic diagnostic = new Diagnostic();
    Range range = new Range();
    range.setStart(new Position());
    range.setEnd(new Position());
    diagnostic.setRange(range);
    return diagnostic;
}
Also used : Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Example 35 with Diagnostic

use of org.eclipse.lsp4j.Diagnostic 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)

Aggregations

Diagnostic (org.eclipse.lsp4j.Diagnostic)56 Test (org.junit.Test)31 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)22 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)11 List (java.util.List)8 Position (org.eclipse.lsp4j.Position)8 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)7 URI (java.net.URI)5 Path (java.nio.file.Path)5 Map (java.util.Map)5 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)5 Command (org.eclipse.lsp4j.Command)5 MarkedString (org.eclipse.lsp4j.MarkedString)5 CodeAction (org.springframework.ide.vscode.languageserver.testharness.CodeAction)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)3