Java Code Examples for org.eclipse.lsp4j.Diagnostic#getSeverity()

The following examples show how to use org.eclipse.lsp4j.Diagnostic#getSeverity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LSPAnnotator.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
protected Annotation createAnnotation(Editor editor, AnnotationHolder holder, Diagnostic diagnostic) {
    final int start = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getStart());
    final int end = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getEnd());
    if (start >= end) {
        return null;
    }
    final TextRange textRange = new TextRange(start, end);
    switch (diagnostic.getSeverity()) {
        // TODO: Use 'newAnnotation'; 'create*Annotation' methods are deprecated.
        case Error:
            return holder.createErrorAnnotation(textRange, diagnostic.getMessage());
        case Warning:
            return holder.createWarningAnnotation(textRange, diagnostic.getMessage());
        case Information:
            return holder.createInfoAnnotation(textRange, diagnostic.getMessage());
        default:
            return holder.createWeakWarningAnnotation(textRange, diagnostic.getMessage());
    }
}
 
Example 2
Source File: N4jscLanguageClient.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
	List<Diagnostic> issueList = diagnostics.getDiagnostics();
	if (issueList.isEmpty()) {
		return;
	}

	synchronized (this) {
		N4jscConsole.println(issueSerializer.uri(diagnostics.getUri()));
		for (Diagnostic diag : issueList) {
			N4jscConsole.println(issueSerializer.diagnostics(diag));
			switch (diag.getSeverity()) {
			case Error:
				errCount++;
				break;
			case Warning:
				wrnCount++;
				break;
			default:
				break;
			}
		}
	}
}
 
Example 3
Source File: N4jscTestLanguageClient.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
	super.publishDiagnostics(diagnostics);

	String uriString = issueSerializer.uri(diagnostics.getUri());

	issues.removeAll(uriString);
	errors.removeAll(uriString);
	warnings.removeAll(uriString);

	List<Diagnostic> issueList = diagnostics.getDiagnostics();
	if (issueList.isEmpty()) {
		return;
	}

	for (Diagnostic diag : issueList) {
		String issueString = issueSerializer.diagnostics(diag);
		issues.put(uriString, diag);

		switch (diag.getSeverity()) {
		case Error:
			errors.put(uriString, issueString);
			break;
		case Warning:
			warnings.put(uriString, issueString);
			break;
		default:
			// ignore
			break;
		}
	}
}
 
Example 4
Source File: IdeTestLanguageClient.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
	URI uriRaw = URI.createURI(diagnostics.getUri());
	if (N4Scheme.isN4Scheme(uriRaw)) {
		return;
	}
	if (!uriRaw.isFile()) {
		throw new IllegalArgumentException("not a file URI: " + uriRaw);
	}

	FileURI uri = new FileURI(uriRaw);

	issues.removeAll(uri);
	errors.removeAll(uri);
	warnings.removeAll(uri);

	List<Diagnostic> issueList = diagnostics.getDiagnostics();
	if (issueList.isEmpty()) {
		return;
	}

	for (Diagnostic diag : issueList) {
		String issueString = getIssueString(diag);
		issues.put(uri, diag);

		switch (diag.getSeverity()) {
		case Error:
			errors.put(uri, issueString);
			break;
		case Warning:
			warnings.put(uri, issueString);
			break;
		default:
			// ignore
			break;
		}
	}
}
 
Example 5
Source File: CodeActionHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static IProblemLocationCore[] getProblemLocationCores(ICompilationUnit unit, List<Diagnostic> diagnostics) {
	IProblemLocationCore[] locations = new IProblemLocationCore[diagnostics.size()];
	for (int i = 0; i < diagnostics.size(); i++) {
		Diagnostic diagnostic = diagnostics.get(i);
		int problemId = getProblemId(diagnostic);
		int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange());
		int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange());
		boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error;
		locations[i] = new ProblemLocationCore(start, end - start, problemId, new String[0], isError, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
	}
	return locations;
}