Skip to content

Commit 54448a0

Browse files
committed
Ensure that the schemas tree view handles indexing updates aka "entering/leaving Dumb mode" (#164)
1 parent 492958d commit 54448a0

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLConfigSchemaNode.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaWithErrors;
2121
import com.intellij.lang.jsgraphql.schema.GraphQLTypeDefinitionRegistryServiceImpl;
2222
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
23+
import com.intellij.openapi.project.IndexNotReadyException;
2324
import com.intellij.openapi.project.Project;
2425
import com.intellij.openapi.vfs.VirtualFile;
2526
import com.intellij.ui.SimpleTextAttributes;
@@ -159,9 +160,13 @@ public GraphQLConfigProjectsNode(GraphQLConfigSchemaNode parent) {
159160
@Override
160161
public SimpleNode[] getChildren() {
161162
if (parent.projectsConfigData != null) {
162-
return parent.projectsConfigData.values().stream().map(config -> {
163-
return new GraphQLConfigSchemaNode(myProject, parent.configManager, config, parent.configBaseDir);
164-
}).toArray(SimpleNode[]::new);
163+
try {
164+
return parent.projectsConfigData.values().stream().map(config -> {
165+
return new GraphQLConfigSchemaNode(myProject, parent.configManager, config, parent.configBaseDir);
166+
}).toArray(SimpleNode[]::new);
167+
} catch (IndexNotReadyException ignored) {
168+
// entered "dumb" mode, so just return no children as the tree view will be rebuilt as empty shortly (GraphQLSchemasRootNode)
169+
}
165170
}
166171
return SimpleNode.NO_CHILDREN;
167172
}

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemasPanel.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.intellij.openapi.fileEditor.FileEditorManager;
1818
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
1919
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
20+
import com.intellij.openapi.project.DumbService;
2021
import com.intellij.openapi.project.DumbServiceImpl;
2122
import com.intellij.openapi.project.Project;
2223
import com.intellij.openapi.util.Condition;
@@ -103,6 +104,19 @@ public boolean isPathSelected(TreePath treePath) {
103104
// Need indexing to be ready to build schema status
104105
DumbServiceImpl.getInstance(myProject).smartInvokeLater(myBuilder::initRootNode);
105106

107+
// update tree in response to indexing changes
108+
connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
109+
@Override
110+
public void enteredDumbMode() {
111+
myBuilder.updateFromRoot(true);
112+
}
113+
114+
@Override
115+
public void exitDumbMode() {
116+
myBuilder.updateFromRoot(true);
117+
}
118+
});
119+
106120
final JBScrollPane scrollPane = new JBScrollPane(myTree);
107121
scrollPane.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT));
108122

src/main/com/intellij/lang/jsgraphql/ide/project/schemastatus/GraphQLSchemasRootNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.ide.util.treeView.PresentableNodeDescriptor;
1212
import com.intellij.lang.jsgraphql.ide.project.graphqlconfig.GraphQLConfigManager;
1313
import com.intellij.lang.jsgraphql.ide.project.graphqlconfig.model.GraphQLConfigData;
14+
import com.intellij.openapi.project.DumbService;
1415
import com.intellij.openapi.project.IndexNotReadyException;
1516
import com.intellij.openapi.project.Project;
1617
import com.intellij.openapi.vfs.VirtualFile;
@@ -38,6 +39,10 @@ public GraphQLSchemasRootNode(Project project) {
3839
@Override
3940
public SimpleNode[] getChildren() {
4041
try {
42+
if (DumbService.getInstance(myProject).isDumb()) {
43+
// empty the tree view during indexing
44+
return SimpleNode.NO_CHILDREN;
45+
}
4146
final List<SimpleNode> children = Lists.newArrayList();
4247
for (Map.Entry<VirtualFile, GraphQLConfigData> entry : configManager.getConfigurationsByPath().entrySet()) {
4348
children.add(new GraphQLConfigSchemaNode(myProject, configManager, entry.getValue(), entry.getKey()));

0 commit comments

Comments
 (0)