TextRange (@NotNull SearchScope searchScope, @NotNull PsiFile file) { if (searchScope instanceof LocalSearchScope) { List<PsiElement> scopeFileElements = ContainerUtil.filter(((LocalSearchScope)searchScope).getScope(), e -> e.getContainingFile() == file); if (!scopeFileElements.isEmpty()) { int start = -1; int end = -1; for (PsiElement scopeElement : scopeFileElements) { TextRange elementRange = scopeElement.getTextRange(); start = start == -1 ? elementRange.getStartOffset() : Math.min(elementRange.getStartOffset(), start); end = end == -1 ? elementRange.getEndOffset() : Math.max(elementRange.getEndOffset(), end); } return new TextRange(start, end); } } return new TextRange(0, file.getTextLength()); }