[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
public boolean isEdtRequired() {
public boolean needsUserInputForScope() {
return true;
}
}

View File

@@ -24,7 +24,7 @@ import kotlin.math.min
* `getDisposable()` is `DialogWrapper`'s method.
*/
@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 modelId = UUID.randomUUID().toString()
private var scopesMap: Map<String, ScopeDescriptor> = emptyMap()

View File

@@ -33,8 +33,11 @@ public class ScopeDescriptor implements ColoredItem {
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
public boolean isEdtRequired() {
public boolean needsUserInputForScope() {
return false;
}

View File

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

View File

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

View File

@@ -16,7 +16,6 @@
<arrayArg name="pluginClasspaths">
<args>
<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>
</args>
</arrayArg>

View File

@@ -5,6 +5,6 @@
<module name="intellij.platform.kernel.backend"/>
</dependencies>
<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>
</idea-plugin>

View File

@@ -20,12 +20,12 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.launch
import java.util.*
import java.util.concurrent.ConcurrentHashMap
private val LOG = logger<ScopesModelApiImpl>()
internal class ScopesModelApiImpl : ScopeModelApi {
private val modelIdToModel = mutableMapOf<String, AbstractScopeModel>()
private val modelIdToScopes = mutableMapOf<String, ScopesState>()
private val modelIdToModel = ConcurrentHashMap<String, AbstractScopeModel>()
override suspend fun createModelAndSubscribe(projectId: ProjectId, modelId: String, filterConditionType: ScopesFilterConditionType): Flow<SearchScopesInfo>? {
val project = projectId.findProjectOrNull()
@@ -51,20 +51,15 @@ internal class ScopesModelApiImpl : ScopeModelApi {
return flow
}
private fun subscribeToModelUpdates(model: AbstractScopeModel, modelId: String, project: Project): Flow<SearchScopesInfo> {
val flow = channelFlow {
model.addScopeModelListener(object : ScopeModelListener {
override fun scopesUpdated(scopes: ScopesSnapshot) {
var scopesState = modelIdToScopes[modelId]
if (scopesState == null) {
scopesState = ScopesStateService.getInstance(project).getScopesState()
modelIdToScopes[modelId] = scopesState
}
val scopesState = ScopesStateService.getInstance(project).getScopesState()
val scopesStateMap = mutableMapOf<String, ScopeDescriptor>()
val scopesData = scopes.scopeDescriptors.mapNotNull { descriptor ->
// 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 scopeData = SearchScopeData.from(descriptor, scopeId) ?: return@mapNotNull null
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
}
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 {

View File

@@ -16,7 +16,6 @@
<arrayArg name="pluginClasspaths">
<args>
<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>
</args>
</arrayArg>

View File

@@ -15,9 +15,6 @@ import org.jetbrains.annotations.ApiStatus
interface ScopeModelApi : RemoteApi<Unit> {
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 {
@JvmStatic
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.scopes.ScopeModelApi
import com.intellij.platform.util.coroutines.childScope
import fleet.rpc.client.RpcTimeoutException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
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 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 {
LOG.performRpcWithRetries {
val scopesFlow = ScopeModelApi.getInstance().createModelAndSubscribe(project.projectId(), modelId, filterConditionType)
if (scopesFlow == null) {
LOG.warn("Failed to subscribe to model updates for modelId: $modelId")
onFinished(null)
LOG.error("Failed to subscribe to model updates for modelId: $modelId")
onScopesUpdate(null)
return@performRpcWithRetries
}
scopesFlow.collect { scopesInfo ->
val fetchedScopes = scopesInfo.getScopeDescriptors()
onFinished(fetchedScopes)
onScopesUpdate(fetchedScopes)
ScopesStateService.getInstance(project).getScopesState().updateIfNotExists(fetchedScopes)
scopeIdToDescriptor = fetchedScopes
}
@@ -45,14 +44,6 @@ private class ScopeModelServiceImpl(private val project: Project, private val co
override fun disposeModel(modelId: String) {
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? {