Skip to content

Commit fae3184

Browse files
authored
Diagnostics from changes to build configuration not reflected in open source files (#1964)
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
1 parent d885ff3 commit fae3184

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public IStatus run(IProgressMonitor monitor) {
301301
JobHelpers.waitForBuildJobs(60 * 60 * 1000); // 1 hour
302302
logInfo(">> build jobs finished");
303303
client.sendStatus(ServiceStatus.ServiceReady, "ServiceReady");
304-
workspaceDiagnosticsHandler = new WorkspaceDiagnosticsHandler(JDTLanguageServer.this.client, pm, preferenceManager.getClientPreferences());
304+
workspaceDiagnosticsHandler = new WorkspaceDiagnosticsHandler(JDTLanguageServer.this.client, pm, preferenceManager.getClientPreferences(), documentLifeCycleHandler);
305305
workspaceDiagnosticsHandler.publishDiagnostics(monitor);
306306
workspaceDiagnosticsHandler.addResourceChangeListener();
307307
classpathUpdateHandler = new ClasspathUpdateHandler(JDTLanguageServer.this.client);

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceDiagnosticsHandler.java

+8
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,22 @@ public final class WorkspaceDiagnosticsHandler implements IResourceChangeListene
7070
private final JavaClientConnection connection;
7171
private final ProjectsManager projectsManager;
7272
private final boolean isDiagnosticTagSupported;
73+
private final DocumentLifeCycleHandler handler;
7374

7475
@Deprecated
7576
public WorkspaceDiagnosticsHandler(JavaClientConnection connection, ProjectsManager projectsManager) {
7677
this(connection, projectsManager, null);
7778
}
7879

7980
public WorkspaceDiagnosticsHandler(JavaClientConnection connection, ProjectsManager projectsManager, ClientPreferences prefs) {
81+
this(connection, projectsManager, prefs, null);
82+
}
83+
84+
public WorkspaceDiagnosticsHandler(JavaClientConnection connection, ProjectsManager projectsManager, ClientPreferences prefs, DocumentLifeCycleHandler handler) {
8085
this.connection = connection;
8186
this.projectsManager = projectsManager;
8287
this.isDiagnosticTagSupported = prefs != null ? prefs.isDiagnosticTagSupported() : false;
88+
this.handler = handler;
8389
}
8490

8591
public void addResourceChangeListener() {
@@ -170,6 +176,8 @@ public boolean visit(IResourceDelta delta) throws CoreException {
170176
markers = Arrays.copyOf(javaMarkers, javaMarkers.length + taskMarkers.length);
171177
System.arraycopy(taskMarkers, 0, markers, javaMarkers.length, taskMarkers.length);
172178
document = JsonRpcHelpers.toDocument(cu.getBuffer());
179+
} else if (handler != null) {
180+
handler.triggerValidation(cu);
173181
}
174182
} // or a build file
175183
else if (projectsManager.isBuildFile(file)) {

org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceDiagnosticsHandlerTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,38 @@ public void testWorkingCopy() throws Exception {
335335
}
336336
}
337337

338+
// https://github.com/eclipse/eclipse.jdt.ls/issues/1963
339+
@Test
340+
public void testWorkingCopy2() throws Exception {
341+
ICompilationUnit cu = null;
342+
try {
343+
DocumentLifeCycleHandler lifeCycleHandler = new DocumentLifeCycleHandler(connection, preferenceManager, projectsManager, false);
344+
handler.removeResourceChangeListener();
345+
handler = new WorkspaceDiagnosticsHandler(connection, projectsManager, preferenceManager.getClientPreferences(), lifeCycleHandler);
346+
handler.addResourceChangeListener();
347+
//import project
348+
importProjects("eclipse/hello");
349+
IProject project = getProject("hello");
350+
IFile iFile = project.getFile("/src/test1/A.java");
351+
352+
cu = JavaCore.createCompilationUnitFrom(iFile);
353+
cu.becomeWorkingCopy(null);
354+
reset(connection);
355+
ResourceUtils.setContent(iFile, "package test1;\npublic class A() {}\n");
356+
waitForBackgroundJobs();
357+
ArgumentCaptor<PublishDiagnosticsParams> captor = ArgumentCaptor.forClass(PublishDiagnosticsParams.class);
358+
verify(connection, atMost(3)).publishDiagnostics(captor.capture());
359+
} finally {
360+
if (cu != null) {
361+
cu.discardWorkingCopy();
362+
}
363+
handler.removeResourceChangeListener();
364+
handler = new WorkspaceDiagnosticsHandler(connection, projectsManager, preferenceManager.getClientPreferences());
365+
handler.addResourceChangeListener();
366+
connection.disconnect();
367+
}
368+
}
369+
338370
// https://github.com/eclipse/eclipse.jdt.ls/issues/1920
339371
@Test
340372
public void testWithoutWorkingCopy() throws Exception {

0 commit comments

Comments
 (0)