(IJPL-61963) Switch SE scope from project files to all places automatically if only semantic results were found

To provide the requested behavior, I do not process semantic items in semantic contributors if the standard search had no results, and the current search scope is default and is automatically set by SE either on tab opening or typing.

GitOrigin-RevId: cd2bc34d1db6e1c866ea5f7798a2e40f68f7b1ce
This commit is contained in:
Evgeny Abramov
2024-05-17 03:06:06 +04:00
committed by intellij-monorepo-bot
parent 1bdc887fcc
commit 335f4a75d2
12 changed files with 39 additions and 2 deletions

View File

@@ -2810,6 +2810,7 @@ com.intellij.ide.actions.searcheverywhere.SearchEverywhereToggleAction
- a:canToggleEverywhere():Z
- a:isEverywhere():Z
- a:setEverywhere(Z):V
- setScopeIsDefaultAndAutoSet(Z):V
com.intellij.ide.actions.searcheverywhere.SearchFieldActionsContributor
- a:createRightActions(kotlin.jvm.functions.Function1,java.lang.Runnable):java.util.List
com.intellij.ide.actions.searcheverywhere.WeightedSearchEverywhereContributor

View File

@@ -5,4 +5,5 @@ public interface SearchEverywhereToggleAction {
boolean isEverywhere();
void setEverywhere(boolean everywhere);
boolean canToggleEverywhere();
default void setScopeIsDefaultAndAutoSet(boolean scopeDefaultAndAutoSet) {}
}

View File

@@ -14192,6 +14192,7 @@ a:com.intellij.ide.actions.searcheverywhere.AbstractGotoSEContributor
- com.intellij.ide.actions.searcheverywhere.ScopeSupporting
- com.intellij.ide.actions.searcheverywhere.SearchEverywhereExtendedInfoProvider
- com.intellij.ide.actions.searcheverywhere.WeightedSearchEverywhereContributor
- p:isScopeDefaultAndAutoSet:Z
- pf:myProject:com.intellij.openapi.project.Project
- pf:myPsiContext:com.intellij.psi.SmartPsiElementPointer
- p:myScopeDescriptor:com.intellij.ide.util.scopeChooser.ScopeDescriptor
@@ -14215,6 +14216,7 @@ a:com.intellij.ide.actions.searcheverywhere.AbstractGotoSEContributor
- getSearchProviderId():java.lang.String
- getSupportedScopes():java.util.List
- isDumbAware():Z
- p:isEverywhere():Z
- isMultiSelectionSupported():Z
- isShownInSeparateTab():Z
- p:preparePsi(com.intellij.psi.PsiElement,I,java.lang.String):com.intellij.psi.PsiElement
@@ -14244,10 +14246,12 @@ c:com.intellij.ide.actions.searcheverywhere.ActionSearchEverywhereContributor
- getSortWeight():I
- f:includeNonProjectItemsText():java.lang.String
- isEmptyPatternSupported():Z
- pf:isScopeDefaultAndAutoSet():Z
- isShownInSeparateTab():Z
- pf:processRecentActions(kotlinx.coroutines.CoroutineScope,kotlin.jvm.functions.Function2,java.lang.String,kotlin.jvm.functions.Function2):V
- processSelectedItem(com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue,I,java.lang.String):Z
- pf:setMyDisabledActions(Z):V
- pf:setScopeDefaultAndAutoSet(Z):V
- showInFindResults():Z
f:com.intellij.ide.actions.searcheverywhere.ActionSearchEverywhereContributor$Companion
- f:showAssignShortcutDialog(com.intellij.openapi.project.Project,com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue):V

View File

