Introduce Scratches named scope (GO-4763)

- it's required to deserialize "Scratches and Consoles" scope
This commit is contained in:
Alexander Zolotov
2017-10-26 17:05:37 +03:00
parent edd0d7625e
commit 691e5a114f
4 changed files with 36 additions and 3 deletions
@@ -315,7 +315,7 @@ public class ScratchFileServiceImpl extends ScratchFileService implements Persis
@NotNull
@Override
public String getDisplayName() {
return "Scratches and Consoles";
return ScratchesAndConsolesNamedScope.NAME;
}
@Override
@@ -0,0 +1,29 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.scratch;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.scope.packageSet.AbstractPackageSet;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ScratchesAndConsolesNamedScope extends NamedScope {
public static final String NAME = "Scratches and Consoles";
public ScratchesAndConsolesNamedScope() {
super(NAME, new AbstractPackageSet(NAME) {
@Override
public boolean contains(VirtualFile file, NamedScopesHolder holder) {
return contains(file, holder.getProject(), holder);
}
@Override
public boolean contains(VirtualFile file, @NotNull Project project, @Nullable NamedScopesHolder holder) {
RootType rootType = ScratchUtil.isScratch(file) ? ScratchFileService.getInstance().getRootType(file) : null;
return rootType != null && !rootType.isHidden();
}
});
}
}
@@ -16,6 +16,7 @@
package com.intellij.ide.util.scopeChooser;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.scratch.ScratchesAndConsolesNamedScope;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
@@ -62,7 +63,9 @@ public class ScopeChooserUtils {
namedScope = new ProjectFilesScope();
}
GlobalSearchScope scope = GlobalSearchScopesCore.filterScope(project, namedScope);
if (namedScope instanceof ProjectFilesScope || namedScope instanceof ProjectProductionScope) {
if (namedScope instanceof ProjectFilesScope ||
namedScope instanceof ProjectProductionScope ||
namedScope instanceof ScratchesAndConsolesNamedScope) {
return scope;
}
return intersectWithContentScope(project, scope);
@@ -15,6 +15,7 @@
*/
package com.intellij.packageDependencies;
import com.intellij.ide.scratch.ScratchesAndConsolesNamedScope;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.scope.NonProjectFilesScope;
@@ -47,7 +48,7 @@ public class DefaultScopesProvider extends CustomScopesProviderEx {
NamedScope projectScope = new ProjectFilesScope();
NamedScope nonProjectScope = new NonProjectFilesScope();
myProblemsScope = new ProblemScope(project);
myScopes = Arrays.asList(projectScope, getProblemsScope(), getAllScope(), nonProjectScope);
myScopes = Arrays.asList(projectScope, getProblemsScope(), getAllScope(), nonProjectScope, new ScratchesAndConsolesNamedScope());
}
@Override