GlobalSearchScope (@NotNull VirtualFile file, @NotNull Project project) { FileType fileType = file.getFileType(); if (!(fileType instanceof LanguageFileType) || ((LanguageFileType)fileType).getLanguage() != GroovyLanguage.INSTANCE) { return null; } ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); Module module = projectFileIndex.getModuleForFile(file); if (module == null) return null; //groovy files are only in modules boolean includeTests = projectFileIndex.isInTestSourceContent(file) || !projectFileIndex.isInSourceContent(file); final GlobalSearchScope scope; if (projectFileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.RESOURCES)) { scope = GlobalSearchScope.moduleRuntimeScope(module, includeTests); } else { scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests); } final PsiFile psi = PsiManager.getInstance(project).findFile(file); if (psi instanceof GroovyFile && ((GroovyFile)psi).isScript()) { return GroovyScriptTypeDetector.patchResolveScope((GroovyFile)psi, scope); } else { return scope; } }