@@ -69,6 +69,7 @@ public abstract class AbstractGotoSEContributor implements WeightedSearchEverywh
private final GlobalSearchScope myEverywhereScope;
private final GlobalSearchScope myProjectScope;
protected boolean isScopeDefaultAndAutoSet = true;
protected final SmartPsiElementPointer<PsiElement> myPsiContext;
@@ -179,6 +180,11 @@ public abstract class AbstractGotoSEContributor implements WeightedSearchEverywh
return myScopeDescriptor.scopeEquals(myEverywhereScope) ||
myScopeDescriptor.scopeEquals(myProjectScope);
}
@Override
public void setScopeIsDefaultAndAutoSet(boolean scopeDefaultAndAutoSet) {
isScopeDefaultAndAutoSet = scopeDefaultAndAutoSet;
}
});
result.add(new PreviewAction());
result.add(new SearchEverywhereFiltersAction<>(filter, onChanged, statisticsCollector));
@@ -286,6 +292,8 @@ public abstract class AbstractGotoSEContributor implements WeightedSearchEverywh
setSelectedScope(scope);
}
protected boolean isEverywhere() { return myScopeDescriptor.scopeEquals(myEverywhereScope); }
@Override
public List<ScopeDescriptor> getSupportedScopes() {
return createScopes();

View File

@@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.impl.Utils.runUpdateSessionForActionSearch
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.serviceAsync
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.keymap.KeymapManager
@@ -53,6 +52,7 @@ open class ActionSearchEverywhereContributor : WeightedSearchEverywhereContribut
protected val model: GotoActionModel
private val myProvider: ActionAsyncProvider
protected var myDisabledActions: Boolean = false
protected var isScopeDefaultAndAutoSet: Boolean = true
private val isRecentEnabled: Boolean
get() = Registry.`is`("search.everywhere.recents") || ApplicationManager.getApplication().isInternal
@@ -114,6 +114,10 @@ open class ActionSearchEverywhereContributor : WeightedSearchEverywhereContribut
myDisabledActions = state
onChanged.run()
}
override fun setScopeIsDefaultAndAutoSet(isDefault: Boolean) {
isScopeDefaultAndAutoSet = isDefault
}
})
}

View File

