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
1818
1919import org .eclipse .core .resources .IProject ;
2020import org .eclipse .core .resources .IResource ;
21- import org .eclipse .core .runtime .NullProgressMonitor ;
21+ import org .eclipse .core .runtime .IProgressMonitor ;
2222import org .eclipse .core .runtime .OperationCanceledException ;
2323import org .eclipse .core .runtime .jobs .Job ;
2424import 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