Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Avoid using ModuleUtilCore#findModuleForFile which can block IJ since 2023.3 Beta2 #1273

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
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;
import com.intellij.openapi.roots.OrderEnumerator;
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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading