postpone isJsProject() check
#KT-9026 Fixed
This commit is contained in:
+5
-5
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.idea.stubindex;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||||
import com.intellij.openapi.roots.ProjectRootManager;
|
import com.intellij.openapi.roots.ProjectRootManager;
|
||||||
|
import com.intellij.openapi.util.Ref;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.JsProjectDetector;
|
|
||||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||||
|
|
||||||
public class KotlinSourceFilterScope extends DelegatingGlobalSearchScope {
|
public class KotlinSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||||
@@ -84,7 +84,9 @@ public class KotlinSourceFilterScope extends DelegatingGlobalSearchScope {
|
|||||||
private final boolean includeProjectSourceFiles;
|
private final boolean includeProjectSourceFiles;
|
||||||
private final boolean includeLibrarySourceFiles;
|
private final boolean includeLibrarySourceFiles;
|
||||||
private final boolean includeClassFiles;
|
private final boolean includeClassFiles;
|
||||||
private final boolean isJsProject;
|
|
||||||
|
//NOTE: avoid recomputing in potentially bottleneck 'contains' method
|
||||||
|
private final Ref<Boolean> isJsProjectRef = new Ref<Boolean>();
|
||||||
|
|
||||||
private KotlinSourceFilterScope(
|
private KotlinSourceFilterScope(
|
||||||
@NotNull GlobalSearchScope delegate,
|
@NotNull GlobalSearchScope delegate,
|
||||||
@@ -98,9 +100,7 @@ public class KotlinSourceFilterScope extends DelegatingGlobalSearchScope {
|
|||||||
this.includeProjectSourceFiles = includeProjectSourceFiles;
|
this.includeProjectSourceFiles = includeProjectSourceFiles;
|
||||||
this.includeLibrarySourceFiles = includeLibrarySourceFiles;
|
this.includeLibrarySourceFiles = includeLibrarySourceFiles;
|
||||||
this.includeClassFiles = includeClassFiles;
|
this.includeClassFiles = includeClassFiles;
|
||||||
//NOTE: avoid recomputing in potentially bottleneck 'contains' method
|
|
||||||
this.index = ProjectRootManager.getInstance(project).getFileIndex();
|
this.index = ProjectRootManager.getInstance(project).getFileIndex();
|
||||||
this.isJsProject = JsProjectDetector.isJsProject(project);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,7 +112,7 @@ public class KotlinSourceFilterScope extends DelegatingGlobalSearchScope {
|
|||||||
public boolean contains(@NotNull VirtualFile file) {
|
public boolean contains(@NotNull VirtualFile file) {
|
||||||
if (!super.contains(file)) return false;
|
if (!super.contains(file)) return false;
|
||||||
return ProjectRootsUtil.isInContent(
|
return ProjectRootsUtil.isInContent(
|
||||||
project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, index, isJsProject
|
project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, index, isJsProjectRef
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util
|
|||||||
import com.intellij.ide.highlighter.JavaClassFileType
|
import com.intellij.ide.highlighter.JavaClassFileType
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.roots.ProjectFileIndex
|
import com.intellij.openapi.roots.ProjectFileIndex
|
||||||
|
import com.intellij.openapi.util.Ref
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.psi.PsiDirectory
|
import com.intellij.psi.PsiDirectory
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -33,21 +34,30 @@ object ProjectRootsUtil {
|
|||||||
@JvmStatic fun isInContent(project: Project, file: VirtualFile, includeProjectSource: Boolean,
|
@JvmStatic fun isInContent(project: Project, file: VirtualFile, includeProjectSource: Boolean,
|
||||||
includeLibrarySource: Boolean, includeLibraryClasses: Boolean,
|
includeLibrarySource: Boolean, includeLibraryClasses: Boolean,
|
||||||
fileIndex: ProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(project),
|
fileIndex: ProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(project),
|
||||||
isJsProject: Boolean? = null): Boolean {
|
isJsProjectRef: Ref<Boolean?>? = null): Boolean {
|
||||||
if (includeProjectSource && fileIndex.isInSourceContent(file)) {
|
if (includeProjectSource && fileIndex.isInSourceContent(file)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if (!includeLibraryClasses && !includeLibrarySource) return false
|
|
||||||
|
|
||||||
//NOTE: avoid computing isJsProject if redundant
|
|
||||||
if (isJsProject ?: JsProjectDetector.isJsProject(project)) {
|
|
||||||
return (includeLibrarySource && fileIndex.isInLibrarySource(file))
|
|
||||||
|| (includeLibraryClasses && fileIndex.isLibraryClassFile(file))
|
|
||||||
}
|
|
||||||
// NOTE: the following is a workaround for cases when class files are under library source roots and source files are under class roots
|
// NOTE: the following is a workaround for cases when class files are under library source roots and source files are under class roots
|
||||||
val isClassFile = file.fileType in classFileLike
|
val isClassFile = file.fileType in classFileLike
|
||||||
return (includeLibraryClasses && isClassFile && fileIndex.isInLibraryClasses(file))
|
|
||||||
|| (includeLibrarySource && !isClassFile && fileIndex.isInLibrarySource(file))
|
if ((includeLibraryClasses && isClassFile && fileIndex.isInLibraryClasses(file)) ||
|
||||||
|
(includeLibrarySource && !isClassFile && fileIndex.isInLibrarySource(file))) {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((includeLibraryClasses && fileIndex.isInLibraryClasses(file)) ||
|
||||||
|
(includeLibrarySource && fileIndex.isInLibrarySource(file))) {
|
||||||
|
|
||||||
|
//NOTE: avoid computing isJsProject if redundant
|
||||||
|
val isJsProject = isJsProjectRef?.get() ?: JsProjectDetector.isJsProject(project)
|
||||||
|
isJsProjectRef?.set(isJsProject)
|
||||||
|
return isJsProject
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic fun isInContent(
|
@JvmStatic fun isInContent(
|
||||||
|
|||||||
Reference in New Issue
Block a user