@@ -85,6 +85,7 @@ public final class SearchEverywhereHeader {
myEverywhereAutoSet = false;
if (mySelectedTab.everywhereAction == null) return;
if (!mySelectedTab.everywhereAction.canToggleEverywhere()) return;
mySelectedTab.everywhereAction.setScopeIsDefaultAndAutoSet(false);
mySelectedTab.everywhereAction.setEverywhere(
!mySelectedTab.everywhereAction.isEverywhere());
myToolbar.updateActionsImmediately();
@@ -257,6 +258,7 @@ public final class SearchEverywhereHeader {
myEverywhereAutoSet = true;
if (mySelectedTab.everywhereAction == null) return;
if (!mySelectedTab.everywhereAction.canToggleEverywhere()) return;
mySelectedTab.everywhereAction.setScopeIsDefaultAndAutoSet(!everywhere);
mySelectedTab.everywhereAction.setEverywhere(everywhere);
myToolbar.updateActionsImmediately();
}

View File

@@ -37,6 +37,7 @@ f:com.intellij.platform.ml.embeddings.models.TextEncoderConfig$Companion
- f:loadConfig(ai.grazie.utils.mpp.DataLoader,kotlin.coroutines.Continuation):java.lang.Object
f:com.intellij.platform.ml.embeddings.search.indices.DiskSynchronizedEmbeddingSearchIndex
- com.intellij.platform.ml.embeddings.search.indices.EmbeddingSearchIndex
- sf:Companion:com.intellij.platform.ml.embeddings.search.indices.DiskSynchronizedEmbeddingSearchIndex$Companion
- <init>(java.nio.file.Path,java.lang.Integer):V
- b:<init>(java.nio.file.Path,java.lang.Integer,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- addEntries(java.lang.Iterable,Z,kotlin.coroutines.Continuation):java.lang.Object
@@ -63,6 +64,7 @@ f:com.intellij.platform.ml.embeddings.search.indices.DiskSynchronizedEmbeddingSe
- setLimit(java.lang.Integer,kotlin.coroutines.Continuation):java.lang.Object
- streamFindClose(ai.grazie.emb.FloatTextEmbedding,java.lang.Double,kotlin.coroutines.Continuation):java.lang.Object
- f:updateEntry(java.lang.String,java.lang.String,ai.grazie.emb.FloatTextEmbedding,kotlin.coroutines.Continuation):java.lang.Object
f:com.intellij.platform.ml.embeddings.search.indices.DiskSynchronizedEmbeddingSearchIndex$Companion
com.intellij.platform.ml.embeddings.search.indices.EmbeddingSearchIndex
- a:addEntries(java.lang.Iterable,Z,kotlin.coroutines.Continuation):java.lang.Object
- bs:addEntries$default(com.intellij.platform.ml.embeddings.search.indices.EmbeddingSearchIndex,java.lang.Iterable,Z,kotlin.coroutines.Continuation,I,java.lang.Object):java.lang.Object
@@ -166,7 +168,7 @@ a:com.intellij.platform.ml.embeddings.search.services.DiskSynchronizedEmbeddings
- f:getProject():com.intellij.openapi.project.Project
- f:loadIndex(kotlin.coroutines.Continuation):java.lang.Object
- f:registerInMemoryManager():V
- f:scheduleCleanup():V
- f:saveIndex(kotlin.coroutines.Continuation):java.lang.Object
- searchNeighbours(java.lang.String,I,java.lang.Double,kotlin.coroutines.Continuation):java.lang.Object
- f:startIndexingSession(kotlin.coroutines.Continuation):java.lang.Object
- f:streamSearchNeighbours(java.lang.String,java.lang.Double,kotlin.coroutines.Continuation):java.lang.Object

View File

@@ -35,6 +35,8 @@ interface SearchEverywhereConcurrentElementsFetcher<I : MergeableElement, E : An
fun ScoredText.findPriority(): DescriptorPriority
fun checkScopeIsDefaultAndAutoSet(): Boolean = true
@RequiresBackgroundThread
fun fetchElementsConcurrently(pattern: String,
progressIndicator: ProgressIndicator,
@@ -62,6 +64,8 @@ interface SearchEverywhereConcurrentElementsFetcher<I : MergeableElement, E : An
val semanticMatches = itemsProvider.searchIfEnabled(pattern, priorityThresholds[DescriptorPriority.LOW])
if (semanticMatches.isEmpty()) return@launch
standardSearchJob.join()
// Allow the scope to change automatically:
if (knownItems.isEmpty() && checkScopeIsDefaultAndAutoSet()) return@launch
suspend fun iterate() {
for (priority in ORDERED_PRIORITIES) {

View File

@@ -5,6 +5,7 @@ import com.intellij.ide.actions.searcheverywhere.ActionSearchEverywhereContribut
import com.intellij.ide.actions.searcheverywhere.FoundItemDescriptor
import com.intellij.ide.actions.searcheverywhere.PossibleSlowContributor
import com.intellij.ide.util.gotoByName.GotoActionModel
import com.intellij.ide.util.gotoByName.GotoActionModel.ActionWrapper
import com.intellij.ide.util.gotoByName.GotoActionModel.MatchedValue
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.impl.Utils.runUpdateSessionForActionSearch
@@ -125,6 +126,8 @@ class SemanticActionSearchEverywhereContributor(defaultContributor: ActionSearch
val semanticMatches = itemsProvider.searchIfEnabled(pattern, priorityThresholds[DescriptorPriority.LOW])
if (semanticMatches.isEmpty()) return@launch
standardSearchJob.join()
if (knownItems.isEmpty() && checkScopeIsDefaultAndAutoSet()) return@launch // allow the scope to change automatically
for (priority in ORDERED_PRIORITIES) {
val iterator = if (priority == DescriptorPriority.HIGH) semanticMatches.iterator()
else cachedMatches.filter { it.findPriority() == priority }.iterator()
@@ -198,6 +201,8 @@ class SemanticActionSearchEverywhereContributor(defaultContributor: ActionSearch
return ORDERED_PRIORITIES.first { similarity > priorityThresholds[it]!! }
}
override fun checkScopeIsDefaultAndAutoSet(): Boolean = isScopeDefaultAndAutoSet
override fun syncSearchSettings() {
throw UnsupportedOperationException()
}

View File

@@ -41,6 +41,8 @@ class SemanticClassSearchEverywhereContributor(initEvent: AnActionEvent)
super.fetchWeightedElements(pattern, progressIndicator, consumer)
}
override fun checkScopeIsDefaultAndAutoSet(): Boolean = isScopeDefaultAndAutoSet
override fun syncSearchSettings() {
itemsProvider.model = createModel(project)
}

View File

@@ -44,6 +44,8 @@ open class SemanticFileSearchEverywhereContributor(initEvent: AnActionEvent)
super.fetchWeightedElements(pattern, progressIndicator, consumer)
}
override fun checkScopeIsDefaultAndAutoSet(): Boolean = isScopeDefaultAndAutoSet
override fun syncSearchSettings() {
itemsProvider.model = createModel(project)
}

View File

@@ -45,6 +45,8 @@ class SemanticSymbolSearchEverywhereContributor(initEvent: AnActionEvent)
super.fetchWeightedElements(pattern, progressIndicator, consumer)
}
override fun checkScopeIsDefaultAndAutoSet(): Boolean = isScopeDefaultAndAutoSet
override fun syncSearchSettings() {
itemsProvider.model = createModel(project)
}