public List<IMarker> publishDiagnostics(IProgressMonitor monitor) throws CoreException { List<IMarker> problemMarkers = getProblemMarkers(monitor); publishDiagnostics(problemMarkers); return problemMarkers; }
/** * Transforms {@link IMarker}s into a list of {@link Diagnostic}s * * @param range * @param markers * @return a list of {@link Diagnostic}s */ public static List<Diagnostic> toDiagnosticArray(Range range, Collection<IMarker> markers) { List<Diagnostic> diagnostics = markers.stream().map(m -> toDiagnostic(range, m)).filter(d -> d != null).collect(Collectors.toList()); return diagnostics; }
workspaceDiagnosticsHandler = new WorkspaceDiagnosticsHandler(this.client, pm); workspaceDiagnosticsHandler.addResourceChangeListener(); workspaceDiagnosticsHandler.publishDiagnostics(monitor); } catch (CoreException e) { logException(e.getMessage(), e);
try { IProject project = (IProject) resource; publishMarkers(project, entry.getValue().toArray(new IMarker[0])); } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document, entry.getValue().toArray(new IMarker[0])); connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
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; }
private void publishMarkers(IProject project, IMarker[] markers) throws CoreException { Range range = new Range(new Position(0, 0), new Position(0, 0)); List<IMarker> projectMarkers = new ArrayList<>(markers.length); String uri = JDTUtils.getFileURI(project); IFile pom = project.getFile("pom.xml"); List<IMarker> pomMarkers = new ArrayList<>(); for (IMarker marker : markers) { if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) { continue; } if (IMavenConstants.MARKER_CONFIGURATION_ID.equals(marker.getType())) { pomMarkers.add(marker); } else { projectMarkers.add(marker); } } List<Diagnostic> diagnostics = toDiagnosticArray(range, projectMarkers); String clientUri = ResourceUtils.toClientUri(uri); connection.publishDiagnostics(new PublishDiagnosticsParams(clientUri, diagnostics)); if (pom.exists()) { IDocument document = JsonRpcHelpers.toDocument(pom); diagnostics = toDiagnosticsArray(document, pom.findMarkers(null, true, IResource.DEPTH_ZERO)); List<Diagnostic> diagnosicts2 = toDiagnosticArray(range, pomMarkers); diagnostics.addAll(diagnosicts2); connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(clientUri + "/pom.xml"), diagnostics)); } }
@Override public CompletableFuture<Object> shutdown() { logInfo(">> shutdown"); return computeAsync((monitor) -> { try { if (workspaceDiagnosticsHandler != null) { workspaceDiagnosticsHandler.removeResourceChangeListener(); workspaceDiagnosticsHandler = null; } ResourcesPlugin.getWorkspace().save(true, monitor); } catch (CoreException e) { logException(e.getMessage(), e); } return new Object(); }); }
private static Diagnostic toDiagnostic(Range range, IMarker marker) { if (marker == null || !marker.exists()) { return null; } Diagnostic d = new Diagnostic(); d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID); String message = marker.getAttribute(IMarker.MESSAGE, ""); if (Messages.ProjectConfigurationUpdateRequired.equals(message)) { message = PROJECT_CONFIGURATION_IS_NOT_UP_TO_DATE_WITH_POM_XML; } d.setMessage(message); d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1))); d.setCode(String.valueOf(marker.getAttribute(IJavaModelMarker.ID, 0))); d.setRange(range); return d; }
publishMarkers(project, markers); return true; this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(document, markers)));
/** * Transforms {@link IMarker}s of a {@link IDocument} into a list of * {@link Diagnostic}s. * * @param document * @param markers * @return a list of {@link Diagnostic}s */ public static List<Diagnostic> toDiagnosticsArray(IDocument document, IMarker[] markers) { List<Diagnostic> diagnostics = Stream.of(markers) .map(m -> toDiagnostic(document, m)) .filter(d -> d != null) .collect(Collectors.toList()); return diagnostics; }