[find in files] IJ-CR-168030 IJPL-194753 set a custom scope by id on findAll/replaceAll actions

(cherry picked from commit 34790bb62a75e3de3113db5a71a68d83f5f94cfd)

GitOrigin-RevId: aea65c36771e13597ae6460bb639ea3c689b438d
This commit is contained in:
Vera Petrenkova
2025-07-02 09:35:16 +02:00
committed by intellij-monorepo-bot
parent 777284c437
commit 0a517c09cd

View File

@@ -20,6 +20,7 @@ import com.intellij.openapi.application.readAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.newvfs.VfsPresentationUtil
import com.intellij.platform.find.FindInFilesResult
import com.intellij.platform.find.FindRemoteApi
@@ -58,11 +59,7 @@ internal class FindRemoteApiImpl : FindRemoteApi {
}
val filesToScanInitially = filesToScanInitially.mapNotNull { it.virtualFile() }.toSet()
// SearchScope is not serializable, so we will get it by id from the client
findModel.customScopeId?.let { scopeId ->
ScopesStateService.getInstance(project).getScopeById(scopeId)?.let {
findModel.customScope = it
}
}
setCustomScopeById(project, findModel)
//read action is necessary in case of the loading from a directory
val scope = readAction { FindInProjectUtil.getGlobalSearchScope(project, findModel) }
FindInProjectUtil.findUsages(findModel, project, progressIndicator, presentation, filesToScanInitially) { usageInfo ->
@@ -120,6 +117,7 @@ internal class FindRemoteApiImpl : FindRemoteApi {
LOG.warn("Project not found for id ${projectId}. FindAll/ReplaceAll operation skipped")
return
}
setCustomScopeById(project, findModel)
if (findModel.isReplaceState) {
ReplaceInProjectManager.getInstance(project).replaceInPath(findModel)
}
@@ -132,4 +130,13 @@ internal class FindRemoteApiImpl : FindRemoteApi {
override suspend fun checkDirectoryExists(findModel: FindModel): Boolean {
return FindInProjectUtil.getDirectory(findModel) != null
}
private fun setCustomScopeById(project: Project, findModel: FindModel) {
if (findModel.customScope == null && findModel.isCustomScope) {
val scopeId = findModel.customScopeId ?: return
ScopesStateService.getInstance(project).getScopeById(scopeId)?.let {
findModel.customScope = it
}
}
}
}