diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java index 54993d888..75aee7ace 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java @@ -56,18 +56,11 @@ public void projectClosing(@NotNull Project project) { @Override public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { Project project = source.getProject(); - boolean readAccessAllowed = ApplicationManager.getApplication().isReadAccessAllowed(); - boolean dumb = DumbService.isDumb(project); - // As document matcher requires read action, we try to open the file in read action and when indexing is finishsed. - if (readAccessAllowed && !dumb) { - // No indexing and read action enabled - // --> force the start of all languages servers mapped with the given file immediately - connectToLanguageServer(file, project); - } else { - // Wait for indexing is finished and read action is enabled - // --> force the start of all languages servers mapped with the given file when indexing is finished and read action is allowed - new ConnectToLanguageServerCompletableFuture(file, project); - } + // As document matcher requires read action, and language server starts can take some times, we connect the file in a future + // to avoid starting language server in the EDT Thread which could freeze IJ. + // Wait for indexing is finished and read action is enabled + // --> force the start of all languages servers mapped with the given file when indexing is finished and read action is allowed + new ConnectToLanguageServerCompletableFuture(file, project); } private static void connectToLanguageServer(@NotNull VirtualFile file, @NotNull Project project) { diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java index 348ef62ce..cf7b70f5f 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusModuleUtil.java @@ -13,7 +13,6 @@ import com.intellij.facet.FacetManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModuleRootManager; @@ -21,6 +20,7 @@ import com.intellij.openapi.roots.RootPolicy; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; import com.redhat.devtools.intellij.quarkus.facet.QuarkusFacet; import org.jetbrains.annotations.NotNull; @@ -144,7 +144,7 @@ public static boolean isQuarkusYAMLFile(VirtualFile file, Project project) { } private static boolean isQuarkusModule(VirtualFile file, Project project) { - Module module = ModuleUtilCore.findModuleForFile(file, project); + Module module = LSPIJUtils.getModule(file, project); return module != null && (FacetManager.getInstance(module).getFacetByType(QuarkusFacet.FACET_TYPE_ID) != null || QuarkusModuleUtil.isQuarkusModule(module)); } diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/json/QuarkusJsonSchemaProvider.java b/src/main/java/com/redhat/devtools/intellij/quarkus/json/QuarkusJsonSchemaProvider.java index 62eebc5c8..6b919f102 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/json/QuarkusJsonSchemaProvider.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/json/QuarkusJsonSchemaProvider.java @@ -11,10 +11,10 @@ package com.redhat.devtools.intellij.quarkus.json; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider; import com.jetbrains.jsonSchema.extension.SchemaType; +import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; import com.redhat.devtools.intellij.quarkus.QuarkusProjectService; import org.jetbrains.annotations.NotNull; @@ -29,7 +29,7 @@ public QuarkusJsonSchemaProvider(Module module) { @Override public boolean isAvailable(@NotNull VirtualFile file) { - return isApplicationYAMLFile(file) && module.equals(ModuleUtilCore.findModuleForFile(file, module.getProject())); + return isApplicationYAMLFile(file) && module.equals(LSPIJUtils.getModule(file, module.getProject())); } private boolean isApplicationYAMLFile(VirtualFile file) { diff --git a/src/main/java/com/redhat/devtools/intellij/qute/lang/QuteLanguageSubstitutor.java b/src/main/java/com/redhat/devtools/intellij/qute/lang/QuteLanguageSubstitutor.java index ed4bb119f..e8f3f0f94 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/lang/QuteLanguageSubstitutor.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/lang/QuteLanguageSubstitutor.java @@ -22,6 +22,7 @@ import com.intellij.openapi.roots.RootPolicy; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.LanguageSubstitutor; +import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -70,7 +71,7 @@ private Module findModule(VirtualFile file) { @Override public @Nullable Language getLanguage(@NotNull VirtualFile file, @NotNull Project project) { - Module module = ModuleUtilCore.findModuleForFile(file, project); + Module module = LSPIJUtils.getModule(file, project); if (module != null) { if (isTemplate(file, module) && isQuteModule(module)) { return QuteLanguage.INSTANCE;