Skip to content

Commit cb9c6b7

Browse files
Fix codeLens for Run/Debug links showing up with latency (#230)
Signed-off-by: Jinbo Wang <[email protected]>
1 parent 6f990d0 commit cb9c6b7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.eclipse.core.resources.IProject;
2020
import org.eclipse.core.resources.IResource;
21+
import org.eclipse.core.runtime.NullProgressMonitor;
22+
import org.eclipse.core.runtime.OperationCanceledException;
23+
import org.eclipse.core.runtime.jobs.Job;
2124
import org.eclipse.jdt.core.Flags;
2225
import org.eclipse.jdt.core.ICompilationUnit;
2326
import org.eclipse.jdt.core.IJavaElement;
@@ -28,6 +31,7 @@
2831
import org.eclipse.jdt.core.IType;
2932
import org.eclipse.jdt.core.JavaModelException;
3033
import org.eclipse.jdt.ls.core.internal.JDTUtils;
34+
import org.eclipse.jdt.ls.core.internal.handlers.DocumentLifeCycleHandler;
3135
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
3236
import org.eclipse.lsp4j.Range;
3337

@@ -43,6 +47,17 @@ public static Object resolveMainMethods(List<Object> arguments) throws DebugExce
4347
return Collections.emptyList();
4448
}
4549

50+
// When the current document is changed, the language server will receive a didChange request about the changed text and then
51+
// trigger a background job to update the change to the CompilationUnit. Because of race condition, the resolveMainMethods may read
52+
// an old CompilationUnit. So add some waiting logic to wait the Document Update to finish first.
53+
try {
54+
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
55+
} catch (OperationCanceledException ignorable) {
56+
// Do nothing.
57+
} catch (InterruptedException e) {
58+
// Do nothing.
59+
}
60+
4661
String uri = (String) arguments.get(0);
4762
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
4863
if (unit == null || unit.getResource() == null || !unit.getResource().exists()) {

0 commit comments

Comments
 (0)