Java Code Examples for org.eclipse.lsp4j.PublishDiagnosticsParams#getDiagnostics()

The following examples show how to use org.eclipse.lsp4j.PublishDiagnosticsParams#getDiagnostics() . 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: 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 2
Source File: DocumentLifeCycleHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testReconcile() throws Exception {
	IJavaProject javaProject = newEmptyProject();
	IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
	StringBuilder buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("public class E123 {\n");
	buf.append("    public void testing() {\n");
	buf.append("        int someIntegerChanged = 5;\n");
	buf.append("        int i = someInteger + 5\n");
	buf.append("    }\n");
	buf.append("}\n");
	ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null);
	openDocument(cu1, cu1.getSource(), 1);
	assertEquals(true, cu1.isWorkingCopy());
	assertEquals(false, cu1.hasUnsavedChanges());
	List<PublishDiagnosticsParams> diagnosticsParams = getClientRequests("publishDiagnostics");
	assertEquals(1, diagnosticsParams.size());
	PublishDiagnosticsParams diagnosticsParam = diagnosticsParams.get(0);
	List<Diagnostic> diagnostics = diagnosticsParam.getDiagnostics();
	assertEquals(2, diagnostics.size());
	diagnosticsParams.clear();
	closeDocument(cu1);
}
 
Example 3
Source File: DocumentLifeCycleHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void publishDiagnostics(PublishDiagnosticsParams publishDiagnosticsParams) {
    String uri = FileUtils.sanitizeURI(publishDiagnosticsParams.getUri());
    List<Diagnostic> diagnostics = publishDiagnosticsParams.getDiagnostics();
    EditorEventManager manager = EditorEventManagerBase.forUri(uri);
    if (manager != null) {
        manager.diagnostics(diagnostics);
    }
}
 
Example 5
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 6
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 7
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
private void addCompilerProblem(ICompilerProblem problem, PublishDiagnosticsParams publish, boolean isConfigFile)
{
    if (!compilerProblemFilter.isAllowed(problem))
    {
        return;
    }
    Diagnostic diagnostic = LanguageServerCompilerUtils.getDiagnosticFromCompilerProblem(problem);
    if(isConfigFile)
    {
        //clear the range because it isn't relevant
        diagnostic.setRange(new Range(new Position(0, 0), new Position(0, 0)));
    }
    List<Diagnostic> diagnostics = publish.getDiagnostics();
    diagnostics.add(diagnostic);
}