create completion thread outside CompletionProgressIndicator main invocation
[idea/community.git] / platform / lang-impl / src / com / intellij / codeInsight / completion / CodeCompletionHandlerBase.java
index d3284f93559c6aef34390fbbe9e1562cd97fb37f..238b7766646dc61b43e6e151184936e8afeaf426 100644 (file)
@@ -297,16 +297,19 @@ public class CodeCompletionHandlerBase {
       CompletionServiceImpl.assertPhase(CompletionPhase.NoCompletion.getClass());
     }
 
+    CompletionThreadingBase threading = ApplicationManager.getApplication().isWriteAccessAllowed() ? new SyncCompletion() : new AsyncCompletion();
     CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, initContext.getCaret(),
                                                                             invocationCount, this,
-                                                                            initContext.getOffsetMap(), hostOffsets, hasModifiers, lookup);
+                                                                            initContext.getOffsetMap(), hostOffsets, hasModifiers, lookup,
+                                                                            threading);
     Disposer.register(indicator, hostCopyOffsets.getOffsets());
     Disposer.register(indicator, finalOffsets.getOffsets());
     Disposer.register(indicator, translator);
 
     CompletionServiceImpl.setCompletionPhase(synchronous ? new CompletionPhase.Synchronous(indicator) : new CompletionPhase.BgCalculation(indicator));
-
-    indicator.startCompletion(initContext, finalOffsets);
+    
+    threading.startThread(indicator, () -> AsyncCompletion.tryReadOrCancel(indicator, () -> 
+      indicator.runContributors(initContext, finalOffsets)));
 
     if (!synchronous) {
       return;