Search in sources :

Example 1 with Diagnostic

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

the class ActionScriptTextDocumentService method addCompilerProblem.

private void addCompilerProblem(ICompilerProblem problem, PublishDiagnosticsParams publish) {
    if (!flexLibSDKContainsFalconCompiler) {
        if (problem.getClass().equals(FontEmbeddingNotSupported.class)) {
            //ignore this error because the framework SDK can embed fonts
            return;
        }
    }
    Diagnostic diagnostic = new Diagnostic();
    DiagnosticSeverity severity = LanguageServerUtils.getDiagnosticSeverityFromCompilerProblem(problem);
    diagnostic.setSeverity(severity);
    Range range = LanguageServerUtils.getRangeFromSourceLocation(problem);
    if (range == null) {
        //fall back to an empty range
        range = new Range(new Position(), new Position());
    }
    diagnostic.setRange(range);
    diagnostic.setMessage(problem.toString());
    try {
        Field field = problem.getClass().getDeclaredField("errorCode");
        int errorCode = (int) field.get(problem);
        diagnostic.setCode(Integer.toString(errorCode));
    } catch (Exception e) {
    //skip it
    }
    List<Diagnostic> diagnostics = publish.getDiagnostics();
    diagnostics.add(diagnostic);
}
Also used : Field(java.lang.reflect.Field) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with Diagnostic

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

the class SonarLintLanguageServer method convert.

static Optional<Diagnostic> convert(Issue issue) {
    if (issue.getStartLine() != null) {
        Range range = position(issue);
        Diagnostic diagnostic = new Diagnostic();
        DiagnosticSeverity severity = severity(issue.getSeverity());
        diagnostic.setSeverity(severity);
        diagnostic.setRange(range);
        diagnostic.setCode(issue.getRuleKey());
        diagnostic.setMessage(issue.getMessage() + " (" + issue.getRuleKey() + ")");
        diagnostic.setSource(SONARLINT_SOURCE);
        return Optional.of(diagnostic);
    }
    return Optional.empty();
}
Also used : DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Example 3 with Diagnostic

use of org.eclipse.lsp4j.Diagnostic in project xtext-core by eclipse.

the class CodeActionService method getCodeActions.

@Override
public List<? extends Command> getCodeActions(final Document document, final XtextResource resource, final CodeActionParams params, final CancelIndicator indicator) {
    final ArrayList<Command> commands = CollectionLiterals.<Command>newArrayList();
    List<Diagnostic> _diagnostics = params.getContext().getDiagnostics();
    for (final Diagnostic d : _diagnostics) {
        String _code = d.getCode();
        if (_code != null) {
            switch(_code) {
                case TestLanguageValidator.INVALID_NAME:
                    Command _fixInvalidName = this.fixInvalidName(d, document, resource, params);
                    commands.add(_fixInvalidName);
                    break;
                case TestLanguageValidator.UNSORTED_MEMBERS:
                    Command _fixUnsortedMembers = this.fixUnsortedMembers(d, document, resource, params);
                    commands.add(_fixUnsortedMembers);
                    break;
            }
        }
    }
    return commands;
}
Also used : Command(org.eclipse.lsp4j.Command) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 4 with Diagnostic

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

the class BuildWorkspaceHandler method publishDiagnostics.

private void publishDiagnostics(List<IMarker> markers) {
    Map<IResource, List<IMarker>> map = markers.stream().collect(Collectors.groupingBy(IMarker::getResource));
    for (Map.Entry<IResource, List<IMarker>> entry : map.entrySet()) {
        IResource resource = entry.getKey();
        // ignore problems caused by standalone files
        if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject())) {
            continue;
        }
        IFile file = resource.getAdapter(IFile.class);
        if (file == null) {
            continue;
        }
        IDocument document = null;
        String uri = JDTUtils.getFileURI(resource);
        if (JavaCore.isJavaLikeFileName(file.getName())) {
            ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
            try {
                document = JsonRpcHelpers.toDocument(cu.getBuffer());
            } catch (JavaModelException e) {
                logException("Failed to publish diagnostics.", e);
            }
        } else if (projectsManager.isBuildFile(file)) {
            document = JsonRpcHelpers.toDocument(file);
        }
        if (document != null) {
            List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document, entry.getValue().toArray(new IMarker[0]));
            connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) Diagnostic(org.eclipse.lsp4j.Diagnostic) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ArrayList(java.util.ArrayList) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with Diagnostic

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

the class WorkspaceDiagnosticsHandler method toDiagnostic.

private static Diagnostic toDiagnostic(IDocument document, IMarker marker) {
    if (marker == null || !marker.exists()) {
        return null;
    }
    Diagnostic d = new Diagnostic();
    d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
    d.setMessage(marker.getAttribute(IMarker.MESSAGE, ""));
    d.setCode(String.valueOf(marker.getAttribute(IJavaModelMarker.ID, 0)));
    d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
    d.setRange(convertRange(document, marker));
    return d;
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic)

Aggregations

Diagnostic (org.eclipse.lsp4j.Diagnostic)60 Test (org.junit.Test)33 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)22 Range (org.eclipse.lsp4j.Range)17 ArrayList (java.util.ArrayList)13 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)10 Position (org.eclipse.lsp4j.Position)8 List (java.util.List)7 Command (org.eclipse.lsp4j.Command)6 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 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 CompletableFuture (java.util.concurrent.CompletableFuture)4 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)4