skip word selectioners that require indices in dumb mode (EA-91632 - INRE: FileBasedI...
authorpeter <peter@jetbrains.com>
Wed, 16 Nov 2016 16:43:11 +0000 (17:43 +0100)
committerpeter <peter@jetbrains.com>
Wed, 16 Nov 2016 17:18:28 +0000 (18:18 +0100)
platform/lang-impl/src/com/intellij/codeInsight/editorActions/SelectWordUtil.java

index 7c3f5738a74b5a6a23700c8788bdf593932095b5..9026286d2778f84a1c6119174190f0b7fa8682ef 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.actions.EditorActionUtil;
 import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.project.DumbService;
+import com.intellij.openapi.project.IndexNotReadyException;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.FileViewProvider;
 import com.intellij.psi.PsiElement;
@@ -259,10 +260,7 @@ public class SelectWordUtil {
     }
     long stamp = editor.getDocument().getModificationStamp();
     for (ExtendWordSelectionHandler selectioner : availableSelectioners) {
-      List<TextRange> ranges = selectioner.select(element, text, cursorOffset, editor);
-      if (stamp != editor.getDocument().getModificationStamp()) {
-        throw new AssertionError("Selectioner " + selectioner + " has changed the document");
-      }
+      List<TextRange> ranges = askSelectioner(element, text, cursorOffset, editor, stamp, selectioner);
       if (ranges == null) continue;
 
       for (TextRange range : ranges) {
@@ -275,6 +273,25 @@ public class SelectWordUtil {
     return stop;
   }
 
+  @Nullable
+  private static List<TextRange> askSelectioner(@NotNull PsiElement element,
+                                                CharSequence text,
+                                                int cursorOffset,
+                                                Editor editor,
+                                                long stamp,
+                                                ExtendWordSelectionHandler selectioner) {
+    try {
+      List<TextRange> ranges = selectioner.select(element, text, cursorOffset, editor);
+      if (stamp != editor.getDocument().getModificationStamp()) {
+        throw new AssertionError("Selectioner " + selectioner + " has changed the document");
+      }
+      return ranges;
+    }
+    catch (IndexNotReadyException e) {
+      return null;
+    }
+  }
+
   public static void addWordHonoringEscapeSequences(CharSequence editorText,
                                                     TextRange literalTextRange,
                                                     int cursorOffset,