use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.
the class DiagnosticsHandler method endReporting.
@Override
public void endReporting() {
JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/')));
PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(this.cu, problems));
this.connection.publishDiagnostics($);
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.
the class WorkspaceDiagnosticsHandler method visit.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.
* resources.IResourceDelta)
*/
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
// WorkspaceEventsHandler removes the diagnostics for deleted resources.
if (resource == null || !resource.isAccessible()) {
return false;
}
if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.ROOT) {
return true;
}
// ignore problems caused by standalone files
if (resource.getType() == IResource.PROJECT) {
return !JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject());
}
// No marker changes continue to visit
if ((delta.getFlags() & IResourceDelta.MARKERS) == 0) {
return false;
}
IFile file = (IFile) resource;
String uri = JDTUtils.getFileURI(resource);
IDocument document = null;
IMarker[] markers = null;
// Check if it is a Java ...
if (JavaCore.isJavaLikeFileName(file.getName())) {
markers = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
ICompilationUnit cu = (ICompilationUnit) JavaCore.create(file);
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} else // or a build file
if (projectsManager.isBuildFile(file)) {
// all errors on that build file should be relevant
markers = file.findMarkers(null, true, 1);
document = JsonRpcHelpers.toDocument(file);
}
if (document != null) {
this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(document, markers)));
}
return false;
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method testDidOpenStandaloneFile.
@Test
public void testDidOpenStandaloneFile() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent = "package java;\n" + "public class Foo extends UnknownType {" + " public void method1(){\n" + " super.whatever();" + " }\n" + "}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals(0, diagParam.getDiagnostics().size());
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method testDidOpenStandaloneFileWithNonSyntaxErrors.
@Test
public void testDidOpenStandaloneFileWithNonSyntaxErrors() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent = "package java;\n" + "public class Foo {\n" + " public static void notThis(){\n" + " System.out.println(this);\n" + " }\n" + " public void method1(){\n" + " }\n" + " public void method1(){\n" + " }\n" + "}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 3, diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Cannot use this in a static context", d.getMessage());
assertRange(3, 21, 25, d.getRange());
d = diagParam.getDiagnostics().get(1);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(5, 13, 22, d.getRange());
d = diagParam.getDiagnostics().get(2);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(7, 13, 22, d.getRange());
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method publishDiagnostics.
private void publishDiagnostics(List<org.ballerinalang.util.diagnostic.Diagnostic> balDiagnostics, Path path) {
Map<String, List<Diagnostic>> diagnosticsMap = new HashMap<>();
balDiagnostics.forEach(diagnostic -> {
Diagnostic d = new Diagnostic();
d.setSeverity(DiagnosticSeverity.Error);
d.setMessage(diagnostic.getMessage());
Range r = new Range();
// LSP diagnostics range is 0 based
int startLine = diagnostic.getPosition().getStartLine() - 1;
int startChar = diagnostic.getPosition().getStartColumn() - 1;
int endLine = diagnostic.getPosition().getEndLine() - 1;
int endChar = diagnostic.getPosition().getEndColumn() - 1;
if (endLine <= 0) {
endLine = startLine;
}
if (endChar <= 0) {
endChar = startChar + 1;
}
r.setStart(new Position(startLine, startChar));
r.setEnd(new Position(endLine, endChar));
d.setRange(r);
String fileName = diagnostic.getPosition().getSource().getCompilationUnitName();
Path filePath = Paths.get(path.getParent().toString(), fileName);
String fileURI = filePath.toUri().toString();
if (!diagnosticsMap.containsKey(fileURI)) {
diagnosticsMap.put(fileURI, new ArrayList<Diagnostic>());
}
List<Diagnostic> clientDiagnostics = diagnosticsMap.get(fileURI);
clientDiagnostics.add(d);
});
// clear previous diagnostics
List<Diagnostic> empty = new ArrayList<Diagnostic>(0);
for (Map.Entry<String, List<Diagnostic>> entry : lastDiagnosticMap.entrySet()) {
if (diagnosticsMap.containsKey(entry.getKey())) {
continue;
}
PublishDiagnosticsParams diagnostics = new PublishDiagnosticsParams();
diagnostics.setUri(entry.getKey());
diagnostics.setDiagnostics(empty);
this.ballerinaLanguageServer.getClient().publishDiagnostics(diagnostics);
}
for (Map.Entry<String, List<Diagnostic>> entry : diagnosticsMap.entrySet()) {
PublishDiagnosticsParams diagnostics = new PublishDiagnosticsParams();
diagnostics.setUri(entry.getKey());
diagnostics.setDiagnostics(entry.getValue());
this.ballerinaLanguageServer.getClient().publishDiagnostics(diagnostics);
}
lastDiagnosticMap = diagnosticsMap;
}
Aggregations