[find in files] IJ-CR-168030 IJPL-186012 fixup review

(cherry picked from commit 432361b49dcfa5d958e6b26e4da9bae32226372f)

GitOrigin-RevId: 2c96c7c117d89976179864453dd0998c9c6dfc8d
This commit is contained in:
Vera Petrenkova
2025-06-27 11:32:46 +02:00
committed by intellij-monorepo-bot
parent a405923f2b
commit cab7a50fb4
11 changed files with 22 additions and 47 deletions

View File

@@ -88,7 +88,7 @@ final class ClassHierarchyScopeDescriptor extends ScopeDescriptor {
} }
@Override @Override
public boolean isEdtRequired() { public boolean needsUserInputForScope() {
return true; return true;
} }
} }

View File

@@ -24,7 +24,7 @@ import kotlin.math.min
* `getDisposable()` is `DialogWrapper`'s method. * `getDisposable()` is `DialogWrapper`'s method.
*/ */
@ApiStatus.Internal @ApiStatus.Internal
class FrontendScopeChooserCombo(project: Project, private val preselectedScopeName: String?, val filterConditionType: ScopesFilterConditionType = ScopesFilterConditionType.OTHER) : ComboBox<ScopeDescriptor>(400), Disposable { class FrontendScopeChooserCombo(project: Project, private val preselectedScopeName: String?, val filterConditionType: ScopesFilterConditionType = ScopesFilterConditionType.OTHER) : ComboBox<ScopeDescriptor>(300), Disposable {
private val scopeService = ScopeModelService.getInstance(project) private val scopeService = ScopeModelService.getInstance(project)
private val modelId = UUID.randomUUID().toString() private val modelId = UUID.randomUUID().toString()
private var scopesMap: Map<String, ScopeDescriptor> = emptyMap() private var scopesMap: Map<String, ScopeDescriptor> = emptyMap()

View File

@@ -33,8 +33,11 @@ public class ScopeDescriptor implements ColoredItem {
return myScope; return myScope;
} }
/**
* @return true if obtaining this scope requires user interaction (e.g., UI dialog, confirmation); false if it can be resolved programmatically.
*/
@ApiStatus.Internal @ApiStatus.Internal
public boolean isEdtRequired() { public boolean needsUserInputForScope() {
return false; return false;
} }

View File

@@ -34,14 +34,12 @@ enum class ScopesFilterConditionType {
return when (this) { return when (this) {
//moved from FindPopupScopeUIImpl //moved from FindPopupScopeUIImpl
FIND -> { FIND -> {
//final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");
val moduleScopeName: String = IndexingBundle.message("search.scope.module", "") val moduleScopeName: String = IndexingBundle.message("search.scope.module", "")
val ind = moduleScopeName.indexOf(' ') val ind = moduleScopeName.indexOf(' ')
val moduleFilesScopeName: String = moduleScopeName.take(ind + 1) val moduleFilesScopeName: String = moduleScopeName.take(ind + 1)
return scopesFilter@{ descriptor: ScopeDescriptor? -> return scopesFilter@{ descriptor: ScopeDescriptor? ->
//final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");
val display = descriptor?.displayName ?: return@scopesFilter true val display = descriptor?.displayName ?: return@scopesFilter true
return@scopesFilter /*!projectFilesScopeName.equals(display) &&*/!display.startsWith(moduleFilesScopeName) return@scopesFilter !display.startsWith(moduleFilesScopeName)
} }
} }
else -> null else -> null

View File

@@ -12,7 +12,7 @@ import java.util.*
@ApiStatus.Internal @ApiStatus.Internal
@Service(Service.Level.PROJECT) @Service(Service.Level.PROJECT)
class ScopesStateService(val project: Project) { class ScopesStateService(val project: Project) {
private var scopesState: ScopesState = ScopesState(project) private val scopesState: ScopesState = ScopesState(project)
fun getScopeById(scopeId: String): SearchScope? { fun getScopeById(scopeId: String): SearchScope? {
try { try {

View File

@@ -16,7 +16,6 @@
<arrayArg name="pluginClasspaths"> <arrayArg name="pluginClasspaths">
<args> <args>
<arg>$KOTLIN_BUNDLED$/lib/kotlinx-serialization-compiler-plugin.jar</arg> <arg>$KOTLIN_BUNDLED$/lib/kotlinx-serialization-compiler-plugin.jar</arg>
<arg>$MAVEN_REPOSITORY$/jetbrains/fleet/rhizomedb-compiler-plugin/2.2.0-RC2-0.2/rhizomedb-compiler-plugin-2.2.0-RC2-0.2.jar</arg>
<arg>$MAVEN_REPOSITORY$/com/jetbrains/fleet/rpc-compiler-plugin/2.2.0-RC2-0.1/rpc-compiler-plugin-2.2.0-RC2-0.1.jar</arg> <arg>$MAVEN_REPOSITORY$/com/jetbrains/fleet/rpc-compiler-plugin/2.2.0-RC2-0.1/rpc-compiler-plugin-2.2.0-RC2-0.1.jar</arg>
</args> </args>
</arrayArg> </arrayArg>

View File

@@ -5,6 +5,6 @@
<module name="intellij.platform.kernel.backend"/> <module name="intellij.platform.kernel.backend"/>
</dependencies> </dependencies>
<extensions defaultExtensionNs="com.intellij"> <extensions defaultExtensionNs="com.intellij">
<platform.rpc.backend.remoteApiProvider implementation="com.intellij.platform.scopes.backend.ScopesStateApiProvider"/>/> <platform.rpc.backend.remoteApiProvider implementation="com.intellij.platform.scopes.backend.ScopesStateApiProvider"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>

View File

@@ -20,12 +20,12 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.* import java.util.*
import java.util.concurrent.ConcurrentHashMap
private val LOG = logger<ScopesModelApiImpl>() private val LOG = logger<ScopesModelApiImpl>()
internal class ScopesModelApiImpl : ScopeModelApi { internal class ScopesModelApiImpl : ScopeModelApi {
private val modelIdToModel = mutableMapOf<String, AbstractScopeModel>() private val modelIdToModel = ConcurrentHashMap<String, AbstractScopeModel>()
private val modelIdToScopes = mutableMapOf<String, ScopesState>()
override suspend fun createModelAndSubscribe(projectId: ProjectId, modelId: String, filterConditionType: ScopesFilterConditionType): Flow<SearchScopesInfo>? { override suspend fun createModelAndSubscribe(projectId: ProjectId, modelId: String, filterConditionType: ScopesFilterConditionType): Flow<SearchScopesInfo>? {
val project = projectId.findProjectOrNull() val project = projectId.findProjectOrNull()
@@ -51,20 +51,15 @@ internal class ScopesModelApiImpl : ScopeModelApi {
return flow return flow
} }
private fun subscribeToModelUpdates(model: AbstractScopeModel, modelId: String, project: Project): Flow<SearchScopesInfo> { private fun subscribeToModelUpdates(model: AbstractScopeModel, modelId: String, project: Project): Flow<SearchScopesInfo> {
val flow = channelFlow { val flow = channelFlow {
model.addScopeModelListener(object : ScopeModelListener { model.addScopeModelListener(object : ScopeModelListener {
override fun scopesUpdated(scopes: ScopesSnapshot) { override fun scopesUpdated(scopes: ScopesSnapshot) {
var scopesState = modelIdToScopes[modelId] val scopesState = ScopesStateService.getInstance(project).getScopesState()
if (scopesState == null) {
scopesState = ScopesStateService.getInstance(project).getScopesState()
modelIdToScopes[modelId] = scopesState
}
val scopesStateMap = mutableMapOf<String, ScopeDescriptor>() val scopesStateMap = mutableMapOf<String, ScopeDescriptor>()
val scopesData = scopes.scopeDescriptors.mapNotNull { descriptor -> val scopesData = scopes.scopeDescriptors.mapNotNull { descriptor ->
// TODO should be removed after support scopes with frontend activity IJPL-194098 // TODO should be removed after support scopes with frontend activity IJPL-194098
if (descriptor.isEdtRequired || descriptor.scope is ScratchesSearchScope) return@mapNotNull null if (descriptor.needsUserInputForScope() || descriptor.scope is ScratchesSearchScope) return@mapNotNull null
val scopeId = scopesState.addScope(descriptor) val scopeId = scopesState.addScope(descriptor)
val scopeData = SearchScopeData.from(descriptor, scopeId) ?: return@mapNotNull null val scopeData = SearchScopeData.from(descriptor, scopeId) ?: return@mapNotNull null
scopesStateMap[scopeData.scopeId] = descriptor scopesStateMap[scopeData.scopeId] = descriptor
@@ -79,21 +74,14 @@ internal class ScopesModelApiImpl : ScopeModelApi {
} }
}) })
awaitClose {} awaitClose {
val model = modelIdToModel[modelId]
model?.let { Disposer.dispose(it) }
modelIdToModel.remove(modelId)
}
} }
return flow return flow
} }
override suspend fun updateModel(modelId: String, scopesInfo: SearchScopesInfo): Flow<SearchScopesInfo> {
TODO("Not yet implemented")
}
override suspend fun dispose(modelId: String) {
modelIdToScopes.remove(modelId)
val model = modelIdToModel[modelId] ?: return
Disposer.dispose(model)
modelIdToModel.remove(modelId)
}
} }
private class ScopesStateApiProvider : RemoteApiProvider { private class ScopesStateApiProvider : RemoteApiProvider {

View File

@@ -16,7 +16,6 @@
<arrayArg name="pluginClasspaths"> <arrayArg name="pluginClasspaths">
<args> <args>
<arg>$KOTLIN_BUNDLED$/lib/kotlinx-serialization-compiler-plugin.jar</arg> <arg>$KOTLIN_BUNDLED$/lib/kotlinx-serialization-compiler-plugin.jar</arg>
<arg>$MAVEN_REPOSITORY$/jetbrains/fleet/rhizomedb-compiler-plugin/2.2.0-RC2-0.2/rhizomedb-compiler-plugin-2.2.0-RC2-0.2.jar</arg>
<arg>$MAVEN_REPOSITORY$/com/jetbrains/fleet/rpc-compiler-plugin/2.2.0-RC2-0.1/rpc-compiler-plugin-2.2.0-RC2-0.1.jar</arg> <arg>$MAVEN_REPOSITORY$/com/jetbrains/fleet/rpc-compiler-plugin/2.2.0-RC2-0.1/rpc-compiler-plugin-2.2.0-RC2-0.1.jar</arg>
</args> </args>
</arrayArg> </arrayArg>

View File

@@ -15,9 +15,6 @@ import org.jetbrains.annotations.ApiStatus
interface ScopeModelApi : RemoteApi<Unit> { interface ScopeModelApi : RemoteApi<Unit> {
suspend fun createModelAndSubscribe(projectId: ProjectId, modelId: String, filterConditionType: ScopesFilterConditionType): Flow<SearchScopesInfo>? suspend fun createModelAndSubscribe(projectId: ProjectId, modelId: String, filterConditionType: ScopesFilterConditionType): Flow<SearchScopesInfo>?
suspend fun updateModel(modelId: String, scopesInfo: SearchScopesInfo): Flow<SearchScopesInfo>
suspend fun dispose(modelId: String)
companion object { companion object {
@JvmStatic @JvmStatic
suspend fun getInstance(): ScopeModelApi { suspend fun getInstance(): ScopeModelApi {

View File

@@ -11,7 +11,6 @@ import com.intellij.openapi.project.Project
import com.intellij.platform.project.projectId import com.intellij.platform.project.projectId
import com.intellij.platform.scopes.ScopeModelApi import com.intellij.platform.scopes.ScopeModelApi
import com.intellij.platform.util.coroutines.childScope import com.intellij.platform.util.coroutines.childScope
import fleet.rpc.client.RpcTimeoutException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.ApiStatus
@@ -24,18 +23,18 @@ private class ScopeModelServiceImpl(private val project: Project, private val co
private var scopeIdToDescriptor = mapOf<String, ScopeDescriptor>() private var scopeIdToDescriptor = mapOf<String, ScopeDescriptor>()
private var itemsLoadingJob: kotlinx.coroutines.Job? = null private var itemsLoadingJob: kotlinx.coroutines.Job? = null
override fun loadItemsAsync(modelId: String, filterConditionType: ScopesFilterConditionType, onFinished: suspend (Map<String, ScopeDescriptor>?) -> Unit) { override fun loadItemsAsync(modelId: String, filterConditionType: ScopesFilterConditionType, onScopesUpdate: suspend (Map<String, ScopeDescriptor>?) -> Unit) {
itemsLoadingJob = coroutineScope.childScope("ScopesStateService.subscribeToScopeStates").launch { itemsLoadingJob = coroutineScope.childScope("ScopesStateService.subscribeToScopeStates").launch {
LOG.performRpcWithRetries { LOG.performRpcWithRetries {
val scopesFlow = ScopeModelApi.getInstance().createModelAndSubscribe(project.projectId(), modelId, filterConditionType) val scopesFlow = ScopeModelApi.getInstance().createModelAndSubscribe(project.projectId(), modelId, filterConditionType)
if (scopesFlow == null) { if (scopesFlow == null) {
LOG.warn("Failed to subscribe to model updates for modelId: $modelId") LOG.error("Failed to subscribe to model updates for modelId: $modelId")
onFinished(null) onScopesUpdate(null)
return@performRpcWithRetries return@performRpcWithRetries
} }
scopesFlow.collect { scopesInfo -> scopesFlow.collect { scopesInfo ->
val fetchedScopes = scopesInfo.getScopeDescriptors() val fetchedScopes = scopesInfo.getScopeDescriptors()
onFinished(fetchedScopes) onScopesUpdate(fetchedScopes)
ScopesStateService.getInstance(project).getScopesState().updateIfNotExists(fetchedScopes) ScopesStateService.getInstance(project).getScopesState().updateIfNotExists(fetchedScopes)
scopeIdToDescriptor = fetchedScopes scopeIdToDescriptor = fetchedScopes
} }
@@ -45,14 +44,6 @@ private class ScopeModelServiceImpl(private val project: Project, private val co
override fun disposeModel(modelId: String) { override fun disposeModel(modelId: String) {
itemsLoadingJob?.cancel() itemsLoadingJob?.cancel()
coroutineScope.launch {
try {
ScopeModelApi.getInstance().dispose(modelId)
}
catch (e: RpcTimeoutException) {
LOG.warn("Failed to dispose model for modelId: $modelId", e)
}
}
} }
override fun getScopeById(scopeId: String): ScopeDescriptor? { override fun getScopeById(scopeId: String): ScopeDescriptor? {