From 277d47ecfb8154924cf74a09afd26b0fcb1fe190 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 Jan 2019 00:55:22 +0300 Subject: [PATCH] guess project even if the file is in excluded directory, to make EncodingManager work for these files --- .../openapi/project/ProjectLocatorImpl.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/platform/projectModel-impl/src/com/intellij/openapi/project/ProjectLocatorImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/project/ProjectLocatorImpl.java index 491a0038f374..8e80e4497649 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/project/ProjectLocatorImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/project/ProjectLocatorImpl.java @@ -20,6 +20,7 @@ package com.intellij.openapi.project; import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SmartList; @@ -31,7 +32,6 @@ import java.util.Collections; import java.util.List; public class ProjectLocatorImpl extends ProjectLocator { - @Override @Nullable public Project guessProjectForFile(@Nullable VirtualFile file) { @@ -47,16 +47,21 @@ public class ProjectLocatorImpl extends ProjectLocator { if (projectManager == null) return null; final Project[] openProjects = projectManager.getOpenProjects(); for (Project openProject : openProjects) { - if (openProject.isInitialized() && - !openProject.isDisposed() && - ProjectRootManager.getInstance(openProject).getFileIndex().isInContent(file)) { - return openProject; - } + if (isUnder(openProject, file)) return openProject; } return null; }); } + // true if the file is either is in the project content or in some excluded folder of the project + private static boolean isUnder(@NotNull Project project, @NotNull VirtualFile file) { + if (!project.isInitialized() || project.isDisposed()) { + return false; + } + ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + return fileIndex.isInContent(file) || fileIndex.isExcluded(file); + } + @Override @NotNull public Collection getProjectsForFile(VirtualFile file) { @@ -71,7 +76,7 @@ public class ProjectLocatorImpl extends ProjectLocator { List result = new SmartList<>(); for (Project project : openProjects) { - if (project.isInitialized() && !project.isDisposed() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) { + if (isUnder(project, file)) { result.add(project); } }