Skip to content

Commit 39a946b

Browse files
Allow cancel the resolveMainMethod command (#350)
1 parent 885ad79 commit 39a946b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
7070
case VALIDATE_LAUNCHCONFIG:
7171
return new ResolveMainClassHandler().validateLaunchConfig(arguments);
7272
case RESOLVE_MAINMETHOD:
73-
return ResolveMainMethodHandler.resolveMainMethods(arguments);
73+
return ResolveMainMethodHandler.resolveMainMethods(arguments, progress);
7474
case INFER_LAUNCH_COMMAND_LENGTH:
7575
return LaunchCommandHandler.getLaunchCommandLength(JsonUtils.fromJson((String) arguments.get(0), LaunchArguments.class));
7676
case CHECK_PROJECT_SETTINGS:

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Microsoft Corporation and others.
2+
* Copyright (c) 2018-2020 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -18,7 +18,7 @@
1818

1919
import org.eclipse.core.resources.IProject;
2020
import org.eclipse.core.resources.IResource;
21-
import org.eclipse.core.runtime.NullProgressMonitor;
21+
import org.eclipse.core.runtime.IProgressMonitor;
2222
import org.eclipse.core.runtime.OperationCanceledException;
2323
import org.eclipse.core.runtime.jobs.Job;
2424
import org.eclipse.jdt.core.Flags;
@@ -42,25 +42,29 @@ public class ResolveMainMethodHandler {
4242
* Resolve the main methods from the current file.
4343
* @return an array of main methods.
4444
*/
45-
public static Object resolveMainMethods(List<Object> arguments) throws DebugException {
46-
if (arguments == null || arguments.isEmpty()) {
45+
public static Object resolveMainMethods(List<Object> arguments, IProgressMonitor monitor) throws DebugException {
46+
if (monitor.isCanceled() || arguments == null || arguments.isEmpty()) {
4747
return Collections.emptyList();
4848
}
4949

5050
// When the current document is changed, the language server will receive a didChange request about the changed text and then
5151
// trigger a background job to update the change to the CompilationUnit. Because of race condition, the resolveMainMethods may read
5252
// an old CompilationUnit. So add some waiting logic to wait the Document Update to finish first.
5353
try {
54-
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
55-
} catch (OperationCanceledException ignorable) {
56-
// Do nothing.
54+
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
55+
} catch (OperationCanceledException e) {
56+
return Collections.emptyList();
5757
} catch (InterruptedException e) {
5858
// Do nothing.
5959
}
6060

61+
if (monitor.isCanceled()) {
62+
return Collections.emptyList();
63+
}
64+
6165
String uri = (String) arguments.get(0);
6266
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
63-
if (unit == null || unit.getResource() == null || !unit.getResource().exists()) {
67+
if (monitor.isCanceled() || unit == null || unit.getResource() == null || !unit.getResource().exists()) {
6468
return Collections.emptyList();
6569
}
6670

0 commit comments

Comments
 (0)