mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-25679 NodeModulesDirectoryManager - Recursion prevented when computing FileIndex extension
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
package com.intellij.openapi.project;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,6 +30,8 @@ import java.util.Collection;
|
||||
|
||||
public abstract class ProjectLocator {
|
||||
|
||||
static final Key<Project> PREFERRED_PROJECT_KEY = Key.create("PREFERRED_PROJECT_KEY");
|
||||
|
||||
public static ProjectLocator getInstance() {
|
||||
return ServiceManager.getService(ProjectLocator.class);
|
||||
}
|
||||
@@ -50,4 +54,16 @@ public abstract class ProjectLocator {
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Collection<Project> getProjectsForFile(VirtualFile file);
|
||||
|
||||
public static <T, E extends Throwable> T computeWithPreferredProject(@NotNull VirtualFile file,
|
||||
@NotNull Project preferredProject,
|
||||
@NotNull ThrowableComputable<T, E> action) throws E {
|
||||
file.putUserData(PREFERRED_PROJECT_KEY, preferredProject);
|
||||
try {
|
||||
return action.compute();
|
||||
}
|
||||
finally {
|
||||
file.putUserData(PREFERRED_PROJECT_KEY, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,10 @@ public class ProjectLocatorImpl extends ProjectLocator {
|
||||
if (projects.length == 1 && !projects[0].isDisposed()) return projects[0];
|
||||
|
||||
if (file != null) {
|
||||
Project preferredProject = file.getUserData(PREFERRED_PROJECT_KEY);
|
||||
if (preferredProject != null) {
|
||||
return preferredProject;
|
||||
}
|
||||
for (Project project : projects) {
|
||||
if (project.isInitialized() && !project.isDisposed() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) {
|
||||
return project;
|
||||
|
||||
Reference in New Issue
Block a user